bump rubocop and pronto-rubocop
make some refactorings for new cops
This commit is contained in:
parent
fd1dd7988d
commit
583d567d67
30 changed files with 191 additions and 211 deletions
15
.rubocop.yml
15
.rubocop.yml
|
|
@ -1,10 +1,12 @@
|
||||||
AllCops:
|
AllCops:
|
||||||
RunRailsCops: true
|
|
||||||
Exclude:
|
Exclude:
|
||||||
- "bin/**/*"
|
- "bin/**/*"
|
||||||
- "test/dummy/bin/**/*"
|
- "test/dummy/bin/**/*"
|
||||||
- "test/dummy/db/**/*"
|
- "test/dummy/db/**/*"
|
||||||
|
|
||||||
|
Rails:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
# Commonly used screens these days easily fit more than 80 characters.
|
# Commonly used screens these days easily fit more than 80 characters.
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 120
|
Max: 120
|
||||||
|
|
@ -19,6 +21,8 @@ Metrics/MethodLength:
|
||||||
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
||||||
Metrics/ClassLength:
|
Metrics/ClassLength:
|
||||||
Max: 1500
|
Max: 1500
|
||||||
|
Metrics/ModuleLength:
|
||||||
|
Max: 1500
|
||||||
|
|
||||||
# No space makes the method definition shorter and differentiates
|
# No space makes the method definition shorter and differentiates
|
||||||
# from a regular assignment.
|
# from a regular assignment.
|
||||||
|
|
@ -144,10 +148,6 @@ Style/DotPosition:
|
||||||
|
|
||||||
|
|
||||||
# diaspora_federation rules
|
# diaspora_federation rules
|
||||||
Rails/TimeZone:
|
|
||||||
Exclude:
|
|
||||||
- "spec/**/*"
|
|
||||||
|
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
Max: 10
|
Max: 10
|
||||||
Metrics/PerceivedComplexity:
|
Metrics/PerceivedComplexity:
|
||||||
|
|
@ -157,8 +157,9 @@ Metrics/AbcSize:
|
||||||
Exclude:
|
Exclude:
|
||||||
- "lib/diaspora_federation/test/factories.rb"
|
- "lib/diaspora_federation/test/factories.rb"
|
||||||
|
|
||||||
Metrics/ModuleLength:
|
Rails/TimeZone:
|
||||||
Max: 1500
|
Exclude:
|
||||||
|
- "spec/lib/**/*"
|
||||||
|
|
||||||
Style/SingleLineMethods:
|
Style/SingleLineMethods:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|
|
||||||
4
Gemfile
4
Gemfile
|
|
@ -17,9 +17,9 @@ end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
# code style
|
# code style
|
||||||
gem "rubocop", "0.35.1"
|
gem "rubocop", "0.36.0"
|
||||||
gem "pronto", "0.5.3"
|
gem "pronto", "0.5.3"
|
||||||
gem "pronto-rubocop", "0.5.0", require: false
|
gem "pronto-rubocop", "0.5.2", require: false
|
||||||
|
|
||||||
# debugging
|
# debugging
|
||||||
gem "pry"
|
gem "pry"
|
||||||
|
|
|
||||||
17
Gemfile.lock
17
Gemfile.lock
|
|
@ -55,8 +55,6 @@ GEM
|
||||||
addressable (2.3.8)
|
addressable (2.3.8)
|
||||||
arel (6.0.3)
|
arel (6.0.3)
|
||||||
ast (2.2.0)
|
ast (2.2.0)
|
||||||
astrolabe (1.3.1)
|
|
||||||
parser (~> 2.2)
|
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
byebug (8.2.1)
|
byebug (8.2.1)
|
||||||
codeclimate-test-reporter (0.4.8)
|
codeclimate-test-reporter (0.4.8)
|
||||||
|
|
@ -156,9 +154,9 @@ GEM
|
||||||
octokit (~> 4.1.0)
|
octokit (~> 4.1.0)
|
||||||
rugged (~> 0.23.0)
|
rugged (~> 0.23.0)
|
||||||
thor (~> 0.19.0)
|
thor (~> 0.19.0)
|
||||||
pronto-rubocop (0.5.0)
|
pronto-rubocop (0.5.2)
|
||||||
pronto (~> 0.5.0)
|
pronto (~> 0.5.0)
|
||||||
rubocop (~> 0.35.0)
|
rubocop (~> 0.36.0)
|
||||||
pry (0.10.3)
|
pry (0.10.3)
|
||||||
coderay (~> 1.1.0)
|
coderay (~> 1.1.0)
|
||||||
method_source (~> 0.8.1)
|
method_source (~> 0.8.1)
|
||||||
|
|
@ -223,13 +221,11 @@ GEM
|
||||||
rspec-mocks (~> 3.4.0)
|
rspec-mocks (~> 3.4.0)
|
||||||
rspec-support (~> 3.4.0)
|
rspec-support (~> 3.4.0)
|
||||||
rspec-support (3.4.1)
|
rspec-support (3.4.1)
|
||||||
rubocop (0.35.1)
|
rubocop (0.36.0)
|
||||||
astrolabe (~> 1.3)
|
parser (>= 2.3.0.0, < 3.0)
|
||||||
parser (>= 2.2.3.0, < 3.0)
|
|
||||||
powerpack (~> 0.1)
|
powerpack (~> 0.1)
|
||||||
rainbow (>= 1.99.1, < 3.0)
|
rainbow (>= 1.99.1, < 3.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
tins (<= 1.6.0)
|
|
||||||
ruby-progressbar (1.7.5)
|
ruby-progressbar (1.7.5)
|
||||||
rugged (0.23.3)
|
rugged (0.23.3)
|
||||||
safe_yaml (1.0.4)
|
safe_yaml (1.0.4)
|
||||||
|
|
@ -263,7 +259,6 @@ GEM
|
||||||
terminal-table (1.5.2)
|
terminal-table (1.5.2)
|
||||||
thor (0.19.1)
|
thor (0.19.1)
|
||||||
thread_safe (0.3.5)
|
thread_safe (0.3.5)
|
||||||
tins (1.6.0)
|
|
||||||
typhoeus (1.0.1)
|
typhoeus (1.0.1)
|
||||||
ethon (>= 0.8.0)
|
ethon (>= 0.8.0)
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
|
|
@ -293,13 +288,13 @@ DEPENDENCIES
|
||||||
logging-rails (= 0.5.0)
|
logging-rails (= 0.5.0)
|
||||||
nyan-cat-formatter
|
nyan-cat-formatter
|
||||||
pronto (= 0.5.3)
|
pronto (= 0.5.3)
|
||||||
pronto-rubocop (= 0.5.0)
|
pronto-rubocop (= 0.5.2)
|
||||||
pry
|
pry
|
||||||
pry-byebug
|
pry-byebug
|
||||||
pry-debundle
|
pry-debundle
|
||||||
rspec-collection_matchers (~> 1.1.2)
|
rspec-collection_matchers (~> 1.1.2)
|
||||||
rspec-rails (~> 3.4.0)
|
rspec-rails (~> 3.4.0)
|
||||||
rubocop (= 0.35.1)
|
rubocop (= 0.36.0)
|
||||||
simplecov (= 0.11.1)
|
simplecov (= 0.11.1)
|
||||||
simplecov-rcov (= 0.2.3)
|
simplecov-rcov (= 0.2.3)
|
||||||
spring
|
spring
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,14 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# creates the host-meta xml with the configured server_uri and caches it
|
# creates the host-meta xml with the configured server_uri and caches it
|
||||||
# @return [String] XML string
|
# @return [String] XML string
|
||||||
def self.host_meta_xml
|
def self.host_meta_xml
|
||||||
@host_meta_xml ||= Discovery::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s).to_xml
|
@host_meta_xml ||= Discovery::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s).to_xml
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def find_person_webfinger(query)
|
def find_person_webfinger(query)
|
||||||
DiasporaFederation.callbacks.trigger(:fetch_person_for_webfinger, query.strip.downcase.sub("acct:", ""))
|
DiasporaFederation.callbacks.trigger(:fetch_person_for_webfinger, query.strip.downcase.sub("acct:", ""))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ module DiasporaFederation
|
||||||
photo_small: ".entity_photo_small .photo[src]",
|
photo_small: ".entity_photo_small .photo[src]",
|
||||||
key: ".key",
|
key: ".key",
|
||||||
searchable: ".searchable"
|
searchable: ".searchable"
|
||||||
}
|
}.freeze
|
||||||
|
|
||||||
# Create the HTML string from the current HCard instance
|
# Create the HTML string from the current HCard instance
|
||||||
# @return [String] HTML string
|
# @return [String] HTML string
|
||||||
|
|
@ -209,13 +209,13 @@ module DiasporaFederation
|
||||||
#
|
#
|
||||||
# @param container [Nokogiri::XML::Element] parent element for added property HTML
|
# @param container [Nokogiri::XML::Element] parent element for added property HTML
|
||||||
# @param name [Symbol] property name
|
# @param name [Symbol] property name
|
||||||
# @param block [Proc] block returning an element
|
# @yield [Nokogiri::HTML::Builder] html builder
|
||||||
def add_property(container, name, &block)
|
def add_property(container, name)
|
||||||
Nokogiri::HTML::Builder.with(container) do |html|
|
Nokogiri::HTML::Builder.with(container) do |html|
|
||||||
html.dl(class: "entity_#{name}") {
|
html.dl(class: "entity_#{name}") {
|
||||||
html.dt(name.to_s.capitalize)
|
html.dt(name.to_s.capitalize)
|
||||||
html.dd {
|
html.dd {
|
||||||
block.call(html)
|
yield html
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
# URL fragment to append to the base URL
|
# URL fragment to append to the base URL
|
||||||
WEBFINGER_SUFFIX = "/webfinger?q={uri}"
|
WEBFINGER_SUFFIX = "/webfinger?q={uri}".freeze
|
||||||
|
|
||||||
# Returns the WebFinger URL that was used to build this instance (either from
|
# Returns the WebFinger URL that was used to build this instance (either from
|
||||||
# xml or by giving a base URL).
|
# xml or by giving a base URL).
|
||||||
|
|
|
||||||
|
|
@ -104,35 +104,35 @@ module DiasporaFederation
|
||||||
property :public_key
|
property :public_key
|
||||||
|
|
||||||
# +hcard_url+ link relation
|
# +hcard_url+ link relation
|
||||||
REL_HCARD = "http://microformats.org/profile/hcard"
|
REL_HCARD = "http://microformats.org/profile/hcard".freeze
|
||||||
|
|
||||||
# +seed_url+ link relation
|
# +seed_url+ link relation
|
||||||
REL_SEED = "http://joindiaspora.com/seed_location"
|
REL_SEED = "http://joindiaspora.com/seed_location".freeze
|
||||||
|
|
||||||
# @deprecated This should be a +Property+ or moved to the +hCard+, but +Link+
|
# @deprecated This should be a +Property+ or moved to the +hCard+, but +Link+
|
||||||
# is inappropriate according to the specification (will affect older
|
# is inappropriate according to the specification (will affect older
|
||||||
# Diaspora* installations).
|
# Diaspora* installations).
|
||||||
# +guid+ link relation
|
# +guid+ link relation
|
||||||
REL_GUID = "http://joindiaspora.com/guid"
|
REL_GUID = "http://joindiaspora.com/guid".freeze
|
||||||
|
|
||||||
# +profile_url+ link relation.
|
# +profile_url+ link relation.
|
||||||
# @note This might just as well be an +Alias+ instead of a +Link+.
|
# @note This might just as well be an +Alias+ instead of a +Link+.
|
||||||
REL_PROFILE = "http://webfinger.net/rel/profile-page"
|
REL_PROFILE = "http://webfinger.net/rel/profile-page".freeze
|
||||||
|
|
||||||
# +atom_url+ link relation
|
# +atom_url+ link relation
|
||||||
REL_ATOM = "http://schemas.google.com/g/2010#updates-from"
|
REL_ATOM = "http://schemas.google.com/g/2010#updates-from".freeze
|
||||||
|
|
||||||
# +salmon_url+ link relation
|
# +salmon_url+ link relation
|
||||||
REL_SALMON = "salmon"
|
REL_SALMON = "salmon".freeze
|
||||||
|
|
||||||
# +subscribe_url+ link relation
|
# +subscribe_url+ link relation
|
||||||
REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe"
|
REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe".freeze
|
||||||
|
|
||||||
# @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+
|
# @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+
|
||||||
# is inappropriate according to the specification (will affect older
|
# is inappropriate according to the specification (will affect older
|
||||||
# Diaspora* installations).
|
# Diaspora* installations).
|
||||||
# +pubkey+ link relation
|
# +pubkey+ link relation
|
||||||
REL_PUBKEY = "diaspora-public-key"
|
REL_PUBKEY = "diaspora-public-key".freeze
|
||||||
|
|
||||||
# Create the XML string from the current WebFinger instance
|
# Create the XML string from the current WebFinger instance
|
||||||
# @return [String] XML string
|
# @return [String] XML string
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,13 @@ module DiasporaFederation
|
||||||
# @see http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html Extensible Resource Descriptor (XRD) Version 1.0
|
# @see http://docs.oasis-open.org/xri/xrd/v1.0/xrd-1.0.html Extensible Resource Descriptor (XRD) Version 1.0
|
||||||
class XrdDocument
|
class XrdDocument
|
||||||
# xml namespace url
|
# xml namespace url
|
||||||
XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0"
|
XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0".freeze
|
||||||
|
|
||||||
# +Link+ element attributes
|
# +Link+ element attributes
|
||||||
LINK_ATTRS = %i(rel type href template)
|
LINK_ATTRS = %i(rel type href template).freeze
|
||||||
|
|
||||||
# format string for datetime (+Expires+ element)
|
# format string for datetime (+Expires+ element)
|
||||||
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
|
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ".freeze
|
||||||
|
|
||||||
# The <Expires> element contains a time value which specifies the instant at
|
# The <Expires> element contains a time value which specifies the instant at
|
||||||
# and after which the document has expired and SHOULD NOT be used.
|
# and after which the document has expired and SHOULD NOT be used.
|
||||||
|
|
@ -107,7 +107,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
NS = {xrd: XMLNS}
|
NS = {xrd: XMLNS}.freeze
|
||||||
|
|
||||||
def add_aliases_to(xml)
|
def add_aliases_to(xml)
|
||||||
@aliases.each do |a|
|
@aliases.each do |a|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module DiasporaFederation
|
||||||
# {http://www.salmon-protocol.org/ Salmon Protocol}.
|
# {http://www.salmon-protocol.org/ Salmon Protocol}.
|
||||||
module Salmon
|
module Salmon
|
||||||
# XML namespace url
|
# XML namespace url
|
||||||
XMLNS = "https://joindiaspora.com/protocol"
|
XMLNS = "https://joindiaspora.com/protocol".freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module DiasporaFederation
|
||||||
# class for AES encryption and decryption
|
# class for AES encryption and decryption
|
||||||
class AES
|
class AES
|
||||||
# OpenSSL aes cipher definition
|
# OpenSSL aes cipher definition
|
||||||
CIPHER = "AES-256-CBC"
|
CIPHER = "AES-256-CBC".freeze
|
||||||
|
|
||||||
# generates a random AES key and initialization vector
|
# generates a random AES key and initialization vector
|
||||||
# @return [Hash] { key: "...", iv: "..." }
|
# @return [Hash] { key: "...", iv: "..." }
|
||||||
|
|
|
||||||
|
|
@ -25,19 +25,19 @@ module DiasporaFederation
|
||||||
attr_reader :payload
|
attr_reader :payload
|
||||||
|
|
||||||
# encoding used for the payload data
|
# encoding used for the payload data
|
||||||
ENCODING = "base64url"
|
ENCODING = "base64url".freeze
|
||||||
|
|
||||||
# algorithm used for signing the payload data
|
# algorithm used for signing the payload data
|
||||||
ALGORITHM = "RSA-SHA256"
|
ALGORITHM = "RSA-SHA256".freeze
|
||||||
|
|
||||||
# mime type describing the payload data
|
# mime type describing the payload data
|
||||||
DATA_TYPE = "application/xml"
|
DATA_TYPE = "application/xml".freeze
|
||||||
|
|
||||||
# digest instance used for signing
|
# digest instance used for signing
|
||||||
DIGEST = OpenSSL::Digest::SHA256.new
|
DIGEST = OpenSSL::Digest::SHA256.new
|
||||||
|
|
||||||
# XML namespace url
|
# XML namespace url
|
||||||
XMLNS = "http://salmon-protocol.org/ns/magic-env"
|
XMLNS = "http://salmon-protocol.org/ns/magic-env".freeze
|
||||||
|
|
||||||
# Creates a new instance of MagicEnvelope.
|
# Creates a new instance of MagicEnvelope.
|
||||||
#
|
#
|
||||||
|
|
@ -128,10 +128,7 @@ module DiasporaFederation
|
||||||
#
|
#
|
||||||
# @return [String] the signature
|
# @return [String] the signature
|
||||||
def signature
|
def signature
|
||||||
subject = self.class.sig_subject([@payload,
|
subject = MagicEnvelope.send(:sig_subject, [@payload, DATA_TYPE, ENCODING, ALGORITHM])
|
||||||
DATA_TYPE,
|
|
||||||
ENCODING,
|
|
||||||
ALGORITHM])
|
|
||||||
@rsa_privkey.sign(DIGEST, subject)
|
@rsa_privkey.sign(DIGEST, subject)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -168,6 +165,7 @@ module DiasporaFederation
|
||||||
def self.sig_subject(data_arr)
|
def self.sig_subject(data_arr)
|
||||||
data_arr.map {|i| Base64.urlsafe_encode64(i) }.join(".")
|
data_arr.map {|i| Base64.urlsafe_encode64(i) }.join(".")
|
||||||
end
|
end
|
||||||
|
private_class_method :sig_subject
|
||||||
|
|
||||||
# @param [Nokogiri::XML::Element] magic_env magic envelope XML
|
# @param [Nokogiri::XML::Element] magic_env magic envelope XML
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ module DiasporaFederation
|
||||||
attr_accessor :author_id
|
attr_accessor :author_id
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
NS = {d: Salmon::XMLNS, me: MagicEnvelope::XMLNS}
|
NS = {d: Salmon::XMLNS, me: MagicEnvelope::XMLNS}.freeze
|
||||||
|
|
||||||
# Returns new instance of the Entity that is contained within the XML of
|
# Returns new instance of the Entity that is contained within the XML of
|
||||||
# this Slap.
|
# this Slap.
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,6 @@ module DiasporaFederation
|
||||||
populate_entity(klass, data)
|
populate_entity(klass, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# @param [Nokogiri::XML::Element] element
|
# @param [Nokogiri::XML::Element] element
|
||||||
def self.wrap_valid?(element)
|
def self.wrap_valid?(element)
|
||||||
(element.name == "XML" && !element.at_xpath("post").nil? &&
|
(element.name == "XML" && !element.at_xpath("post").nil? &&
|
||||||
|
|
|
||||||
|
|
@ -43,14 +43,13 @@ module DiasporaFederation
|
||||||
validity
|
validity
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# @param [Hash] hash data to sign
|
# @param [Hash] hash data to sign
|
||||||
# @return [String] signature data string
|
# @return [String] signature data string
|
||||||
def self.signable_string(hash)
|
def self.signable_string(hash)
|
||||||
hash.map {|name, value|
|
hash.map {|name, value|
|
||||||
value.to_s unless name.match(/signature/)
|
value.to_s unless name =~ /signature/
|
||||||
}.compact.join(";")
|
}.compact.join(";")
|
||||||
end
|
end
|
||||||
|
private_class_method :signable_string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ module DiasporaFederation
|
||||||
created_at { Time.now.utc }
|
created_at { Time.now.utc }
|
||||||
messages []
|
messages []
|
||||||
diaspora_id
|
diaspora_id
|
||||||
participant_ids { 3.times.map { generate(:diaspora_id) }.join(";") }
|
participant_ids { Array.new(3) { generate(:diaspora_id) }.join(";") }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :message_entity, class: DiasporaFederation::Entities::Message, parent: :relayable_entity do
|
factory :message_entity, class: DiasporaFederation::Entities::Message, parent: :relayable_entity do
|
||||||
|
|
@ -179,7 +179,7 @@ module DiasporaFederation
|
||||||
factory :poll_entity, class: DiasporaFederation::Entities::Poll do
|
factory :poll_entity, class: DiasporaFederation::Entities::Poll do
|
||||||
guid
|
guid
|
||||||
question { "Select an answer" }
|
question { "Select an answer" }
|
||||||
poll_answers { 3.times.map { FactoryGirl.build(:poll_answer_entity) } }
|
poll_answers { Array.new(3) { FactoryGirl.build(:poll_answer_entity) } }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :poll_participation_entity,
|
factory :poll_participation_entity,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
# the gem version
|
# the gem version
|
||||||
VERSION = "0.0.11"
|
VERSION = "0.0.11".freeze
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,10 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls the fetch_person_for_hcard callback" do
|
it "calls the fetch_person_for_hcard callback" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_person_for_hcard, alice.guid)
|
:fetch_person_for_hcard, alice.guid
|
||||||
.and_call_original
|
).and_call_original
|
||||||
|
|
||||||
get :hcard, "guid" => alice.guid
|
get :hcard, "guid" => alice.guid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,14 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a 202 if queued correctly" do
|
it "returns a 202 if queued correctly" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:queue_public_receive, "<diaspora/>")
|
||||||
.with(:queue_public_receive, "<diaspora/>")
|
|
||||||
|
|
||||||
post :public, xml: "<diaspora/>"
|
post :public, xml: "<diaspora/>"
|
||||||
expect(response.code).to eq("202")
|
expect(response.code).to eq("202")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "unescapes the xml before sending it to the callback" do
|
it "unescapes the xml before sending it to the callback" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:queue_public_receive, "<diaspora/>")
|
||||||
.with(:queue_public_receive, "<diaspora/>")
|
|
||||||
|
|
||||||
post :public, xml: CGI.escape("<diaspora/>")
|
post :public, xml: CGI.escape("<diaspora/>")
|
||||||
end
|
end
|
||||||
|
|
@ -26,9 +24,9 @@ module DiasporaFederation
|
||||||
|
|
||||||
describe "POST #private" do
|
describe "POST #private" do
|
||||||
it "return a 404 if not queued successfully (unknown user guid)" do
|
it "return a 404 if not queued successfully (unknown user guid)" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:queue_private_receive, "any-guid", "<diaspora/>")
|
:queue_private_receive, "any-guid", "<diaspora/>"
|
||||||
.and_return(false)
|
).and_return(false)
|
||||||
|
|
||||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||||
expect(response.code).to eq("404")
|
expect(response.code).to eq("404")
|
||||||
|
|
@ -40,18 +38,18 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a 202 if the callback returned true" do
|
it "returns a 202 if the callback returned true" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:queue_private_receive, "any-guid", "<diaspora/>")
|
:queue_private_receive, "any-guid", "<diaspora/>"
|
||||||
.and_return(true)
|
).and_return(true)
|
||||||
|
|
||||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||||
expect(response.code).to eq("202")
|
expect(response.code).to eq("202")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "unescapes the xml before sending it to the callback" do
|
it "unescapes the xml before sending it to the callback" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:queue_private_receive, "any-guid", "<diaspora/>")
|
:queue_private_receive, "any-guid", "<diaspora/>"
|
||||||
.and_return(true)
|
).and_return(true)
|
||||||
|
|
||||||
post :private, guid: "any-guid", xml: CGI.escape("<diaspora/>")
|
post :private, guid: "any-guid", xml: CGI.escape("<diaspora/>")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,10 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls the fetch_person_for_webfinger callback" do
|
it "calls the fetch_person_for_webfinger callback" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_person_for_webfinger, "alice@localhost:3000")
|
:fetch_person_for_webfinger, "alice@localhost:3000"
|
||||||
.and_call_original
|
).and_call_original
|
||||||
|
|
||||||
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,13 @@ XML
|
||||||
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }
|
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }
|
||||||
|
|
||||||
it "updates author signature when it was nil and key was supplied" do
|
it "updates author signature when it was nil and key was supplied" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(
|
:fetch_entity_author_id_by_guid, hash[:target_type], hash[:target_guid]
|
||||||
:fetch_entity_author_id_by_guid,
|
).and_return(hash[:diaspora_id])
|
||||||
hash[:target_type],
|
|
||||||
hash[:target_guid]
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
)
|
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(hash[:diaspora_id])
|
).and_return(author_pkey)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
|
|
||||||
.and_return(author_pkey)
|
|
||||||
|
|
||||||
Entities::RelayableRetraction.update_signatures!(hash)
|
Entities::RelayableRetraction.update_signatures!(hash)
|
||||||
|
|
||||||
|
|
@ -43,16 +40,13 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates parent author signature when it was nil, key was supplied and sender is not author of the target" do
|
it "updates parent author signature when it was nil, key was supplied and sender is not author of the target" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(
|
:fetch_entity_author_id_by_guid, hash[:target_type], hash[:target_guid]
|
||||||
:fetch_entity_author_id_by_guid,
|
).and_return(FactoryGirl.generate(:diaspora_id))
|
||||||
hash[:target_type],
|
|
||||||
hash[:target_guid]
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
)
|
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(FactoryGirl.generate(:diaspora_id))
|
).and_return(author_pkey)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
|
|
||||||
.and_return(author_pkey)
|
|
||||||
|
|
||||||
Entities::RelayableRetraction.update_signatures!(hash)
|
Entities::RelayableRetraction.update_signatures!(hash)
|
||||||
|
|
||||||
|
|
@ -71,12 +65,13 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't change signatures if keys weren't supplied" do
|
it "doesn't change signatures if keys weren't supplied" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(nil)
|
).and_return(nil)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(:fetch_entity_author_id_by_guid, "Comment", hash[:target_guid])
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.and_return(hash[:diaspora_id])
|
:fetch_entity_author_id_by_guid, "Comment", hash[:target_guid]
|
||||||
|
).and_return(hash[:diaspora_id])
|
||||||
|
|
||||||
Entities::RelayableRetraction.update_signatures!(hash)
|
Entities::RelayableRetraction.update_signatures!(hash)
|
||||||
expect(hash[:target_author_signature]).to eq(nil)
|
expect(hash[:target_author_signature]).to eq(nil)
|
||||||
|
|
|
||||||
|
|
@ -19,25 +19,25 @@ module DiasporaFederation
|
||||||
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
||||||
hash[:parent_author_signature] = Signing.sign_with_key(hash, parent_pkey)
|
hash[:parent_author_signature] = Signing.sign_with_key(hash, parent_pkey)
|
||||||
|
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(author_pkey.public_key)
|
).and_return(author_pkey.public_key)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
:fetch_author_public_key_by_entity_guid,
|
:fetch_author_public_key_by_entity_guid, "Post", hash[:parent_guid]
|
||||||
"Post",
|
).and_return(parent_pkey.public_key)
|
||||||
hash[:parent_guid]
|
|
||||||
)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.and_return(parent_pkey.public_key)
|
:entity_author_is_local?, "Post", hash[:parent_guid]
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
).and_return(false)
|
||||||
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
|
|
||||||
.and_return(false)
|
|
||||||
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.not_to raise_error
|
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.not_to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises when no public key for author was fetched" do
|
it "raises when no public key for author was fetched" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:fetch_public_key_by_diaspora_id, anything)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.and_return(nil)
|
:fetch_public_key_by_diaspora_id, anything
|
||||||
|
).and_return(nil)
|
||||||
|
|
||||||
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
||||||
Entities::Relayable::SignatureVerificationFailed
|
Entities::Relayable::SignatureVerificationFailed
|
||||||
|
|
@ -47,9 +47,10 @@ module DiasporaFederation
|
||||||
it "raises when bad author signature was passed" do
|
it "raises when bad author signature was passed" do
|
||||||
hash[:author_signature] = nil
|
hash[:author_signature] = nil
|
||||||
|
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(author_pkey.public_key)
|
).and_return(author_pkey.public_key)
|
||||||
|
|
||||||
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
||||||
Entities::Relayable::SignatureVerificationFailed
|
Entities::Relayable::SignatureVerificationFailed
|
||||||
)
|
)
|
||||||
|
|
@ -58,19 +59,18 @@ module DiasporaFederation
|
||||||
it "raises when no public key for parent author was fetched" do
|
it "raises when no public key for parent author was fetched" do
|
||||||
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
||||||
|
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(author_pkey.public_key)
|
).and_return(author_pkey.public_key)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
:fetch_author_public_key_by_entity_guid,
|
:fetch_author_public_key_by_entity_guid, "Post", hash[:parent_guid]
|
||||||
"Post",
|
).and_return(nil)
|
||||||
hash[:parent_guid]
|
|
||||||
)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.and_return(nil)
|
:entity_author_is_local?, "Post", hash[:parent_guid]
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
).and_return(false)
|
||||||
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
|
|
||||||
.and_return(false)
|
|
||||||
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
||||||
Entities::Relayable::SignatureVerificationFailed
|
Entities::Relayable::SignatureVerificationFailed
|
||||||
)
|
)
|
||||||
|
|
@ -80,19 +80,18 @@ module DiasporaFederation
|
||||||
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
||||||
hash[:parent_author_signature] = nil
|
hash[:parent_author_signature] = nil
|
||||||
|
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(author_pkey.public_key)
|
).and_return(author_pkey.public_key)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
:fetch_author_public_key_by_entity_guid,
|
:fetch_author_public_key_by_entity_guid, "Post", hash[:parent_guid]
|
||||||
"Post",
|
).and_return(parent_pkey.public_key)
|
||||||
hash[:parent_guid]
|
|
||||||
)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.and_return(parent_pkey.public_key)
|
:entity_author_is_local?, "Post", hash[:parent_guid]
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
).and_return(false)
|
||||||
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
|
|
||||||
.and_return(false)
|
|
||||||
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
|
||||||
Entities::Relayable::SignatureVerificationFailed
|
Entities::Relayable::SignatureVerificationFailed
|
||||||
)
|
)
|
||||||
|
|
@ -102,28 +101,27 @@ module DiasporaFederation
|
||||||
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
|
||||||
hash[:parent_author_signature] = nil
|
hash[:parent_author_signature] = nil
|
||||||
|
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(author_pkey.public_key)
|
).and_return(author_pkey.public_key)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.and_return(true)
|
:entity_author_is_local?, "Post", hash[:parent_guid]
|
||||||
|
).and_return(true)
|
||||||
|
|
||||||
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.not_to raise_error
|
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.not_to raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".update_singatures!" do
|
describe ".update_singatures!" do
|
||||||
it "updates signatures when they were nil and keys were supplied" do
|
it "updates signatures when they were nil and keys were supplied" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(author_pkey)
|
).and_return(author_pkey)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
:fetch_author_private_key_by_entity_guid,
|
:fetch_author_private_key_by_entity_guid, "Post", hash[:parent_guid]
|
||||||
"Post",
|
).and_return(parent_pkey)
|
||||||
hash[:parent_guid]
|
|
||||||
)
|
|
||||||
.and_return(parent_pkey)
|
|
||||||
|
|
||||||
Entities::Relayable.update_signatures!(hash, SomeRelayable)
|
Entities::Relayable.update_signatures!(hash, SomeRelayable)
|
||||||
expect(Signing.verify_signature(hash, hash[:author_signature], author_pkey)).to be_truthy
|
expect(Signing.verify_signature(hash, hash[:author_signature], author_pkey)).to be_truthy
|
||||||
|
|
@ -140,16 +138,13 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't change signatures if keys weren't supplied" do
|
it "doesn't change signatures if keys weren't supplied" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(nil)
|
).and_return(nil)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
:fetch_author_private_key_by_entity_guid,
|
:fetch_author_private_key_by_entity_guid, "Post", hash[:parent_guid]
|
||||||
"Post",
|
).and_return(nil)
|
||||||
hash[:parent_guid]
|
|
||||||
)
|
|
||||||
.and_return(nil)
|
|
||||||
|
|
||||||
Entities::Relayable.update_signatures!(hash, SomeRelayable)
|
Entities::Relayable.update_signatures!(hash, SomeRelayable)
|
||||||
expect(hash[:author_signature]).to eq(nil)
|
expect(hash[:author_signature]).to eq(nil)
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ XML
|
||||||
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }
|
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }
|
||||||
|
|
||||||
it "updates author signature when it was nil and key was supplied" do
|
it "updates author signature when it was nil and key was supplied" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(author_pkey)
|
).and_return(author_pkey)
|
||||||
|
|
||||||
signable_hash = hash.select do |key, _|
|
signable_hash = hash.select do |key, _|
|
||||||
%i(target_guid target_type).include?(key)
|
%i(target_guid target_type).include?(key)
|
||||||
|
|
@ -44,9 +44,9 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't change signature if a key wasn't supplied" do
|
it "doesn't change signature if a key wasn't supplied" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
|
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
|
||||||
.and_return(nil)
|
).and_return(nil)
|
||||||
|
|
||||||
Entities::SignedRetraction.update_signatures!(hash)
|
Entities::SignedRetraction.update_signatures!(hash)
|
||||||
expect(hash[:author_signature]).to eq(nil)
|
expect(hash[:author_signature]).to eq(nil)
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,19 @@ module DiasporaFederation
|
||||||
}
|
}
|
||||||
|
|
||||||
it "calls save_entity_after_receive if everything is fine" do
|
it "calls save_entity_after_receive if everything is fine" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, sender_id)
|
:fetch_public_key_by_diaspora_id, sender_id
|
||||||
.and_return(sender_key)
|
).and_return(sender_key)
|
||||||
|
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:save_entity_after_receive, kind_of(Entity))
|
||||||
.with(:save_entity_after_receive, kind_of(Entity))
|
|
||||||
|
|
||||||
described_class.new(xml, recipient_key).receive!
|
described_class.new(xml, recipient_key).receive!
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises when sender public key is not available" do
|
it "raises when sender public key is not available" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, sender_id)
|
:fetch_public_key_by_diaspora_id, sender_id
|
||||||
.and_return(nil)
|
).and_return(nil)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(xml, recipient_key).receive!
|
described_class.new(xml, recipient_key).receive!
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,19 @@ module DiasporaFederation
|
||||||
}
|
}
|
||||||
|
|
||||||
it "calls save_entity_after_receive if everything is fine" do
|
it "calls save_entity_after_receive if everything is fine" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, sender_id)
|
:fetch_public_key_by_diaspora_id, sender_id
|
||||||
.and_return(sender_key)
|
).and_return(sender_key)
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
|
||||||
.with(:save_entity_after_receive, kind_of(Entity))
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:save_entity_after_receive, kind_of(Entity))
|
||||||
|
|
||||||
described_class.new(xml).receive!
|
described_class.new(xml).receive!
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises when sender public key is not available" do
|
it "raises when sender public key is not available" do
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger)
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
|
||||||
.with(:fetch_public_key_by_diaspora_id, sender_id)
|
:fetch_public_key_by_diaspora_id, sender_id
|
||||||
.and_return(nil)
|
).and_return(nil)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
described_class.new(xml).receive!
|
described_class.new(xml).receive!
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ module DiasporaFederation
|
||||||
describe "#insert_job" do
|
describe "#insert_job" do
|
||||||
it "queues a request to hydra" do
|
it "queues a request to hydra" do
|
||||||
expect(hydra).to receive(:queue).with(kind_of(Typhoeus::Request))
|
expect(hydra).to receive(:queue).with(kind_of(Typhoeus::Request))
|
||||||
expect(Typhoeus::Request).to receive(:new)
|
expect(Typhoeus::Request).to receive(:new).with(
|
||||||
.with(url, Federation::Sender::HydraWrapper.hydra_opts.merge(body: {xml: xml}))
|
url, Federation::Sender::HydraWrapper.hydra_opts.merge(body: {xml: xml})
|
||||||
.and_call_original
|
).and_call_original
|
||||||
|
|
||||||
hydra_wrapper.insert_job(url, xml)
|
hydra_wrapper.insert_job(url, xml)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ RSA
|
||||||
|
|
||||||
describe ".signable_string" do
|
describe ".signable_string" do
|
||||||
it "forms correct string for a hash" do
|
it "forms correct string for a hash" do
|
||||||
expect(Signing.signable_string(hash)).to eq("1;2;3;4")
|
expect(Signing.send(:signable_string, hash)).to eq("1;2;3;4")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ module DiasporaFederation
|
||||||
# must not contain more than 20 participant handles
|
# must not contain more than 20 participant handles
|
||||||
it_behaves_like "a property with a value validation/restriction" do
|
it_behaves_like "a property with a value validation/restriction" do
|
||||||
let(:property) { :participant_ids }
|
let(:property) { :participant_ids }
|
||||||
let(:wrong_values) { [21.times.map { FactoryGirl.generate(:diaspora_id) }.join(";")] }
|
let(:wrong_values) { [Array.new(21) { FactoryGirl.generate(:diaspora_id) }.join(";")] }
|
||||||
let(:correct_values) { [20.times.map { FactoryGirl.generate(:diaspora_id) }.join(";")] }
|
let(:correct_values) { [Array.new(20) { FactoryGirl.generate(:diaspora_id) }.join(";")] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
describe Validation::Rule::DiasporaIdCount do
|
describe Validation::Rule::DiasporaIdCount do
|
||||||
let(:id_str) { 3.times.map { FactoryGirl.generate(:diaspora_id) }.join(";") }
|
let(:id_str) { Array.new(3) { FactoryGirl.generate(:diaspora_id) }.join(";") }
|
||||||
|
|
||||||
it "requires a parameter" do
|
it "requires a parameter" do
|
||||||
validator = Validation::Validator.new({})
|
validator = Validation::Validator.new({})
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ def entity_stub(entity, data={})
|
||||||
OpenStruct.new(FactoryGirl.attributes_for(entity).merge(data))
|
OpenStruct.new(FactoryGirl.attributes_for(entity).merge(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"]
|
ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"].freeze
|
||||||
|
|
||||||
def alphanumeric_string(length)
|
def alphanumeric_string(length)
|
||||||
Array.new(length) { ALPHANUMERIC_RANGE.sample }.join
|
Array.new(length) { ALPHANUMERIC_RANGE.sample }.join
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
require "diaspora_federation/discovery"
|
require "diaspora_federation/discovery"
|
||||||
|
|
||||||
if File.file?("/etc/ssl/certs/ca-certificates.crt")
|
ca_file = if File.file?("/etc/ssl/certs/ca-certificates.crt")
|
||||||
# For Debian, Ubuntu, Archlinux, Gentoo
|
# For Debian, Ubuntu, Archlinux, Gentoo
|
||||||
ca_file = "/etc/ssl/certs/ca-certificates.crt"
|
"/etc/ssl/certs/ca-certificates.crt"
|
||||||
else
|
else
|
||||||
# For CentOS, Fedora
|
# For CentOS, Fedora
|
||||||
ca_file = "/etc/pki/tls/certs/ca-bundle.crt"
|
"/etc/pki/tls/certs/ca-bundle.crt"
|
||||||
end
|
end
|
||||||
|
|
||||||
# configure the federation engine
|
# configure the federation engine
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue