|
22 | 22 | end
|
23 | 23 | end
|
24 | 24 |
|
25 |
| - after do |
26 |
| - # We could have set up our test such that we can unset |
27 |
| - # `ArbitraryController` as a const during cleanup. But we'll just leave it |
28 |
| - # around and avoid the extra metaprogramming. |
29 |
| - Rails.application.reload_routes! |
30 |
| - end |
| 25 | + after { Rails.application.reload_routes! } |
31 | 26 |
|
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 |
| 27 | + context 'when feature flag is enabled' do |
| 28 | + before { Flipper.enable(:accredited_representative_portal_pilot) } |
38 | 29 |
|
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 |
| 30 | + context 'when authenticated' do |
| 31 | + context 'with a valid audience' do |
| 32 | + it 'allows access' do |
| 33 | + expect(subject).to have_http_status(:ok) |
| 34 | + end |
47 | 35 | end
|
48 | 36 |
|
49 |
| - before do |
50 |
| - allow(Rails.logger).to receive(:error) |
51 |
| - end |
| 37 | + context 'with an invalid audience' do |
| 38 | + let(:access_token_cookie) { SignIn::AccessTokenJwtEncoder.new(access_token: invalid_access_token).perform } |
| 39 | + let(:expected_log_message) { '[SignIn][AudienceValidator] Invalid audience' } |
| 40 | + let(:expected_log_payload) do |
| 41 | + { invalid_audience: invalid_access_token.audience, valid_audience: valid_access_token.audience } |
| 42 | + end |
| 43 | + let(:expected_response_body) do |
| 44 | + { errors: 'Invalid audience' }.to_json |
| 45 | + end |
52 | 46 |
|
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) |
| 47 | + before { allow(Rails.logger).to receive(:error) } |
| 48 | + |
| 49 | + it 'denies access' do |
| 50 | + expect(subject).to have_http_status(:unauthorized) |
| 51 | + expect(subject.body).to eq(expected_response_body) |
| 52 | + expect(Rails.logger).to have_received(:error).with(expected_log_message, expected_log_payload) |
| 53 | + end |
57 | 54 | end
|
58 | 55 | end
|
59 | 56 | end
|
| 57 | + |
| 58 | + context 'when feature flag is disabled' do |
| 59 | + before { Flipper.disable(:accredited_representative_portal_pilot) } |
| 60 | + |
| 61 | + it 'returns 403 Forbidden regardless of authentication' do |
| 62 | + expect(subject).to have_http_status(:forbidden) |
| 63 | + end |
| 64 | + end |
60 | 65 | end
|
61 | 66 | end
|
62 | 67 |
|
|
0 commit comments