Bump rubocop
This commit is contained in:
parent
0531a02aaa
commit
e4f56e06bb
29 changed files with 57 additions and 17 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
require: rubocop-rails
|
||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
TargetRubyVersion: 2.5
|
TargetRubyVersion: 2.5
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
||||||
3
Gemfile
3
Gemfile
|
|
@ -21,7 +21,8 @@ group :development do
|
||||||
# code style
|
# code style
|
||||||
gem "pronto", "0.10.0", require: false
|
gem "pronto", "0.10.0", require: false
|
||||||
gem "pronto-rubocop", "0.10.0", require: false
|
gem "pronto-rubocop", "0.10.0", require: false
|
||||||
gem "rubocop", "0.57.2", require: false
|
gem "rubocop", "0.75.1", require: false
|
||||||
|
gem "rubocop-rails", "2.3.2", require: false
|
||||||
|
|
||||||
# automatic test runs
|
# automatic test runs
|
||||||
gem "guard-rspec", require: false
|
gem "guard-rspec", require: false
|
||||||
|
|
|
||||||
14
Gemfile.lock
14
Gemfile.lock
|
|
@ -126,7 +126,6 @@ GEM
|
||||||
parallel (1.18.0)
|
parallel (1.18.0)
|
||||||
parser (2.6.5.0)
|
parser (2.6.5.0)
|
||||||
ast (~> 2.4.0)
|
ast (~> 2.4.0)
|
||||||
powerpack (0.1.2)
|
|
||||||
pronto (0.10.0)
|
pronto (0.10.0)
|
||||||
gitlab (~> 4.0, >= 4.0.0)
|
gitlab (~> 4.0, >= 4.0.0)
|
||||||
httparty (>= 0.13.7)
|
httparty (>= 0.13.7)
|
||||||
|
|
@ -187,14 +186,16 @@ GEM
|
||||||
rspec-mocks (~> 3.8.0)
|
rspec-mocks (~> 3.8.0)
|
||||||
rspec-support (~> 3.8.0)
|
rspec-support (~> 3.8.0)
|
||||||
rspec-support (3.8.0)
|
rspec-support (3.8.0)
|
||||||
rubocop (0.57.2)
|
rubocop (0.75.1)
|
||||||
jaro_winkler (~> 1.5.1)
|
jaro_winkler (~> 1.5.1)
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 2.5)
|
parser (>= 2.6)
|
||||||
powerpack (~> 0.1)
|
|
||||||
rainbow (>= 2.2.2, < 4.0)
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (~> 1.0, >= 1.0.1)
|
unicode-display_width (>= 1.4.0, < 1.7)
|
||||||
|
rubocop-rails (2.3.2)
|
||||||
|
rack (>= 1.1)
|
||||||
|
rubocop (>= 0.72.0)
|
||||||
ruby-progressbar (1.10.1)
|
ruby-progressbar (1.10.1)
|
||||||
ruby_dep (1.5.0)
|
ruby_dep (1.5.0)
|
||||||
rugged (0.28.3.1)
|
rugged (0.28.3.1)
|
||||||
|
|
@ -258,7 +259,8 @@ DEPENDENCIES
|
||||||
rspec-collection_matchers (~> 1.1.2)
|
rspec-collection_matchers (~> 1.1.2)
|
||||||
rspec-json_expectations (~> 2.1)
|
rspec-json_expectations (~> 2.1)
|
||||||
rspec-rails (~> 3.8.0)
|
rspec-rails (~> 3.8.0)
|
||||||
rubocop (= 0.57.2)
|
rubocop (= 0.75.1)
|
||||||
|
rubocop-rails (= 2.3.2)
|
||||||
simplecov (= 0.16.1)
|
simplecov (= 0.16.1)
|
||||||
simplecov-rcov (= 0.2.3)
|
simplecov-rcov (= 0.2.3)
|
||||||
spring
|
spring
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,7 @@ module DiasporaFederation
|
||||||
configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Integer)
|
configuration_error "http_timeout: please configure a number" unless @http_timeout.is_a?(Integer)
|
||||||
|
|
||||||
return unless !@http_verbose.is_a?(TrueClass) && !@http_verbose.is_a?(FalseClass)
|
return unless !@http_verbose.is_a?(TrueClass) && !@http_verbose.is_a?(FalseClass)
|
||||||
|
|
||||||
configuration_error "http_verbose: please configure a boolean"
|
configuration_error "http_verbose: please configure a boolean"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ module DiasporaFederation
|
||||||
def validate_diaspora_id
|
def validate_diaspora_id
|
||||||
# Validates if the diaspora* ID matches the diaspora* ID in the webfinger response
|
# Validates if the diaspora* ID matches the diaspora* ID in the webfinger response
|
||||||
return if diaspora_id == clean_diaspora_id(webfinger.acct_uri)
|
return if diaspora_id == clean_diaspora_id(webfinger.acct_uri)
|
||||||
|
|
||||||
raise DiscoveryError, "diaspora* ID does not match: Wanted #{diaspora_id} but got" \
|
raise DiscoveryError, "diaspora* ID does not match: Wanted #{diaspora_id} but got" \
|
||||||
" #{clean_diaspora_id(webfinger.acct_uri)}"
|
" #{clean_diaspora_id(webfinger.acct_uri)}"
|
||||||
end
|
end
|
||||||
|
|
@ -49,6 +50,7 @@ module DiasporaFederation
|
||||||
logger.info "Fetching #{url} for #{diaspora_id}"
|
logger.info "Fetching #{url} for #{diaspora_id}"
|
||||||
response = HttpClient.get(url)
|
response = HttpClient.get(url)
|
||||||
raise "Failed to fetch #{url}: #{response.status}" unless response.success?
|
raise "Failed to fetch #{url}: #{response.status}" unless response.success?
|
||||||
|
|
||||||
response.body
|
response.body
|
||||||
rescue => e # rubocop:disable Style/RescueStandardError
|
rescue => e # rubocop:disable Style/RescueStandardError
|
||||||
raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}" unless http_fallback
|
raise DiscoveryError, "Failed to fetch #{url} for #{diaspora_id}: #{e.class}: #{e.message}" unless http_fallback
|
||||||
|
|
@ -73,6 +75,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
def webfinger
|
def webfinger
|
||||||
return @webfinger if @webfinger
|
return @webfinger if @webfinger
|
||||||
|
|
||||||
webfinger_url = "https://#{domain}/.well-known/webfinger?resource=#{acct_parameter}"
|
webfinger_url = "https://#{domain}/.well-known/webfinger?resource=#{acct_parameter}"
|
||||||
|
|
||||||
# This tries the WebFinger URL with https first, then falls back to http if webfinger_http_fallback is enabled.
|
# This tries the WebFinger URL with https first, then falls back to http if webfinger_http_fallback is enabled.
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
doc = Nokogiri::HTML::Document.parse(html_string)
|
doc = Nokogiri::HTML::Document.parse(html_string)
|
||||||
raise InvalidData, "hcard html incomplete" unless html_document_complete?(doc)
|
raise InvalidData, "hcard html incomplete" unless html_document_complete?(doc)
|
||||||
|
|
||||||
doc
|
doc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ module DiasporaFederation
|
||||||
to_xrd.to_xml
|
to_xrd.to_xml
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json(*_args)
|
||||||
to_xrd.to_json
|
to_xrd.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ module DiasporaFederation
|
||||||
}.to_xml
|
}.to_xml
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json(*_args)
|
||||||
{
|
{
|
||||||
subject: subject,
|
subject: subject,
|
||||||
expires: (expires.strftime(DATETIME_FORMAT) if expires.instance_of?(DateTime)),
|
expires: (expires.strftime(DATETIME_FORMAT) if expires.instance_of?(DateTime)),
|
||||||
|
|
@ -148,6 +148,7 @@ module DiasporaFederation
|
||||||
def add_aliases_to(xml)
|
def add_aliases_to(xml)
|
||||||
aliases.each do |a|
|
aliases.each do |a|
|
||||||
next if !a.instance_of?(String) || a.empty?
|
next if !a.instance_of?(String) || a.empty?
|
||||||
|
|
||||||
xml.Alias(a.to_s)
|
xml.Alias(a.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -173,6 +174,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
doc = Nokogiri::XML(xrd_doc)
|
doc = Nokogiri::XML(xrd_doc)
|
||||||
raise InvalidDocument, "Not an XRD document" if !doc.root || doc.root.name != "XRD"
|
raise InvalidDocument, "Not an XRD document" if !doc.root || doc.root.name != "XRD"
|
||||||
|
|
||||||
doc
|
doc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ module DiasporaFederation
|
||||||
# @return [String] diaspora* ID of the old person identity
|
# @return [String] diaspora* ID of the old person identity
|
||||||
def old_identity
|
def old_identity
|
||||||
return @old_identity if author_is_new_id?
|
return @old_identity if author_is_new_id?
|
||||||
|
|
||||||
author
|
author
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -87,6 +88,7 @@ module DiasporaFederation
|
||||||
def sign_with_respective_key
|
def sign_with_respective_key
|
||||||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, signer_id)
|
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, signer_id)
|
||||||
raise PrivateKeyNotFound, "signer=#{signer_id} obj=#{self}" if privkey.nil?
|
raise PrivateKeyNotFound, "signer=#{signer_id} obj=#{self}" if privkey.nil?
|
||||||
|
|
||||||
sign_with_key(privkey).tap do
|
sign_with_key(privkey).tap do
|
||||||
logger.info "event=sign status=complete signature=signature signer=#{signer_id} obj=#{self}"
|
logger.info "event=sign status=complete signature=signature signer=#{signer_id} obj=#{self}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
# never add {RelatedEntity} to json
|
# never add {RelatedEntity} to json
|
||||||
def to_json
|
def to_json(*_args)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ module DiasporaFederation
|
||||||
"#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}"
|
"#{super}#{":#{parent_type}" if respond_to?(:parent_type)}:#{parent_guid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json
|
def to_json(*_args)
|
||||||
super.merge!(property_order: signature_order).tap {|json_hash|
|
super.merge!(property_order: signature_order).tap {|json_hash|
|
||||||
missing_properties = json_hash[:property_order] - json_hash[:entity_data].keys
|
missing_properties = json_hash[:property_order] - json_hash[:entity_data].keys
|
||||||
missing_properties.each {|property|
|
missing_properties.each {|property|
|
||||||
|
|
@ -115,6 +115,7 @@ module DiasporaFederation
|
||||||
def sign_with_author
|
def sign_with_author
|
||||||
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
|
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
|
||||||
raise AuthorPrivateKeyNotFound, "author=#{author} obj=#{self}" if privkey.nil?
|
raise AuthorPrivateKeyNotFound, "author=#{author} obj=#{self}" if privkey.nil?
|
||||||
|
|
||||||
sign_with_key(privkey).tap do
|
sign_with_key(privkey).tap do
|
||||||
logger.info "event=sign status=complete signature=author_signature author=#{author} obj=#{self}"
|
logger.info "event=sign status=complete signature=author_signature author=#{author} obj=#{self}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ module DiasporaFederation
|
||||||
def sender_valid?(sender)
|
def sender_valid?(sender)
|
||||||
case target_type
|
case target_type
|
||||||
when "Comment", "Like", "PollParticipation"
|
when "Comment", "Like", "PollParticipation"
|
||||||
sender == target.author || sender == target.root.author
|
[target.root.author, target.author].include?(sender)
|
||||||
else
|
else
|
||||||
sender == target.author
|
sender == target.author
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
# Invalid XML characters
|
# Invalid XML characters
|
||||||
# @see https://www.w3.org/TR/REC-xml/#charsets "Extensible Markup Language (XML) 1.0"
|
# @see https://www.w3.org/TR/REC-xml/#charsets "Extensible Markup Language (XML) 1.0"
|
||||||
INVALID_XML_REGEX = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/
|
INVALID_XML_REGEX = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/.freeze
|
||||||
|
|
||||||
# Regex to validate and find entity names
|
# Regex to validate and find entity names
|
||||||
ENTITY_NAME_REGEX = "[a-z]*(?:_[a-z]*)*"
|
ENTITY_NAME_REGEX = "[a-z]*(?:_[a-z]*)*"
|
||||||
|
|
@ -151,6 +151,7 @@ module DiasporaFederation
|
||||||
# @return [Class] entity class
|
# @return [Class] entity class
|
||||||
def self.entity_class(entity_name)
|
def self.entity_class(entity_name)
|
||||||
raise InvalidEntityName, "'#{entity_name}' is invalid" unless entity_name =~ /\A#{ENTITY_NAME_REGEX}\z/
|
raise InvalidEntityName, "'#{entity_name}' is invalid" unless entity_name =~ /\A#{ENTITY_NAME_REGEX}\z/
|
||||||
|
|
||||||
class_name = entity_name.sub(/\A[a-z]/, &:upcase)
|
class_name = entity_name.sub(/\A[a-z]/, &:upcase)
|
||||||
class_name.gsub!(/_([a-z])/) { Regexp.last_match[1].upcase }
|
class_name.gsub!(/_([a-z])/) { Regexp.last_match[1].upcase }
|
||||||
|
|
||||||
|
|
@ -171,7 +172,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
# Renders entity to a hash representation of the entity JSON format
|
# Renders entity to a hash representation of the entity JSON format
|
||||||
# @return [Hash] Returns a hash that is equal by structure to the entity in JSON format
|
# @return [Hash] Returns a hash that is equal by structure to the entity in JSON format
|
||||||
def to_json
|
def to_json(*_args)
|
||||||
{
|
{
|
||||||
entity_type: self.class.entity_name,
|
entity_type: self.class.entity_name,
|
||||||
entity_data: json_data
|
entity_data: json_data
|
||||||
|
|
@ -233,12 +234,14 @@ module DiasporaFederation
|
||||||
|
|
||||||
def nilify(value)
|
def nilify(value)
|
||||||
return nil if value.respond_to?(:empty?) && value.empty? && !value.instance_of?(Array)
|
return nil if value.respond_to?(:empty?) && value.empty? && !value.instance_of?(Array)
|
||||||
|
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def instantiate_nested(name, value)
|
def instantiate_nested(name, value)
|
||||||
if value.instance_of?(Array)
|
if value.instance_of?(Array)
|
||||||
return value unless value.first.instance_of?(Hash)
|
return value unless value.first.instance_of?(Hash)
|
||||||
|
|
||||||
value.map {|hash| self.class.class_props[name].first.new(hash) }
|
value.map {|hash| self.class.class_props[name].first.new(hash) }
|
||||||
elsif value.instance_of?(Hash)
|
elsif value.instance_of?(Hash)
|
||||||
self.class.class_props[name].new(value)
|
self.class.class_props[name].new(value)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ module DiasporaFederation
|
||||||
(#{Validation::Rule::DiasporaId::DIASPORA_ID_REGEX})/
|
(#{Validation::Rule::DiasporaId::DIASPORA_ID_REGEX})/
|
||||||
(#{Entity::ENTITY_NAME_REGEX})/
|
(#{Entity::ENTITY_NAME_REGEX})/
|
||||||
(#{Validation::Rule::Guid::VALID_CHARS})
|
(#{Validation::Rule::Guid::VALID_CHARS})
|
||||||
}ux
|
}ux.freeze
|
||||||
|
|
||||||
# Parses all diaspora:// URLs from the text and fetches the entities from
|
# Parses all diaspora:// URLs from the text and fetches the entities from
|
||||||
# the remote server if needed.
|
# the remote server if needed.
|
||||||
|
|
@ -27,6 +27,7 @@ module DiasporaFederation
|
||||||
private_class_method def self.fetch_entity(author, type, guid)
|
private_class_method def self.fetch_entity(author, type, guid)
|
||||||
class_name = Entity.entity_class(type).to_s.rpartition("::").last
|
class_name = Entity.entity_class(type).to_s.rpartition("::").last
|
||||||
return if DiasporaFederation.callbacks.trigger(:fetch_related_entity, class_name, guid)
|
return if DiasporaFederation.callbacks.trigger(:fetch_related_entity, class_name, guid)
|
||||||
|
|
||||||
Fetcher.fetch_public(author, type, guid)
|
Fetcher.fetch_public(author, type, guid)
|
||||||
rescue => e # rubocop:disable Style/RescueStandardError
|
rescue => e # rubocop:disable Style/RescueStandardError
|
||||||
logger.error "Failed to fetch linked entity #{type}:#{guid}: #{e.class}: #{e.message}"
|
logger.error "Failed to fetch linked entity #{type}:#{guid}: #{e.class}: #{e.message}"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ module DiasporaFederation
|
||||||
def self.fetch_public(author, entity_type, guid)
|
def self.fetch_public(author, entity_type, guid)
|
||||||
type = entity_name(entity_type).to_s
|
type = entity_name(entity_type).to_s
|
||||||
raise "Already fetching ..." if fetching[type].include?(guid)
|
raise "Already fetching ..." if fetching[type].include?(guid)
|
||||||
|
|
||||||
fetch_from_url(author, type, guid)
|
fetch_from_url(author, type, guid)
|
||||||
rescue => e # rubocop:disable Style/RescueStandardError
|
rescue => e # rubocop:disable Style/RescueStandardError
|
||||||
raise NotFetchable, "Failed to fetch #{entity_type}:#{guid} from #{author}: #{e.class}: #{e.message}"
|
raise NotFetchable, "Failed to fetch #{entity_type}:#{guid} from #{author}: #{e.class}: #{e.message}"
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ module DiasporaFederation
|
||||||
# @param [Boolean] legacy use old slap parser
|
# @param [Boolean] legacy use old slap parser
|
||||||
def self.receive_private(data, recipient_private_key, recipient_id, legacy=false)
|
def self.receive_private(data, recipient_private_key, recipient_id, legacy=false)
|
||||||
raise ArgumentError, "no recipient key provided" unless recipient_private_key.instance_of?(OpenSSL::PKey::RSA)
|
raise ArgumentError, "no recipient key provided" unless recipient_private_key.instance_of?(OpenSSL::PKey::RSA)
|
||||||
|
|
||||||
magic_env = if legacy
|
magic_env = if legacy
|
||||||
Salmon::EncryptedSlap.from_xml(data, recipient_private_key)
|
Salmon::EncryptedSlap.from_xml(data, recipient_private_key)
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
raise RecipientRequired if recipient_id.nil?
|
raise RecipientRequired if recipient_id.nil?
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ module DiasporaFederation
|
||||||
text.to_i if text =~ /\A\d+\z/
|
text.to_i if text =~ /\A\d+\z/
|
||||||
when :boolean
|
when :boolean
|
||||||
return true if text =~ /\A(true|t|yes|y|1)\z/i
|
return true if text =~ /\A(true|t|yes|y|1)\z/i
|
||||||
|
|
||||||
false if text =~ /\A(false|f|no|n|0)\z/i
|
false if text =~ /\A(false|f|no|n|0)\z/i
|
||||||
else
|
else
|
||||||
text
|
text
|
||||||
|
|
@ -46,6 +47,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
def assert_parsability_of(entity_class)
|
def assert_parsability_of(entity_class)
|
||||||
return if entity_class == entity_type.entity_name
|
return if entity_class == entity_type.entity_name
|
||||||
|
|
||||||
raise InvalidRootNode, "'#{entity_class}' can't be parsed by #{entity_type.name}"
|
raise InvalidRootNode, "'#{entity_class}' can't be parsed by #{entity_type.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,14 @@ module DiasporaFederation
|
||||||
|
|
||||||
def parse_element_from_value(type, value)
|
def parse_element_from_value(type, value)
|
||||||
return if value.nil?
|
return if value.nil?
|
||||||
|
|
||||||
if %i[integer boolean timestamp].include?(type) && !value.is_a?(String)
|
if %i[integer boolean timestamp].include?(type) && !value.is_a?(String)
|
||||||
value
|
value
|
||||||
elsif type.instance_of?(Symbol)
|
elsif type.instance_of?(Symbol)
|
||||||
parse_string(type, value)
|
parse_string(type, value)
|
||||||
elsif type.instance_of?(Array)
|
elsif type.instance_of?(Array)
|
||||||
raise DeserializationError, "Expected array for #{type}" unless value.respond_to?(:map)
|
raise DeserializationError, "Expected array for #{type}" unless value.respond_to?(:map)
|
||||||
|
|
||||||
value.map {|element|
|
value.map {|element|
|
||||||
type.first.from_json(element)
|
type.first.from_json(element)
|
||||||
}
|
}
|
||||||
|
|
@ -51,6 +53,7 @@ module DiasporaFederation
|
||||||
prop if json_hash[prop].nil?
|
prop if json_hash[prop].nil?
|
||||||
}.compact.join(", ")
|
}.compact.join(", ")
|
||||||
raise DeserializationError, "Required properties are missing in JSON object: #{missing}" unless missing.empty?
|
raise DeserializationError, "Required properties are missing in JSON object: #{missing}" unless missing.empty?
|
||||||
|
|
||||||
assert_parsability_of(json_hash["entity_type"])
|
assert_parsability_of(json_hash["entity_type"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ module DiasporaFederation
|
||||||
def from_json_sanity_validation(json_hash)
|
def from_json_sanity_validation(json_hash)
|
||||||
super
|
super
|
||||||
return unless json_hash["property_order"].nil?
|
return unless json_hash["property_order"].nil?
|
||||||
|
|
||||||
raise DeserializationError, "Required property is missing in JSON object: property_order"
|
raise DeserializationError, "Required property is missing in JSON object: property_order"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
def from_xml_sanity_validation(root_node)
|
def from_xml_sanity_validation(root_node)
|
||||||
raise ArgumentError, "only Nokogiri::XML::Element allowed" unless root_node.instance_of?(Nokogiri::XML::Element)
|
raise ArgumentError, "only Nokogiri::XML::Element allowed" unless root_node.instance_of?(Nokogiri::XML::Element)
|
||||||
|
|
||||||
assert_parsability_of(root_node.name)
|
assert_parsability_of(root_node.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ module DiasporaFederation
|
||||||
if class_prop_aliases.has_key? name
|
if class_prop_aliases.has_key? name
|
||||||
prop_name = class_prop_aliases[name]
|
prop_name = class_prop_aliases[name]
|
||||||
raise InvalidData, "only use '#{name}' OR '#{prop_name}'" if data.has_key? prop_name
|
raise InvalidData, "only use '#{name}' OR '#{prop_name}'" if data.has_key? prop_name
|
||||||
|
|
||||||
[prop_name, value]
|
[prop_name, value]
|
||||||
else
|
else
|
||||||
[name, value]
|
[name, value]
|
||||||
|
|
@ -88,7 +89,7 @@ module DiasporaFederation
|
||||||
# @param [String] xml_name name of the property from the received xml
|
# @param [String] xml_name name of the property from the received xml
|
||||||
# @return [Hash] the property data
|
# @return [Hash] the property data
|
||||||
def find_property_for_xml_name(xml_name)
|
def find_property_for_xml_name(xml_name)
|
||||||
class_props.keys.find {|name| name.to_s == xml_name || xml_names[name].to_s == xml_name }
|
class_props.keys.find {|name| [name.to_s, xml_names[name].to_s].include?(xml_name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -102,6 +103,7 @@ module DiasporaFederation
|
||||||
if type.instance_of?(Symbol)
|
if type.instance_of?(Symbol)
|
||||||
if opts.has_key? :xml_name
|
if opts.has_key? :xml_name
|
||||||
raise InvalidName, "invalid xml_name" unless name_valid?(opts[:xml_name])
|
raise InvalidName, "invalid xml_name" unless name_valid?(opts[:xml_name])
|
||||||
|
|
||||||
opts[:xml_name]
|
opts[:xml_name]
|
||||||
else
|
else
|
||||||
name
|
name
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,12 @@ module DiasporaFederation
|
||||||
# @raise [MissingMagicEnvelope] if the +me:env+ element is missing in the XML
|
# @raise [MissingMagicEnvelope] if the +me:env+ element is missing in the XML
|
||||||
def self.from_xml(slap_xml, privkey)
|
def self.from_xml(slap_xml, privkey)
|
||||||
raise ArgumentError unless slap_xml.instance_of?(String) && privkey.instance_of?(OpenSSL::PKey::RSA)
|
raise ArgumentError unless slap_xml.instance_of?(String) && privkey.instance_of?(OpenSSL::PKey::RSA)
|
||||||
|
|
||||||
doc = Nokogiri::XML(slap_xml)
|
doc = Nokogiri::XML(slap_xml)
|
||||||
|
|
||||||
header_elem = doc.at_xpath("d:diaspora/d:encrypted_header", Slap::NS)
|
header_elem = doc.at_xpath("d:diaspora/d:encrypted_header", Slap::NS)
|
||||||
raise MissingHeader if header_elem.nil?
|
raise MissingHeader if header_elem.nil?
|
||||||
|
|
||||||
header = header_data(header_elem.content, privkey)
|
header = header_data(header_elem.content, privkey)
|
||||||
sender = header[:author_id]
|
sender = header[:author_id]
|
||||||
cipher_params = {key: Base64.decode64(header[:aes_key]), iv: Base64.decode64(header[:iv])}
|
cipher_params = {key: Base64.decode64(header[:aes_key]), iv: Base64.decode64(header[:iv])}
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,7 @@ module DiasporaFederation
|
||||||
# @raise [InvalidEnvelope] if the envelope XML structure is malformed
|
# @raise [InvalidEnvelope] if the envelope XML structure is malformed
|
||||||
private_class_method def self.validate_envelope(env)
|
private_class_method def self.validate_envelope(env)
|
||||||
raise InvalidEnvelope unless env.instance_of?(Nokogiri::XML::Element) && env.name == "env"
|
raise InvalidEnvelope unless env.instance_of?(Nokogiri::XML::Element) && env.name == "env"
|
||||||
|
|
||||||
validate_element(env, "me:data")
|
validate_element(env, "me:data")
|
||||||
validate_element(env, "me:sig")
|
validate_element(env, "me:sig")
|
||||||
end
|
end
|
||||||
|
|
@ -190,6 +191,7 @@ module DiasporaFederation
|
||||||
private_class_method def self.sender(env)
|
private_class_method def self.sender(env)
|
||||||
key_id = env.at_xpath("me:sig")["key_id"]
|
key_id = env.at_xpath("me:sig")["key_id"]
|
||||||
raise InvalidEnvelope, "no key_id" unless key_id # TODO: move to `envelope_valid?`
|
raise InvalidEnvelope, "no key_id" unless key_id # TODO: move to `envelope_valid?`
|
||||||
|
|
||||||
Base64.urlsafe_decode64(key_id)
|
Base64.urlsafe_decode64(key_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,12 @@ module DiasporaFederation
|
||||||
# @raise [MissingMagicEnvelope] if the +me:env+ element is missing from the XML
|
# @raise [MissingMagicEnvelope] if the +me:env+ element is missing from the XML
|
||||||
def self.from_xml(slap_xml)
|
def self.from_xml(slap_xml)
|
||||||
raise ArgumentError unless slap_xml.instance_of?(String)
|
raise ArgumentError unless slap_xml.instance_of?(String)
|
||||||
|
|
||||||
doc = Nokogiri::XML(slap_xml)
|
doc = Nokogiri::XML(slap_xml)
|
||||||
|
|
||||||
author_elem = doc.at_xpath("d:diaspora/d:header/d:author_id", Slap::NS)
|
author_elem = doc.at_xpath("d:diaspora/d:header/d:author_id", Slap::NS)
|
||||||
raise MissingAuthor if author_elem.nil? || author_elem.content.empty?
|
raise MissingAuthor if author_elem.nil? || author_elem.content.empty?
|
||||||
|
|
||||||
sender = author_elem.content
|
sender = author_elem.content
|
||||||
|
|
||||||
MagicEnvelope.unenvelop(magic_env_from_doc(doc), sender)
|
MagicEnvelope.unenvelop(magic_env_from_doc(doc), sender)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
def optional_props
|
def optional_props
|
||||||
return [] unless @obj.class.respond_to?(:optional_props)
|
return [] unless @obj.class.respond_to?(:optional_props)
|
||||||
|
|
||||||
@obj.class.optional_props
|
@obj.class.optional_props
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ module Validation
|
||||||
end
|
end
|
||||||
|
|
||||||
# The Regex for validating a full diaspora* ID
|
# The Regex for validating a full diaspora* ID
|
||||||
DIASPORA_ID = /\A#{DIASPORA_ID_REGEX}\z/u
|
DIASPORA_ID = /\A#{DIASPORA_ID_REGEX}\z/u.freeze
|
||||||
|
|
||||||
# The error key for this rule
|
# The error key for this rule
|
||||||
# @return [Symbol] error key
|
# @return [Symbol] error key
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ module Validation
|
||||||
ids = value.split(";")
|
ids = value.split(";")
|
||||||
return false if params.include?(:maximum) && ids.count > params[:maximum]
|
return false if params.include?(:maximum) && ids.count > params[:maximum]
|
||||||
return false if params.include?(:minimum) && ids.count < params[:minimum]
|
return false if params.include?(:minimum) && ids.count < params[:minimum]
|
||||||
|
|
||||||
ids.each do |id|
|
ids.each do |id|
|
||||||
return false if DiasporaId::DIASPORA_ID.match(id).nil?
|
return false if DiasporaId::DIASPORA_ID.match(id).nil?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class Person
|
||||||
|
|
||||||
def find_by(opts)
|
def find_by(opts)
|
||||||
return database[:diaspora_id][opts[:diaspora_id]] if opts[:diaspora_id]
|
return database[:diaspora_id][opts[:diaspora_id]] if opts[:diaspora_id]
|
||||||
|
|
||||||
database[:guid][opts[:guid]]
|
database[:guid][opts[:guid]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue