Skip to content

Commit 77cd030

Browse files
committed
feat: enforce Flipper feature flag in ApplicationController
•Added Flipper validation to ApplicationController spec to ensure API access is blocked when :accredited_representative_portal_pilot is disabled. •Modified tests to check that the feature flag takes priority over authentication. •Ensured existing authentication tests remain intact, validating correct behavior when the flag is enabled. •If Flipper is disabled, requests now return 403 Forbidden before checking tokens or audience validation.
1 parent 357e539 commit 77cd030

File tree

1 file changed

+32
-21
lines changed
  • modules/accredited_representative_portal/spec/requests/accredited_representative_portal

1 file changed

+32
-21
lines changed

modules/accredited_representative_portal/spec/requests/accredited_representative_portal/application_spec.rb

+32-21
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,45 @@
2929
Rails.application.reload_routes!
3030
end
3131

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) }
3834

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
4740
end
4841

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) }
5253

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
5759
end
5860
end
5961
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
6071
end
6172
end
6273

0 commit comments

Comments
 (0)