Quick revision
The short answer
I would turn the audit into a precise, written requirement: every endpoint and sensitive method in a customer-facing service has positive and negative authorization tests, including cross-tenant attempts. Then I would make it cheap with shared test utilities, make the evidence a by-product of every build through a generated map of endpoints to rules to tests, block releases with missing coverage after a transition period, and give each service team ownership with a regular review together with security and compliance.
What to remember
In this answer, we saw how to turn an audit requirement into a lasting engineering standard. We defined precisely which positive, negative and cross-tenant tests every endpoint and sensitive method needs, made them cheap with shared utilities, generated the evidence from every build as a map of endpoints to rules to tests, made missing coverage block release after a transition, and gave ownership to service teams with a regular review alongside security and compliance.
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 turn the audit into a precise, written requirement: every endpoint and sensitive method in a customer-facing service has positive and negative authorization tests, including cross-tenant attempts. Then I would make it cheap with shared test utilities, make the evidence a by-product of every build through a generated map of endpoints to rules to tests, block releases with missing coverage after a transition period, and give each service team ownership with a regular review together with security and compliance.
Why this question is asked
An audit finding can be answered in two ways. A team can spend a month writing tests, produce a spreadsheet and move on, and a year later the spreadsheet is wrong and the next audit starts from zero. Or the organisation can change how it builds software so the evidence exists all the time. Interviewers ask this at the senior level to see whether we know the difference and can lead the second path across many teams. In this answer, we will define the requirement precisely, make compliance cheap, automate the evidence, add a release gate, and set up ownership and review so the standard lasts.
1Why One-Off Compliance Fails
A one-off exercise produces evidence about the code as it was on one day. Services change every week, new endpoints appear, and rules get refactored. The moment the exercise ends, the evidence starts to decay, and nothing tells anyone that it has. The regulator does not really want a spreadsheet; they want confidence that the company controls who can access customer data, and that confidence comes from a process that keeps working without heroics.
So the plan has three properties. The requirement is precise enough that a machine can check it. The work is cheap enough that teams do it as part of normal development. And the evidence is generated, not written by hand, so it is always current.
2Define the Requirement Precisely
A vague rule such as authorization must be tested cannot be checked. I would write it like this: in every customer-facing service, every HTTP endpoint and every method marked as sensitive has at least one test showing an allowed caller succeeds, at least one test showing a caller without the needed permission is refused, and, for any data owned by a tenant or a customer, a test showing a caller from another tenant cannot read or change it.
The cross-tenant case deserves special attention. Most serious access incidents are not a missing role check but a correct role used against someone else's record: a support agent of company A reading company B's orders by changing an ID in the URL. A test that only checks roles will never find that. Writing this case into the requirement makes every team think about it.
| Case | Example caller | Expected |
|---|---|---|
| Allowed | orders.write, tenant acme, own order | 200 |
| Wrong permission | orders.read only | 403 |
| Not authenticated | no token | 401 |
| Cross-tenant | orders.write, tenant globex, acme's order | 403 or 404 |
| Sensitive method | service call without role | AccessDeniedException |
3Make the Tests Cheap to Write
If each test needs twenty lines of token setup, teams will write the minimum. So the platform starter, the shared library every service already uses, gets a security test module: mock JWT builders for named personas, annotations built on Spring Security's @WithSecurityContext for method tests, @WithMockUser patterns documented with examples, and tenant fixtures that create two tenants with their own data so a cross-tenant test is one line.
I would fund a small platform group to build this first, together with two pilot teams, because tools designed without real users rarely fit. The pilot also gives us an honest estimate of how long the backfill takes per endpoint, which we need for planning the transition.
4Automate the Evidence
The core of a lasting standard is that the build produces the evidence. A test in each service starts the application context, reads every endpoint and its security configuration, finds the methods annotated as sensitive, and records which tests exercised each one and with which outcome. The build writes this as a report: endpoint, rule, tests covering it, cases present and cases missing. It is stored with the build artefact, so for any release we can show exactly what was tested.
Notice what this changes for an audit. Instead of asking teams to assemble evidence, we export the reports for the releases in the audit period. The evidence is current because it was produced by the same build that shipped the code.
- Build and run testssecurity tests record caller, endpoint and outcome
- Read endpoints and rules from the contextplus methods marked sensitive
- Join endpoints, rules and testsfind missing allowed, refused or cross-tenant cases
- Coverage complete?YesPublish the report with the releaseNoReport gaps; block release after transition
- Store report with the artefactexported for auditors on request
5 steps in order. Play them, or step through them one at a time.
The evidence is a by-product of the build, so it never goes stale.
5Block Releases, After a Transition
A report nobody acts on decays too. So after a transition period, for example one quarter for new and changed endpoints and two quarters for the full backfill, missing coverage in a customer-facing service blocks release. Before that date, the gaps appear as warnings with a count per service, so teams can plan.
I would also define an exception path: a team can ship with a documented gap if security approves it and a date is set to close it. That keeps the gate from becoming a reason to bypass the process during an incident, while still leaving a trace that the auditors can see.
6Ownership and Regular Review
Each service team owns its coverage and its gaps; the platform group owns the tools and the report format; security owns the policy of what must be protected. Every month or quarter, the three sit together and look at the numbers: coverage per service, open exceptions, escaped authorization bugs, and findings from penetration tests. Each escaped bug leads to a question about which required case was missing or which case the requirement should add.
Over time, this review is what keeps the standard alive. The rule improves with what we learn, and the regulator sees not just tests but a control that is measured and maintained.
7Follow-up questions
How do you handle legacy services that would take months to backfill?
I would rank them by exposure: services that hold customer data and are reachable from outside go first. For the rest, the gate starts with new and changed endpoints only, so the gap stops growing, and each team commits to a backfill plan with dates that appears in the review. Security can accept a temporary exception for a low-risk service with a clear end date.
What do you show the regulator?
A short description of the control (the requirement, the tools and the release gate), the generated reports for the releases in the audit period, the list of exceptions with their approvals, and the minutes of the regular reviews. That shows not only that tests exist, but that the company notices and fixes gaps.
How do you stop teams from writing tests that tick the box but assert nothing?
The shared helpers assert the status code for every case, so a test written with them always checks the outcome. Reviews spot-check a sample of tests each quarter, and penetration test findings tell us where the tests were weak. Mutation-style checks, where we remove a rule in a test build and expect tests to fail, are a strong extra signal for the most sensitive services.
8Conclusion
In this answer, we saw how to turn an audit requirement into a lasting engineering standard. We defined precisely which positive, negative and cross-tenant tests every endpoint and sensitive method needs, made them cheap with shared utilities, generated the evidence from every build as a map of endpoints to rules to tests, made missing coverage block release after a transition, and gave ownership to service teams with a regular review alongside security and compliance.
Open with
I would avoid a one-off exercise, because evidence written by hand is out of date the week after the audit. I would start by defining the requirement precisely: every endpoint and every sensitive method in a customer-facing service has a test that an allowed caller succeeds, a test that a caller without permission is refused, and for tenant data a test that a caller from another tenant is refused.
Then, if they want more
Then I would make that cheap. Our platform starter gets a security test module with mock JWT personas, WithSecurityContext annotations and tenant fixtures, built with two pilot teams so it fits real code. Next, the evidence has to be automatic.
Each build reads the endpoints and their rules from the application context, joins them with the tests that hit them, and produces a report stored with the release. For an audit we export those reports instead of asking teams to assemble anything.
After a transition period, about a quarter for new code, missing coverage blocks release for customer-facing services, with a documented exception path approved by security. Finally, service teams own their coverage, the platform team owns the tools, security owns the policy, and we review the numbers and escaped bugs together every quarter so the standard keeps improving.
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 "After a regulator's audit, your company must show evidence that authorization rules in...": https://scrivio-interview-library.netlify.app/spring-boot/spring-boot-test/89dba83a41/