|
29 | 29 | Rails.application.reload_routes!
|
30 | 30 | end
|
31 | 31 |
|
32 |
| - context 'when authenticated' do |
33 |
| - context 'with a valid audience' do |
34 |
| - it 'allows access' do |
35 |
| - expect(subject).to have_http_status(:ok) |
36 |
| - end |
37 |
| - end |
| 32 | + context 'when feature flag is enabled' do |
| 33 | + before { Flipper.enable(:accredited_representative_portal_pilot) } |
38 | 34 |
|
39 |
| - context 'with an invalid audience' do |
40 |
| - let(:access_token_cookie) { SignIn::AccessTokenJwtEncoder.new(access_token: invalid_access_token).perform } |
41 |
| - let(:expected_log_message) { '[SignIn][AudienceValidator] Invalid audience' } |
42 |
| - let(:expected_log_payload) do |
43 |
| - { invalid_audience: invalid_access_token.audience, valid_audience: valid_access_token.audience } |
44 |
| - end |
45 |
| - let(:expected_response_body) do |
46 |
| - { errors: 'Invalid audience' }.to_json |
| 35 | + context 'when authenticated' do |
| 36 | + context 'with a valid audience' do |
| 37 | + it 'allows access' do |
| 38 | + expect(subject).to have_http_status(:ok) |
| 39 | + end |
47 | 40 | end
|
48 | 41 |
|
49 |
| - before do |
50 |
| - allow(Rails.logger).to receive(:error) |
51 |
| - end |
| 42 | + context 'with an invalid audience' do |
| 43 | + let(:access_token_cookie) { SignIn::AccessTokenJwtEncoder.new(access_token: invalid_access_token).perform } |
| 44 | + let(:expected_log_message) { '[SignIn][AudienceValidator] Invalid audience' } |
| 45 | + let(:expected_log_payload) do |
| 46 | + { invalid_audience: invalid_access_token.audience, valid_audience: valid_access_token.audience } |
| 47 | + end |
| 48 | + let(:expected_response_body) do |
| 49 | + { errors: 'Invalid audience' }.to_json |
| 50 | + end |
| 51 | + |
| 52 | + before { allow(Rails.logger).to receive(:error) } |
52 | 53 |
|
53 |
| - it 'denies access' do |
54 |
| - expect(subject).to have_http_status(:unauthorized) |
55 |
| - expect(subject.body).to eq(expected_response_body) |
56 |
| - expect(Rails.logger).to have_received(:error).with(expected_log_message, expected_log_payload) |
| 54 | + it 'denies access' do |
| 55 | + expect(subject).to have_http_status(:unauthorized) |
| 56 | + expect(subject.body).to eq(expected_response_body) |
| 57 | + expect(Rails.logger).to have_received(:error).with(expected_log_message, expected_log_payload) |
| 58 | + end |
57 | 59 | end
|
58 | 60 | end
|
59 | 61 | end
|
| 62 | + |
| 63 | + context 'when feature flag is disabled' do |
| 64 | + before { Flipper.disable(:accredited_representative_portal_pilot) } |
| 65 | + |
| 66 | + it 'returns 403 Forbidden regardless of authentication' do |
| 67 | + expect(subject).to have_http_status(:forbidden) |
| 68 | + expect(subject.body).to match(/flag is disabled/) |
| 69 | + end |
| 70 | + end |
60 | 71 | end
|
61 | 72 | end
|
62 | 73 |
|
|
0 commit comments