summaryrefslogtreecommitdiff
path: root/spec/lib/error_tracking/collector/sentry_auth_parser_spec.rb
blob: 0e4bba04baa862b82d8b9aad710acfdfac010fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ErrorTracking::Collector::SentryAuthParser do
  describe '.parse' do
    let(:headers) { { 'X-Sentry-Auth' => "Sentry sentry_key=glet_1fedb514e17f4b958435093deb02048c" } }
    let(:request) { instance_double('ActionDispatch::Request', headers: headers) }

    subject { described_class.parse(request) }

    context 'with empty headers' do
      let(:headers) { {} }

      it 'fails with exception' do
        expect { subject }.to raise_error(StandardError)
      end
    end

    context 'with missing sentry_key' do
      let(:headers) { { 'X-Sentry-Auth' => "Sentry foo=bar" } }

      it 'returns empty value for public_key' do
        expect(subject[:public_key]).to be_nil
      end
    end

    it 'returns correct value for public_key' do
      expect(subject[:public_key]).to eq('glet_1fedb514e17f4b958435093deb02048c')
    end
  end
end