2024-02-07 13:35:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe SignatureParser do
|
|
|
|
describe '.parse' do
|
|
|
|
subject { described_class.parse(header) }
|
|
|
|
|
|
|
|
context 'with Signature headers conforming to draft-cavage-http-signatures-12' do
|
|
|
|
let(:header) do
|
|
|
|
# This example signature string deliberately mixes uneven spacing
|
|
|
|
# and quoting styles to ensure everything is covered
|
2024-02-07 17:24:42 +00:00
|
|
|
'keyId = "https://remote.domain/users/bob#main-key,",algorithm= rsa-sha256 , headers="host date digest (request-target)",signature="gmhMjgMROGElJU3fpehV2acD5kMHeELi8EFP2UPHOdQ54H0r55AxIpji+J3lPe+N2qSb/4H1KXIh6f0lRu8TGSsu12OQmg5hiO8VA9flcA/mh9Lpk+qwlQZIPRqKP9xUEfqD+Z7ti5wPzDKrWAUK/7FIqWgcT/mlqB1R1MGkpMFc/q4CIs2OSNiWgA4K+Kp21oQxzC2kUuYob04gAZ7cyE/FTia5t08uv6lVYFdRsn4XNPn1MsHgFBwBMRG79ng3SyhoG4PrqBEi5q2IdLq3zfre/M6He3wlCpyO2VJNdGVoTIzeZ0Zz8jUscPV3XtWUchpGclLGSaKaq/JyNZeiYQ=="' # rubocop:disable Layout/LineLength
|
2024-02-07 13:35:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly parses the header' do
|
|
|
|
expect(subject).to eq({
|
2024-02-07 17:24:42 +00:00
|
|
|
'keyId' => 'https://remote.domain/users/bob#main-key,',
|
2024-02-07 13:35:37 +00:00
|
|
|
'algorithm' => 'rsa-sha256',
|
|
|
|
'headers' => 'host date digest (request-target)',
|
|
|
|
'signature' => 'gmhMjgMROGElJU3fpehV2acD5kMHeELi8EFP2UPHOdQ54H0r55AxIpji+J3lPe+N2qSb/4H1KXIh6f0lRu8TGSsu12OQmg5hiO8VA9flcA/mh9Lpk+qwlQZIPRqKP9xUEfqD+Z7ti5wPzDKrWAUK/7FIqWgcT/mlqB1R1MGkpMFc/q4CIs2OSNiWgA4K+Kp21oQxzC2kUuYob04gAZ7cyE/FTia5t08uv6lVYFdRsn4XNPn1MsHgFBwBMRG79ng3SyhoG4PrqBEi5q2IdLq3zfre/M6He3wlCpyO2VJNdGVoTIzeZ0Zz8jUscPV3XtWUchpGclLGSaKaq/JyNZeiYQ==', # rubocop:disable Layout/LineLength
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a malformed Signature header' do
|
|
|
|
let(:header) { 'hello this is malformed!' }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2024-03-13 15:42:39 +00:00
|
|
|
expect { subject }.to raise_error(described_class::ParsingError)
|
2024-02-07 13:35:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|