Quick revision
The short answer
I would make access rules a tested part of every endpoint, with negative cases required, and make that cheap by shipping shared token and role test utilities in the platform starter. Then I would stop relying on people remembering: the build generates a report of every endpoint and its rule, CI compares it to a written policy and fails on gaps, periodic penetration tests check what automation misses, and every regression is tracked and discussed openly until the numbers fall.
What to remember
In this answer, we saw why authorization regressions slip past tests that only check the happy path, and how to raise the standard across teams. We set a clear requirement of tests for every access rule with negative cases, made it cheap with shared token and persona utilities in the platform starter, generated an endpoint report from each application and compared it with a policy in CI, kept periodic penetration tests for logic flaws, and made regressions visible so the trend can be followed.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would make access rules a tested part of every endpoint, with negative cases required, and make that cheap by shipping shared token and role test utilities in the platform starter. Then I would stop relying on people remembering: the build generates a report of every endpoint and its rule, CI compares it to a written policy and fails on gaps, periodic penetration tests check what automation misses, and every regression is tracked and discussed openly until the numbers fall.
Why this question is asked
Authorization regressions are among the most expensive bugs we can ship, because the code works perfectly for the people who should use it, so nobody notices until the wrong person reads the data. When a security review finds several of them across services, the real finding is not a few bugs but a gap in how teams test. Interviewers ask this to see whether we can change a habit across many teams rather than fix one service. In this answer, we will look at why these regressions slip through, set a clear testing requirement, make it cheap with shared tools, add automated checks against a policy, and keep the results visible.
1Why Authorization Regressions Escape Tests
Most teams test the happy path: a user with the right role calls the endpoint and gets 200. That test still passes if someone deletes the rule entirely, because an endpoint open to everyone also lets the right user in. So a whole category of bugs, a rule removed during a refactor, a new endpoint added without a rule, a path pattern that no longer matches after a URL change, is invisible to the tests teams already have.
The second reason is cost. Writing a security test means building a token, choosing roles and setting up a tenant, and if every team does that from scratch, it feels like a chore and gets skipped under deadline. So the plan has to address both: what must be tested, and how cheap it is to test it.
2Set a Clear Requirement
I would write one short standard: every endpoint has a test for each of its access rules, and every rule has at least one negative test. For an endpoint that requires orders.write, that means a caller with orders.write gets through, a caller with only orders.read gets 403, an anonymous caller gets 401, and, where the service is multi-tenant, a caller from another tenant is refused. The negative tests are the ones that catch removed or loosened rules, so they are not optional.
I would agree this with the team leads and the security group rather than announce it, and I would apply it to new and changed endpoints first, so teams are not asked to backfill everything in one sprint. Backfilling then happens service by service, starting with the endpoints that expose the most sensitive data.
3Make the Tests Cheap With Shared Utilities
The platform starter, the shared library every service already depends on, gets a test module with the pieces every team was writing by hand: helpers that build mock JWTs for named personas, annotations such as @AsCustomer(tenant = "acme") or @AsSupportAgent built on Spring Security's @WithSecurityContext, and a small table-driven helper that runs one endpoint against a list of callers and expected statuses.
Notice how the negative cases are now one line each. When the right thing costs one line, people do it. The helpers also make tests consistent across teams, which matters later when we read reports from fifty services.
4Compare What the Application Exposes With a Policy
Tests only cover the endpoints someone remembered to test. To find the rest, we generate a report from the application itself. In a test that starts the context, we read every mapping from the RequestMappingHandlerMapping, along with the security rule that applies to it, and write a small file: method, path, required authority, and the tests that call it. Each service also has a policy file, written with the security team, that says what each endpoint should require.
CI compares the two and fails the build when an endpoint has no rule, when a rule differs from the policy, or when an endpoint has no negative test. The reason this works is that it does not depend on anyone remembering: a new endpoint appears in the report automatically, and the build tells the author what is missing.
- Start the application context in a testlist every endpoint and its security rule
- Collect which tests hit each endpointpositive and negative cases
- Matches the policy file?YesContinueNoFail the build with the difference
- At least one negative test?YesPassNoFail the build and name the endpoint
4 steps in order. Play them, or step through them one at a time.
A new endpoint shows up in the report automatically, so it cannot be forgotten.
5Penetration Tests for What Automation Misses
Automated checks find missing and changed rules. They do not find logic flaws, such as an order ID that can be guessed, an export that leaks other tenants' rows, or a rule that is correct in the policy but wrong for the business. So I would keep periodic penetration tests, for example twice a year for the most exposed services, and turn every finding into a new automated test and, where it applies, a new rule in the shared policy checks, so the same kind of bug cannot come back.
6Make Regressions Visible
Finally, the numbers have to be seen. I would track authorization regressions as their own category in the incident and bug tracker, publish per team how many endpoints meet the standard and how many regressions were found by tests, by review or by someone outside, and add a short checklist item to code review for any change that touches a controller or a security configuration. When a regression escapes, the review asks which test should have caught it and adds that test to the shared helpers if it is general.
The goal is a clear trend: within two or three quarters, almost every endpoint covered, regressions caught in CI rather than in reviews or production, and penetration test findings shifting from missing checks to subtle logic issues.
7Follow-up questions
How do you get teams to adopt this without slowing delivery?
By making the default path the easy one. The shared helpers and the generated report do most of the work, the requirement starts with new and changed endpoints, and the CI check begins as a warning for a few weeks before it blocks. Teams see that a security test now takes minutes rather than an afternoon, and that the warning list is something they can shrink.
What if the security rules live in a gateway rather than in the service?
Then the gateway configuration is part of the policy and needs the same treatment: a test suite that sends requests through the gateway with different tokens. I would still keep rules in the service for anything tenant- or data-specific, because a gateway usually sees only paths and scopes, not which tenant owns a record.
Is code coverage a useful measure here?
Not on its own. Line coverage says a controller method ran, not that its rule was tested with a caller who should be refused. The endpoint-to-rule-to-test report is a better measure because it counts negative tests per rule, which is what actually catches these regressions.
8Conclusion
In this answer, we saw why authorization regressions slip past tests that only check the happy path, and how to raise the standard across teams. We set a clear requirement of tests for every access rule with negative cases, made it cheap with shared token and persona utilities in the platform starter, generated an endpoint report from each application and compared it with a policy in CI, kept periodic penetration tests for logic flaws, and made regressions visible so the trend can be followed.
Open with
First I would look at why the regressions escaped. Usually the tests only check that the right user gets in, and that still passes if the rule is removed.
Then, if they want more
So the standard I would set is simple: every endpoint has a test for each access rule, and every rule has negative cases, wrong scope gives 403, no token gives 401, another tenant is refused.
To make that cheap, I would add a test module to our platform starter with persona helpers for JWTs and roles, annotations built on WithSecurityContext, and a table-driven helper so each negative case is one line. Then I would stop relying on memory.
A test in each service lists every endpoint and its security rule from the running context, and CI compares that report with a policy file agreed with the security team, failing on endpoints with no rule, a rule that differs, or no negative test. I would roll that out as a warning first and then make it blocking.
Penetration tests stay, maybe twice a year for exposed services, and each finding becomes an automated test. Finally, I would track authorization regressions as their own category, report coverage per team, and review every escaped regression to see which test should have caught it.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference, Testing
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A security review found that several services had authorization regressions that tests...": https://scrivio-interview-library.netlify.app/spring-boot/spring-boot-test/8f8430643e/