demarches-normaliennes/spec/services/signature_service_spec.rb
2019-01-03 17:48:53 +01:00

24 lines
791 B
Ruby

require 'spec_helper'
describe SignatureService do
let(:service) { SignatureService }
let(:message) { { hello: 'World!' }.to_json }
let(:tampered_message) { { hello: 'Tampered' }.to_json }
it 'sign and verify' do
signature = service.sign(message)
expect(service.verify(signature, message)).to eq(true)
end
it 'fails the verification if the message changed' do
signature = service.sign(message)
expect(service.verify(signature, tampered_message)).to eq(false)
end
it 'fails the verification if the signature changed' do
other_signature = service.sign(tampered_message)
expect(service.verify(nil, message)).to eq(false)
expect(service.verify('', message)).to eq(false)
expect(service.verify(other_signature, message)).to eq(false)
end
end