Extract helper methods
This commit is contained in:
parent
f860a62382
commit
ccd4b7eceb
2 changed files with 28 additions and 28 deletions
|
|
@ -25,34 +25,6 @@ require "factories"
|
||||||
# load test entities
|
# load test entities
|
||||||
require "entities"
|
require "entities"
|
||||||
|
|
||||||
# some helper methods
|
|
||||||
|
|
||||||
def alice
|
|
||||||
@alice ||= Fabricate(:user, diaspora_id: "alice@localhost:3000")
|
|
||||||
end
|
|
||||||
|
|
||||||
def bob
|
|
||||||
@bob ||= Fabricate(:user, diaspora_id: "bob@localhost:3000")
|
|
||||||
end
|
|
||||||
|
|
||||||
def expect_callback(*opts)
|
|
||||||
expect(DiasporaFederation.callbacks).to receive(:trigger).with(*opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_signatures(hash, klass=described_class)
|
|
||||||
properties = klass.new(hash).send(:enriched_properties)
|
|
||||||
hash[:author_signature] = properties[:author_signature]
|
|
||||||
hash[:parent_author_signature] = properties[:parent_author_signature]
|
|
||||||
end
|
|
||||||
|
|
||||||
def sign_with_key(privkey, signature_data)
|
|
||||||
Base64.strict_encode64(privkey.sign(OpenSSL::Digest::SHA256.new, signature_data))
|
|
||||||
end
|
|
||||||
|
|
||||||
def verify_signature(pubkey, signature, signed_string)
|
|
||||||
pubkey.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signed_string)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Requires supporting files with custom matchers and macros, etc,
|
# Requires supporting files with custom matchers and macros, etc,
|
||||||
# in ./support/ and its subdirectories.
|
# in ./support/ and its subdirectories.
|
||||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
|
||||||
|
|
|
||||||
28
spec/support/helper_methods.rb
Normal file
28
spec/support/helper_methods.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# default users
|
||||||
|
def alice
|
||||||
|
@alice ||= Fabricate(:user, diaspora_id: "alice@localhost:3000")
|
||||||
|
end
|
||||||
|
|
||||||
|
def bob
|
||||||
|
@bob ||= Fabricate(:user, diaspora_id: "bob@localhost:3000")
|
||||||
|
end
|
||||||
|
|
||||||
|
# callback expectation helper
|
||||||
|
def expect_callback(*opts)
|
||||||
|
expect(DiasporaFederation.callbacks).to receive(:trigger).with(*opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
# signature methods
|
||||||
|
def add_signatures(hash, klass=described_class)
|
||||||
|
properties = klass.new(hash).send(:enriched_properties)
|
||||||
|
hash[:author_signature] = properties[:author_signature]
|
||||||
|
hash[:parent_author_signature] = properties[:parent_author_signature]
|
||||||
|
end
|
||||||
|
|
||||||
|
def sign_with_key(privkey, signature_data)
|
||||||
|
Base64.strict_encode64(privkey.sign(OpenSSL::Digest::SHA256.new, signature_data))
|
||||||
|
end
|
||||||
|
|
||||||
|
def verify_signature(pubkey, signature, signed_string)
|
||||||
|
pubkey.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signed_string)
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue