bump rubocop and pronto-rubocop

make some refactorings for new cops
This commit is contained in:
Benjamin Neff 2016-01-19 01:31:34 +01:00
parent fd1dd7988d
commit 583d567d67
30 changed files with 191 additions and 211 deletions

View file

@ -1,10 +1,12 @@
AllCops:
RunRailsCops: true
Exclude:
- "bin/**/*"
- "test/dummy/bin/**/*"
- "test/dummy/db/**/*"
Rails:
Enabled: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
@ -19,6 +21,8 @@ Metrics/MethodLength:
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
Metrics/ClassLength:
Max: 1500
Metrics/ModuleLength:
Max: 1500
# No space makes the method definition shorter and differentiates
# from a regular assignment.
@ -144,10 +148,6 @@ Style/DotPosition:
# diaspora_federation rules
Rails/TimeZone:
Exclude:
- "spec/**/*"
Metrics/CyclomaticComplexity:
Max: 10
Metrics/PerceivedComplexity:
@ -157,8 +157,9 @@ Metrics/AbcSize:
Exclude:
- "lib/diaspora_federation/test/factories.rb"
Metrics/ModuleLength:
Max: 1500
Rails/TimeZone:
Exclude:
- "spec/lib/**/*"
Style/SingleLineMethods:
Exclude:

View file

@ -17,9 +17,9 @@ end
group :development do
# code style
gem "rubocop", "0.35.1"
gem "rubocop", "0.36.0"
gem "pronto", "0.5.3"
gem "pronto-rubocop", "0.5.0", require: false
gem "pronto-rubocop", "0.5.2", require: false
# debugging
gem "pry"

View file

@ -55,8 +55,6 @@ GEM
addressable (2.3.8)
arel (6.0.3)
ast (2.2.0)
astrolabe (1.3.1)
parser (~> 2.2)
builder (3.2.2)
byebug (8.2.1)
codeclimate-test-reporter (0.4.8)
@ -156,9 +154,9 @@ GEM
octokit (~> 4.1.0)
rugged (~> 0.23.0)
thor (~> 0.19.0)
pronto-rubocop (0.5.0)
pronto-rubocop (0.5.2)
pronto (~> 0.5.0)
rubocop (~> 0.35.0)
rubocop (~> 0.36.0)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -223,13 +221,11 @@ GEM
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.35.1)
astrolabe (~> 1.3)
parser (>= 2.2.3.0, < 3.0)
rubocop (0.36.0)
parser (>= 2.3.0.0, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
tins (<= 1.6.0)
ruby-progressbar (1.7.5)
rugged (0.23.3)
safe_yaml (1.0.4)
@ -263,7 +259,6 @@ GEM
terminal-table (1.5.2)
thor (0.19.1)
thread_safe (0.3.5)
tins (1.6.0)
typhoeus (1.0.1)
ethon (>= 0.8.0)
tzinfo (1.2.2)
@ -293,13 +288,13 @@ DEPENDENCIES
logging-rails (= 0.5.0)
nyan-cat-formatter
pronto (= 0.5.3)
pronto-rubocop (= 0.5.0)
pronto-rubocop (= 0.5.2)
pry
pry-byebug
pry-debundle
rspec-collection_matchers (~> 1.1.2)
rspec-rails (~> 3.4.0)
rubocop (= 0.35.1)
rubocop (= 0.36.0)
simplecov (= 0.11.1)
simplecov-rcov (= 0.2.3)
spring

View file

@ -45,14 +45,14 @@ module DiasporaFederation
end
end
private
# creates the host-meta xml with the configured server_uri and caches it
# @return [String] XML string
def self.host_meta_xml
@host_meta_xml ||= Discovery::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s).to_xml
end
private
def find_person_webfinger(query)
DiasporaFederation.callbacks.trigger(:fetch_person_for_webfinger, query.strip.downcase.sub("acct:", ""))
end

View file

@ -121,7 +121,7 @@ module DiasporaFederation
photo_small: ".entity_photo_small .photo[src]",
key: ".key",
searchable: ".searchable"
}
}.freeze
# Create the HTML string from the current HCard instance
# @return [String] HTML string
@ -209,13 +209,13 @@ module DiasporaFederation
#
# @param container [Nokogiri::XML::Element] parent element for added property HTML
# @param name [Symbol] property name
# @param block [Proc] block returning an element
def add_property(container, name, &block)
# @yield [Nokogiri::HTML::Builder] html builder
def add_property(container, name)
Nokogiri::HTML::Builder.with(container) do |html|
html.dl(class: "entity_#{name}") {
html.dt(name.to_s.capitalize)
html.dd {
block.call(html)
yield html
}
}
end

View file

@ -26,7 +26,7 @@ module DiasporaFederation
end
# 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
# xml or by giving a base URL).

View file

@ -104,35 +104,35 @@ module DiasporaFederation
property :public_key
# +hcard_url+ link relation
REL_HCARD = "http://microformats.org/profile/hcard"
REL_HCARD = "http://microformats.org/profile/hcard".freeze
# +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+
# is inappropriate according to the specification (will affect older
# Diaspora* installations).
# +guid+ link relation
REL_GUID = "http://joindiaspora.com/guid"
REL_GUID = "http://joindiaspora.com/guid".freeze
# +profile_url+ link relation.
# @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
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
REL_SALMON = "salmon"
REL_SALMON = "salmon".freeze
# +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+
# is inappropriate according to the specification (will affect older
# Diaspora* installations).
# +pubkey+ link relation
REL_PUBKEY = "diaspora-public-key"
REL_PUBKEY = "diaspora-public-key".freeze
# Create the XML string from the current WebFinger instance
# @return [String] XML string

View file

@ -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
class XrdDocument
# 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_ATTRS = %i(rel type href template)
LINK_ATTRS = %i(rel type href template).freeze
# 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
# and after which the document has expired and SHOULD NOT be used.
@ -107,7 +107,7 @@ module DiasporaFederation
private
NS = {xrd: XMLNS}
NS = {xrd: XMLNS}.freeze
def add_aliases_to(xml)
@aliases.each do |a|

View file

@ -3,7 +3,7 @@ module DiasporaFederation
# {http://www.salmon-protocol.org/ Salmon Protocol}.
module Salmon
# XML namespace url
XMLNS = "https://joindiaspora.com/protocol"
XMLNS = "https://joindiaspora.com/protocol".freeze
end
end

View file

@ -3,7 +3,7 @@ module DiasporaFederation
# class for AES encryption and decryption
class AES
# OpenSSL aes cipher definition
CIPHER = "AES-256-CBC"
CIPHER = "AES-256-CBC".freeze
# generates a random AES key and initialization vector
# @return [Hash] { key: "...", iv: "..." }

View file

@ -25,19 +25,19 @@ module DiasporaFederation
attr_reader :payload
# encoding used for the payload data
ENCODING = "base64url"
ENCODING = "base64url".freeze
# algorithm used for signing the payload data
ALGORITHM = "RSA-SHA256"
ALGORITHM = "RSA-SHA256".freeze
# mime type describing the payload data
DATA_TYPE = "application/xml"
DATA_TYPE = "application/xml".freeze
# digest instance used for signing
DIGEST = OpenSSL::Digest::SHA256.new
# 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.
#
@ -128,10 +128,7 @@ module DiasporaFederation
#
# @return [String] the signature
def signature
subject = self.class.sig_subject([@payload,
DATA_TYPE,
ENCODING,
ALGORITHM])
subject = MagicEnvelope.send(:sig_subject, [@payload, DATA_TYPE, ENCODING, ALGORITHM])
@rsa_privkey.sign(DIGEST, subject)
end
@ -168,6 +165,7 @@ module DiasporaFederation
def self.sig_subject(data_arr)
data_arr.map {|i| Base64.urlsafe_encode64(i) }.join(".")
end
private_class_method :sig_subject
# @param [Nokogiri::XML::Element] magic_env magic envelope XML
# @return [Boolean]

View file

@ -34,7 +34,7 @@ module DiasporaFederation
attr_accessor :author_id
# 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
# this Slap.

View file

@ -54,8 +54,6 @@ module DiasporaFederation
populate_entity(klass, data)
end
private
# @param [Nokogiri::XML::Element] element
def self.wrap_valid?(element)
(element.name == "XML" && !element.at_xpath("post").nil? &&

View file

@ -43,14 +43,13 @@ module DiasporaFederation
validity
end
private
# @param [Hash] hash data to sign
# @return [String] signature data string
def self.signable_string(hash)
hash.map {|name, value|
value.to_s unless name.match(/signature/)
value.to_s unless name =~ /signature/
}.compact.join(";")
end
private_class_method :signable_string
end
end

View file

@ -132,7 +132,7 @@ module DiasporaFederation
created_at { Time.now.utc }
messages []
diaspora_id
participant_ids { 3.times.map { generate(:diaspora_id) }.join(";") }
participant_ids { Array.new(3) { generate(:diaspora_id) }.join(";") }
end
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
guid
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
factory :poll_participation_entity,

View file

@ -1,4 +1,4 @@
module DiasporaFederation
# the gem version
VERSION = "0.0.11"
VERSION = "0.0.11".freeze
end

View file

@ -25,9 +25,10 @@ module DiasporaFederation
end
it "calls the fetch_person_for_hcard callback" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_person_for_hcard, alice.guid)
.and_call_original
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_person_for_hcard, alice.guid
).and_call_original
get :hcard, "guid" => alice.guid
end
end

View file

@ -9,16 +9,14 @@ module DiasporaFederation
end
it "returns a 202 if queued correctly" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:queue_public_receive, "<diaspora/>")
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:queue_public_receive, "<diaspora/>")
post :public, xml: "<diaspora/>"
expect(response.code).to eq("202")
end
it "unescapes the xml before sending it to the callback" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:queue_public_receive, "<diaspora/>")
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:queue_public_receive, "<diaspora/>")
post :public, xml: CGI.escape("<diaspora/>")
end
@ -26,9 +24,9 @@ module DiasporaFederation
describe "POST #private" do
it "return a 404 if not queued successfully (unknown user guid)" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:queue_private_receive, "any-guid", "<diaspora/>")
.and_return(false)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:queue_private_receive, "any-guid", "<diaspora/>"
).and_return(false)
post :private, guid: "any-guid", xml: "<diaspora/>"
expect(response.code).to eq("404")
@ -40,18 +38,18 @@ module DiasporaFederation
end
it "returns a 202 if the callback returned true" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:queue_private_receive, "any-guid", "<diaspora/>")
.and_return(true)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:queue_private_receive, "any-guid", "<diaspora/>"
).and_return(true)
post :private, guid: "any-guid", xml: "<diaspora/>"
expect(response.code).to eq("202")
end
it "unescapes the xml before sending it to the callback" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:queue_private_receive, "any-guid", "<diaspora/>")
.and_return(true)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:queue_private_receive, "any-guid", "<diaspora/>"
).and_return(true)
post :private, guid: "any-guid", xml: CGI.escape("<diaspora/>")
end

View file

@ -59,9 +59,10 @@ module DiasporaFederation
end
it "calls the fetch_person_for_webfinger callback" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_person_for_webfinger, "alice@localhost:3000")
.and_call_original
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_person_for_webfinger, "alice@localhost:3000"
).and_call_original
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
end
end

View file

@ -23,16 +23,13 @@ XML
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }
it "updates author signature when it was nil and key was supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(
:fetch_entity_author_id_by_guid,
hash[:target_type],
hash[:target_guid]
)
.and_return(hash[:diaspora_id])
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_entity_author_id_by_guid, hash[:target_type], hash[:target_guid]
).and_return(hash[:diaspora_id])
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)
@ -43,16 +40,13 @@ XML
end
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)
.with(
:fetch_entity_author_id_by_guid,
hash[:target_type],
hash[:target_guid]
)
.and_return(FactoryGirl.generate(:diaspora_id))
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_entity_author_id_by_guid, hash[:target_type], hash[:target_guid]
).and_return(FactoryGirl.generate(:diaspora_id))
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)
@ -71,12 +65,13 @@ XML
end
it "doesn't change signatures if keys weren't supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_entity_author_id_by_guid, "Comment", hash[:target_guid])
.and_return(hash[:diaspora_id])
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
).and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_entity_author_id_by_guid, "Comment", hash[:target_guid]
).and_return(hash[:diaspora_id])
Entities::RelayableRetraction.update_signatures!(hash)
expect(hash[:target_author_signature]).to eq(nil)

View file

@ -19,25 +19,25 @@ module DiasporaFederation
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
hash[:parent_author_signature] = Signing.sign_with_key(hash, parent_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(
:fetch_author_public_key_by_entity_guid,
"Post",
hash[:parent_guid]
)
.and_return(parent_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
.and_return(false)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_author_public_key_by_entity_guid, "Post", hash[:parent_guid]
).and_return(parent_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:entity_author_is_local?, "Post", hash[:parent_guid]
).and_return(false)
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.not_to raise_error
end
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)
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, anything
).and_return(nil)
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
Entities::Relayable::SignatureVerificationFailed
@ -47,9 +47,10 @@ module DiasporaFederation
it "raises when bad author signature was passed" do
hash[:author_signature] = nil
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
).and_return(author_pkey.public_key)
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
Entities::Relayable::SignatureVerificationFailed
)
@ -58,19 +59,18 @@ module DiasporaFederation
it "raises when no public key for parent author was fetched" do
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(
:fetch_author_public_key_by_entity_guid,
"Post",
hash[:parent_guid]
)
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
.and_return(false)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_author_public_key_by_entity_guid, "Post", hash[:parent_guid]
).and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:entity_author_is_local?, "Post", hash[:parent_guid]
).and_return(false)
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
Entities::Relayable::SignatureVerificationFailed
)
@ -80,19 +80,18 @@ module DiasporaFederation
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
hash[:parent_author_signature] = nil
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(
:fetch_author_public_key_by_entity_guid,
"Post",
hash[:parent_guid]
)
.and_return(parent_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
.and_return(false)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_author_public_key_by_entity_guid, "Post", hash[:parent_guid]
).and_return(parent_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:entity_author_is_local?, "Post", hash[:parent_guid]
).and_return(false)
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.to raise_error(
Entities::Relayable::SignatureVerificationFailed
)
@ -102,28 +101,27 @@ module DiasporaFederation
hash[:author_signature] = Signing.sign_with_key(hash, author_pkey)
hash[:parent_author_signature] = nil
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:entity_author_is_local?, "Post", hash[:parent_guid])
.and_return(true)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, hash[:diaspora_id]
).and_return(author_pkey.public_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:entity_author_is_local?, "Post", hash[:parent_guid]
).and_return(true)
expect { Entities::Relayable.verify_signatures(hash, SomeRelayable) }.not_to raise_error
end
end
describe ".update_singatures!" do
it "updates signatures when they were nil and keys were supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
.and_return(author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(
:fetch_author_private_key_by_entity_guid,
"Post",
hash[:parent_guid]
)
.and_return(parent_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
).and_return(author_pkey)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_author_private_key_by_entity_guid, "Post", hash[:parent_guid]
).and_return(parent_pkey)
Entities::Relayable.update_signatures!(hash, SomeRelayable)
expect(Signing.verify_signature(hash, hash[:author_signature], author_pkey)).to be_truthy
@ -140,16 +138,13 @@ module DiasporaFederation
end
it "doesn't change signatures if keys weren't supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(
:fetch_author_private_key_by_entity_guid,
"Post",
hash[:parent_guid]
)
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
).and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_author_private_key_by_entity_guid, "Post", hash[:parent_guid]
).and_return(nil)
Entities::Relayable.update_signatures!(hash, SomeRelayable)
expect(hash[:author_signature]).to eq(nil)

View file

@ -22,9 +22,9 @@ XML
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }
it "updates author signature when it was nil and key was supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_private_key_by_diaspora_id, 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)
signable_hash = hash.select do |key, _|
%i(target_guid target_type).include?(key)
@ -44,9 +44,9 @@ XML
end
it "doesn't change signature if a key wasn't supplied" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_private_key_by_diaspora_id, hash[:diaspora_id])
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key_by_diaspora_id, hash[:diaspora_id]
).and_return(nil)
Entities::SignedRetraction.update_signatures!(hash)
expect(hash[:author_signature]).to eq(nil)

View file

@ -5,24 +5,23 @@ module DiasporaFederation
let(:recipient_key) { OpenSSL::PKey::RSA.generate(1024) }
let(:xml) {
DiasporaFederation::Salmon::EncryptedSlap.prepare(sender_id, sender_key, FactoryGirl.build(:request_entity))
.generate_xml(recipient_key)
.generate_xml(recipient_key)
}
it "calls save_entity_after_receive if everything is fine" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, sender_id)
.and_return(sender_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender_id
).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, recipient_key).receive!
end
it "raises when sender public key is not available" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, sender_id)
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender_id
).and_return(nil)
expect {
described_class.new(xml, recipient_key).receive!

View file

@ -11,19 +11,19 @@ module DiasporaFederation
}
it "calls save_entity_after_receive if everything is fine" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, sender_id)
.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(
:fetch_public_key_by_diaspora_id, sender_id
).and_return(sender_key)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(:save_entity_after_receive, kind_of(Entity))
described_class.new(xml).receive!
end
it "raises when sender public key is not available" do
expect(DiasporaFederation.callbacks).to receive(:trigger)
.with(:fetch_public_key_by_diaspora_id, sender_id)
.and_return(nil)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_public_key_by_diaspora_id, sender_id
).and_return(nil)
expect {
described_class.new(xml).receive!

View file

@ -16,9 +16,9 @@ module DiasporaFederation
describe "#insert_job" do
it "queues a request to hydra" do
expect(hydra).to receive(:queue).with(kind_of(Typhoeus::Request))
expect(Typhoeus::Request).to receive(:new)
.with(url, Federation::Sender::HydraWrapper.hydra_opts.merge(body: {xml: xml}))
.and_call_original
expect(Typhoeus::Request).to receive(:new).with(
url, Federation::Sender::HydraWrapper.hydra_opts.merge(body: {xml: xml})
).and_call_original
hydra_wrapper.insert_job(url, xml)
end

View file

@ -37,7 +37,7 @@ RSA
describe ".signable_string" 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

View file

@ -17,8 +17,8 @@ module DiasporaFederation
# must not contain more than 20 participant handles
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :participant_ids }
let(:wrong_values) { [21.times.map { FactoryGirl.generate(:diaspora_id) }.join(";")] }
let(:correct_values) { [20.times.map { FactoryGirl.generate(:diaspora_id) }.join(";")] }
let(:wrong_values) { [Array.new(21) { FactoryGirl.generate(:diaspora_id) }.join(";")] }
let(:correct_values) { [Array.new(20) { FactoryGirl.generate(:diaspora_id) }.join(";")] }
end
end
end

View file

@ -1,5 +1,5 @@
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
validator = Validation::Validator.new({})

View file

@ -2,7 +2,7 @@ def entity_stub(entity, data={})
OpenStruct.new(FactoryGirl.attributes_for(entity).merge(data))
end
ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"]
ALPHANUMERIC_RANGE = [*"0".."9", *"A".."Z", *"a".."z"].freeze
def alphanumeric_string(length)
Array.new(length) { ALPHANUMERIC_RANGE.sample }.join

View file

@ -1,12 +1,12 @@
require "diaspora_federation/discovery"
if File.file?("/etc/ssl/certs/ca-certificates.crt")
# For Debian, Ubuntu, Archlinux, Gentoo
ca_file = "/etc/ssl/certs/ca-certificates.crt"
else
# For CentOS, Fedora
ca_file = "/etc/pki/tls/certs/ca-bundle.crt"
end
ca_file = if File.file?("/etc/ssl/certs/ca-certificates.crt")
# For Debian, Ubuntu, Archlinux, Gentoo
"/etc/ssl/certs/ca-certificates.crt"
else
# For CentOS, Fedora
"/etc/pki/tls/certs/ca-bundle.crt"
end
# configure the federation engine
DiasporaFederation.configure do |config|