test(basic-auth): store the vault secret before the consumer references it - #13853
Merged
nic-6443 merged 1 commit intoAug 20, 2026
Merged
Conversation
…es it Four test files write the same Vault path kv/apisix/foo with different fields, and `vault kv put` replaces the whole secret rather than merging it. Two of them sort before basic-auth.t in the t/plugin/[a-k]*.t job, so by the time it runs the path holds a client_secret and no passwd. TEST 22 then configures a consumer whose password is $secret://vault/test1/foo/passwd, and the admin write resolves it right there -- admin/consumers.lua check_duplicate_key() -> find_consumer() -> create_consume_cache() -> fetch_secrets() -- so the reference is looked up while the field is still missing. It is logged at error level and the default no_error_log: [error] trips. The failure only looks intermittent because rerun_flaky_tests re-runs the failed file on its own with FLUSH_ETCD=1: alone, nothing has overwritten kv/apisix/foo, the path is absent rather than incomplete, and that does not log an error. Write the secret first so the file no longer depends on what ran before it. The following blocks still verify that the credential resolves and authenticates.
nic-6443
force-pushed
the
test/basic-auth-secret-ref-order
branch
from
August 20, 2026 02:32
b42cd09 to
1d26833
Compare
shreemaan-abhishek
approved these changes
Aug 20, 2026
AlinsRan
approved these changes
Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
t/plugin/basic-auth.tTEST 22 fails in CI with:It is not a timing race — it is deterministic given the Vault state the rest of the job leaves behind.
Four test files write the same Vault path with different fields, and
vault kv putreplaces the whole secret rather than merging:ai-aws-content-moderation-secrets.tsecret_access_key,access_key_idauthz-keycloak4.tclient_secretbasic-auth.tpasswdopenid-connect9.tclient_secretThe first two sort before
basic-auth.tin thet/plugin/[a-k]*.tjob, so by the time it runskv/apisix/fooholds aclient_secretand nopasswd. TEST 22 then creates a consumer whose password is$secret://vault/test1/foo/passwd, and the admin write resolves it right there:admin/consumers.luacallscheck_duplicate_key()→find_consumer()→create_consume_cache()→fetch_secrets(), synchronously inside the request — which is why the error carries thePUT /apisix/admin/consumerscontext. The key exists but the field does not, so it logs at error level and the defaultno_error_log: [error]trips.It looks flaky only because of the rerun harness: after the job fails,
rerun_flaky_testsre-runs the failed file on its own withFLUSH_ETCD=1. Alone, nothing has overwrittenkv/apisix/foo, the path is absent rather than incomplete, that path does not log an error, and the file goes green — which is exactly what happened in the run that prompted this PR.Writing the secret before the reference is configured makes the file self-sufficient regardless of what ran before it.
Reproduced deterministically, and the fix verified against it:
before:
Failed 2/179 subtestswith the two error lines above — after:All tests successful.Sharing one Vault path across four unrelated test files is the underlying hazard; giving each file its own path would be the more thorough fix, but it touches four files and this one is enough to make
basic-auth.tindependent of the others.