Skip to content

Commit 0b2a207

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 84264e4 commit 0b2a207

File tree

1 file changed

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

1 file changed

+32
-27
lines changed

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,46 @@
2222
end
2323
end
2424

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! }
3126

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

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
4735
end
4836

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
5246

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
5754
end
5855
end
5956
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
6065
end
6166
end
6267

0 commit comments

Comments
 (0)