2018-04-03 16:26:24 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SignatureService do
|
|
|
|
let(:service) { SignatureService }
|
|
|
|
let(:message) { { hello: 'World!' }.to_json }
|
2019-01-03 17:14:41 +01:00
|
|
|
let(:tampered_message) { { hello: 'Tampered' }.to_json }
|
2018-04-03 16:26:24 +02:00
|
|
|
|
2019-01-03 17:14:41 +01:00
|
|
|
it 'sign and verify' do
|
2018-04-03 16:26:24 +02:00
|
|
|
signature = service.sign(message)
|
|
|
|
expect(service.verify(signature, message)).to eq(true)
|
2019-01-03 17:14:41 +01:00
|
|
|
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)
|
2018-04-03 16:26:24 +02:00
|
|
|
end
|
|
|
|
end
|