Quick revision
The short answer
First we treat every committed credential as exposed and rotate it, because removing it from files and Git history does not undo existing clones. Then the values move out of the suite files: CI injects them as environment variables from its secret store or the tests fetch them from a secret manager at runtime, through a shared test configuration library that reads typed values and fails with clear errors. Secret scanning in CI prevents recurrence, and the 60 repositories are migrated with named owners, a tracker and a deadline.
What to remember
In this answer, we saw that credentials committed to Git must be treated as exposed, so rotation comes first and history cleanup after it. We moved values out of testng.xml into CI secret stores or a secret manager, gave 60 teams one shared library that reads typed values and fails with clear messages, added secret scanning and push protection to prevent recurrence, and ran the migration as a tracked programme with owners, a pilot and a revocation deadline.
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.
First we treat every committed credential as exposed and rotate it, because removing it from files and Git history does not undo existing clones. Then the values move out of the suite files: CI injects them as environment variables from its secret store or the tests fetch them from a secret manager at runtime, through a shared test configuration library that reads typed values and fails with clear errors. Secret scanning in CI prevents recurrence, and the 60 repositories are migrated with named owners, a tracker and a deadline.
Why this question is asked
Credentials in test configuration are one of the most common findings in a security review, because test environments feel harmless. They rarely are: a staging database often holds copies of production data, and a test API token may work against shared services or even production if someone reused it. Interviewers give this scenario to senior engineers because the technical fix is easy and the hard parts are elsewhere: ordering the steps so the exposure actually ends, building something 60 teams will adopt, and making sure it does not happen again. In this answer, we will understand why history matters, contain the exposure, change how values are supplied, build the shared library, add prevention, and plan the rollout.
1Why Deleting the Line Is Not Enough
A file committed to Git stays in the repository's history forever unless the history is rewritten. Anyone who cloned the repository, every CI cache, every fork and every backup has a copy. So when a password has been in testng.xml for two years, we must assume that it is known to people we cannot list. Removing the line in a new commit makes the current files clean but does not make the secret secret again.
That is why the order of steps matters. Rotation, issuing new credentials and revoking the old ones, is what actually ends the exposure. Cleaning history is still worth doing, so the old values do not keep appearing in searches and scans, but it comes after rotation, not instead of it.
2Inventory and Contain
We start by finding what is exposed. A secret scanner such as gitleaks, run over the full history of all 60 repositories, produces a list of credentials with the files and commits they appear in. We group the findings by system, such as the staging database, the payment sandbox or an internal API, because rotation happens per system, not per repository.
For each system, its owner issues new credentials, stores them in the secret store, and revokes the old ones on an agreed date. Systems that may hold real customer data, or tokens that might work beyond the test environment, go first, within days. Lower-risk sandbox credentials follow in the normal rollout.
- Scan all 60 repositories and their historygitleaks or similar
- Group findings by systemdatabase, sandbox, internal API
- Rotate and revoke, highest risk firstthe step that ends exposure
- Release the shared config librarytyped values, clear errors
- Migrate each repositoryowner, ticket, deadline
- Purge history and enable scanning in CIprevent recurrence
6 steps in order. Play them, or step through them one at a time.
3Supply Values at Runtime
The new rule is simple: suite files contain structure only, never credentials and preferably no environment URLs either. Values reach the tests at runtime in one of two ways. The CI system injects them as environment variables from its own secret store, which is the simplest and works on every CI product. Or the tests fetch them from a secret manager, such as HashiCorp Vault or a cloud provider's secret service, using the CI job's own identity, which avoids long-lived secrets in CI configuration but needs more setup.
For local runs, developers point the same variables at a local environment, often containers with throwaway passwords, or fetch short-lived credentials with their own identity. No developer should need the shared staging password on their laptop.
4A Shared Test Configuration Library
Sixty teams will each invent a slightly different way to read variables unless we give them one. A small library, published to the internal repository, reads typed values, applies the precedence rules and fails with a message that tells the reader exactly what to do.
Notice that the error message names the variable and where it should come from, but never the value. The library is also the natural place to mask values in logs and reports and to support a secret manager later without changing the tests.
5Prevent Recurrence
Without prevention, the same finding returns within months, because copying a working testng.xml with a password in it is still the fastest way to make a test pass. So we add secret scanning to every pipeline, failing the build when a new commit contains something that looks like a credential, and enable push protection in the Git hosting service where it is available, so the commit is rejected before it even reaches the server. A small rule in the shared test library can also fail the run if any testng.xml <parameter> has a name like password, token or secret.
Once rotation is done and the repositories are migrated, we rewrite history with a tool such as git filter-repo to remove the old values, coordinating with each team, since rewritten history requires everyone to re-clone.
6Roll Out Across 60 Repositories
The rollout is a small programme. Each repository gets a named owner and a ticket that lists exactly which secrets it contains, which systems they belong to, and the target variable names. We migrate two or three repositories first with the platform team's help, to test the library and the instructions, then publish a deadline, for example six weeks, for the rest. A tracker visible to security and engineering leadership shows status per repository. On the deadline, the old credentials are revoked, so any repository not migrated fails visibly rather than staying exposed quietly.
| Repository | Secrets found | Owner | Status |
|---|---|---|---|
| orders-service | 2 (DB, payment sandbox) | Orders team | Migrated, history purged |
| checkout-ui-tests | 1 (test user password) | Web team | Migrated |
| billing-service | 3 (DB, API token, SFTP) | Billing team | In progress |
| legacy-reports | 1 (DB) | Unassigned | Escalated |
7Follow-up questions
Is purging Git history really necessary if we rotate everything?
It is not what makes us safe, rotation is, but it is still worth doing. Old values in history keep triggering scanners, confuse audits, and can still matter if a rotation was incomplete. We purge after rotation, once per repository, with the team's agreement, because everyone must re-clone afterwards.
How do you handle teams that miss the deadline?
The revocation date is the deadline, so their tests start failing with the library's clear error rather than continuing with leaked credentials. Before that we escalate through the tracker, and the platform team offers pairing sessions. A firm date with visible status works better than repeated reminders.
Should environment URLs also leave testng.xml?
They are not secrets, but they are environment values, and keeping them in suite files is what led to copied files in the first place. Moving them into the same configuration library, with defaults for local runs, keeps the suite files purely structural and makes the next audit simpler.
8Conclusion
In this answer, we saw that credentials committed to Git must be treated as exposed, so rotation comes first and history cleanup after it. We moved values out of testng.xml into CI secret stores or a secret manager, gave 60 teams one shared library that reads typed values and fails with clear messages, added secret scanning and push protection to prevent recurrence, and ran the migration as a tracked programme with owners, a pilot and a revocation deadline.
Open with
I would start from the assumption that every credential in those files is already exposed, because Git history, clones, forks and CI caches all have copies. So step one is an inventory: scan all 60 repositories including history with something like gitleaks, and group the findings by system, the staging database, the payment sandbox and so on.
Then, if they want more
Then each system owner rotates and revokes, highest risk first, for example anything that touches copies of real data. That rotation is what actually ends the exposure; cleaning history comes later.
Step two is changing how values reach tests: suite files keep only structure, and secrets arrive at runtime as environment variables injected by CI from its secret store, or fetched from a secret manager with the job's identity.
Step three is a small shared library, so 60 teams do not each invent their own: it reads typed values, fails with a message that names the variable and where it should come from, and never prints the value.
Step four is prevention: secret scanning in every pipeline, push protection in the Git host, and a check that fails a run if a suite parameter looks like a password.
Finally the rollout: a pilot with two or three repositories, then a ticket and an owner for each repository, a tracker visible to security and leadership, and the revocation date as the hard deadline. After migration, we purge history with git filter-repo.
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
- JUnit user guide, Mockito documentation
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 "TestNG suites at your company read environment URLs and credentials from testng.xml...": https://scrivio-interview-library.netlify.app/java/testng/c0b4627df7/