Skip to content

Commit d3ee9cc

Browse files
committed
fix(qa): invalidate stale WC API keys after environment reset
resetEnvironment() wipes the DB row backing whatever WC API key is cached in .env, but left the now-dead ck_/cs_ pair in place. ensureWooCommerceApiKeys() only checks that the pair is present (deliberately, to avoid a different false-positive on shared environments), so every WC REST call after a reset 401'd until someone noticed and cleared the keys by hand. Verified on both local wp-env and Kinsta.
1 parent 607e12f commit d3ee9cc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tests/qa/utils/helpers/env.helper.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execFileSync } from 'node:child_process';
2+
import { updateDotenv } from '@inpsyde/playwright-utils/build';
23
import type { AnyCli } from './pos-cli.helper';
34
import { runWpCli } from './pos-cli.helper';
45

@@ -9,6 +10,16 @@ const checkEnvVars = ( names: string[] ): void => {
910
}
1011
};
1112

13+
// A reset wipes the DB row backing whatever ck_/cs_ pair is in .env, but leaves the now-dead
14+
// strings in place. ensureWooCommerceApiKeys() only checks that they're present (deliberately,
15+
// see its own comment), so without this every WC REST call after a reset 401s until someone
16+
// notices and clears them by hand.
17+
async function invalidateApiKeys(): Promise< void > {
18+
delete process.env.WC_API_KEY;
19+
delete process.env.WC_API_SECRET;
20+
await updateDotenv( '.env', { WC_API_KEY: '', WC_API_SECRET: '' } );
21+
}
22+
1223
// Wipes the database and reinstalls WordPress + WooCommerce from scratch. Destructive and
1324
// irreversible — use with care on shared environments.
1425
//
@@ -28,6 +39,7 @@ export async function resetEnvironment( cli: AnyCli ): Promise< void > {
2839
checkEnvVars( [ 'WP_BASE_URL', 'WP_USERNAME', 'WP_PASSWORD' ] );
2940

3041
await runWpCli( cli, 'db reset --yes' );
42+
await invalidateApiKeys();
3143
await runWpCli(
3244
cli,
3345
// Single-quoted: WpEnvCli wraps the whole command in `bash -c "..."` (double
@@ -64,6 +76,7 @@ async function resetRemoteEnvironment( cli: AnyCli ): Promise< void > {
6476
],
6577
{ stdio: 'inherit', timeout: 5 * 60_000 }
6678
);
79+
await invalidateApiKeys();
6780

6881
// reset-wp.sh deletes all WordPress files, including plugins/themes — unlike a plain
6982
// `wp db reset` (wpenv path above), which only wipes the database and leaves them on

0 commit comments

Comments
 (0)