1
0

signature_parser_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe SignatureParser do
  4. describe '.parse' do
  5. subject { described_class.parse(header) }
  6. context 'with Signature headers conforming to draft-cavage-http-signatures-12' do
  7. let(:header) do
  8. # This example signature string deliberately mixes uneven spacing
  9. # and quoting styles to ensure everything is covered
  10. '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
  11. end
  12. it 'correctly parses the header' do
  13. expect(subject).to eq({
  14. 'keyId' => 'https://remote.domain/users/bob#main-key,',
  15. 'algorithm' => 'rsa-sha256',
  16. 'headers' => 'host date digest (request-target)',
  17. 'signature' => 'gmhMjgMROGElJU3fpehV2acD5kMHeELi8EFP2UPHOdQ54H0r55AxIpji+J3lPe+N2qSb/4H1KXIh6f0lRu8TGSsu12OQmg5hiO8VA9flcA/mh9Lpk+qwlQZIPRqKP9xUEfqD+Z7ti5wPzDKrWAUK/7FIqWgcT/mlqB1R1MGkpMFc/q4CIs2OSNiWgA4K+Kp21oQxzC2kUuYob04gAZ7cyE/FTia5t08uv6lVYFdRsn4XNPn1MsHgFBwBMRG79ng3SyhoG4PrqBEi5q2IdLq3zfre/M6He3wlCpyO2VJNdGVoTIzeZ0Zz8jUscPV3XtWUchpGclLGSaKaq/JyNZeiYQ==', # rubocop:disable Layout/LineLength
  18. })
  19. end
  20. end
  21. context 'with a malformed Signature header' do
  22. let(:header) { 'hello this is malformed!' }
  23. it 'raises an error' do
  24. expect { subject }.to raise_error(described_class::ParsingError)
  25. end
  26. end
  27. end
  28. end