diaspora_federation/spec/support/helper_methods.rb
2017-04-05 00:36:52 +02:00

28 lines
848 B
Ruby

# 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