From ccd4b7eceb47c81f60419308169e4cb8bced3191 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Tue, 4 Apr 2017 22:06:55 +0200 Subject: [PATCH] Extract helper methods --- spec/spec_helper.rb | 28 ---------------------------- spec/support/helper_methods.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 spec/support/helper_methods.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 67f9916..b7578b7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,34 +25,6 @@ require "factories" # load test 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, # in ./support/ and its subdirectories. Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f } diff --git a/spec/support/helper_methods.rb b/spec/support/helper_methods.rb new file mode 100644 index 0000000..e4ff32c --- /dev/null +++ b/spec/support/helper_methods.rb @@ -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