Skip to content

Commit 6a001bf

Browse files
authored
test: make shared secret names unique (#910)
* test: make shared secret names unique * try this * try this * try that * poke ci * test * test * test * test * test * test * poke ci * Revert "test" This reverts commit 1b8b847. * test * test * this should work * fix lint * fix e2e hotswap test with shared secrets * uncomment project tear down in e2e test * add amplifySharedSecretNameKey * Revert "add amplifySharedSecretNameKey" This reverts commit b5f9050. * add amplifySharedSecretNameKey * fix lint * remove createSharedSecretEnvObject * try this
1 parent f70611d commit 6a001bf

File tree

6 files changed

+71
-25
lines changed

6 files changed

+71
-25
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/integration-tests': patch
3+
---
4+
5+
Make shared secret names unique for e2e tests
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { shortUuid } from './short_uuid.js';
2+
3+
/**
4+
* Create a unique shared secret name
5+
*/
6+
export const createAmplifySharedSecretName = (): string => {
7+
return 'amplifySharedSecret' + shortUuid();
8+
};
9+
10+
export const amplifySharedSecretNameKey = 'AMPLIFY_SHARED_SECRET_NAME';

packages/integration-tests/src/test-e2e/deployment.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import { ClientConfigFormat } from '@aws-amplify/client-config';
2525
import { testConcurrencyLevel } from './test_concurrency.js';
2626
import { TestCdkProjectBase } from '../test-project-setup/cdk/test_cdk_project_base.js';
2727
import { getTestCdkProjectCreators } from '../test-project-setup/cdk/test_cdk_project_creator.js';
28+
import {
29+
amplifySharedSecretNameKey,
30+
createAmplifySharedSecretName,
31+
} from '../shared_secret.js';
2832

2933
const testProjectCreators = getTestProjectCreators();
3034
const testCdkProjectCreators = getTestCdkProjectCreators();
@@ -122,15 +126,24 @@ void describe('deployment tests', { concurrency: testConcurrencyLevel }, () => {
122126
});
123127

124128
void describe('in sequence', { concurrency: false }, () => {
129+
const sharedSecretsEnv = {
130+
[amplifySharedSecretNameKey]: createAmplifySharedSecretName(),
131+
};
125132
void it(`[${testProjectCreator.name}] deploys fully`, async () => {
126-
await testProject.deploy(sandboxBackendIdentifier);
133+
await testProject.deploy(
134+
sandboxBackendIdentifier,
135+
sharedSecretsEnv
136+
);
127137
await testProject.assertPostDeployment(sandboxBackendIdentifier);
128138
});
129139

130140
void it(`[${testProjectCreator.name}] hot-swaps a change`, async () => {
131141
const processController = amplifyCli(
132142
['sandbox', '--dirToWatch', 'amplify'],
133-
testProject.projectDirPath
143+
testProject.projectDirPath,
144+
{
145+
env: sharedSecretsEnv,
146+
}
134147
);
135148

136149
const updates = await testProject.getUpdates();

packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { TestProjectCreator } from './test_project_creator.js';
1010
import { DeployedResourcesFinder } from '../find_deployed_resource.js';
1111
import assert from 'node:assert';
1212
import { InvokeCommand, LambdaClient } from '@aws-sdk/client-lambda';
13+
import {
14+
amplifySharedSecretNameKey,
15+
createAmplifySharedSecretName,
16+
} from '../shared_secret.js';
1317

1418
/**
1519
* Creates test projects with data, storage, and auth categories.
@@ -85,7 +89,7 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
8589
'amazonSecret',
8690
];
8791

88-
private readonly testSharedSecretNames = ['amplifySharedSecret'];
92+
private amplifySharedSecret: string;
8993

9094
/**
9195
* Create a test project instance.
@@ -105,9 +109,19 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
105109
/**
106110
* @inheritdoc
107111
*/
108-
override async deploy(backendIdentifier: BackendIdentifier) {
112+
override async deploy(
113+
backendIdentifier: BackendIdentifier,
114+
environment: Record<string, string> = {}
115+
) {
116+
this.amplifySharedSecret =
117+
amplifySharedSecretNameKey in environment
118+
? environment[amplifySharedSecretNameKey]
119+
: createAmplifySharedSecretName();
120+
const sharedSecretEnvObject = {
121+
[amplifySharedSecretNameKey]: this.amplifySharedSecret,
122+
};
109123
await this.setUpDeployEnvironment(backendIdentifier);
110-
await super.deploy(backendIdentifier);
124+
await super.deploy(backendIdentifier, sharedSecretEnvObject);
111125
}
112126

113127
/**
@@ -147,7 +161,6 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
147161
backendId: BackendIdentifier
148162
): Promise<void> {
149163
await super.assertPostDeployment(backendId);
150-
151164
// Check that deployed lambda is working correctly
152165

153166
// find lambda function
@@ -171,7 +184,7 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
171184
assert.equal(
172185
responsePayload,
173186
// eslint-disable-next-line spellcheck/spell-checker
174-
'Your uuid is 6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b. TEST_SECRET env var value is amazonSecret-e2eTestValue. TEST_SHARED_SECRET env var value is amplifySharedSecret-e2eTestSharedValue.'
187+
`Your uuid is 6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b. TEST_SECRET env var value is amazonSecret-e2eTestValue. TEST_SHARED_SECRET env var value is ${this.amplifySharedSecret}-e2eTestSharedValue.`
175188
);
176189
}
177190

@@ -182,14 +195,12 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
182195
const secretValue = `${secretName}-e2eTestValue`;
183196
await this.secretClient.setSecret(backendId, secretName, secretValue);
184197
}
185-
for (const sharedSecretName of this.testSharedSecretNames) {
186-
const secretValue = `${sharedSecretName}-e2eTestSharedValue`;
187-
await this.secretClient.setSecret(
188-
backendId.namespace,
189-
sharedSecretName,
190-
secretValue
191-
);
192-
}
198+
const secretValue = `${this.amplifySharedSecret}-e2eTestSharedValue`;
199+
await this.secretClient.setSecret(
200+
backendId.namespace,
201+
this.amplifySharedSecret,
202+
secretValue
203+
);
193204
};
194205

195206
private clearDeployEnvironment = async (
@@ -199,11 +210,9 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
199210
for (const secretName of this.testSecretNames) {
200211
await this.secretClient.removeSecret(backendId, secretName);
201212
}
202-
for (const sharedSecretName of this.testSharedSecretNames) {
203-
await this.secretClient.removeSecret(
204-
backendId.namespace,
205-
sharedSecretName
206-
);
207-
}
213+
await this.secretClient.removeSecret(
214+
backendId.namespace,
215+
this.amplifySharedSecret
216+
);
208217
};
209218
}

packages/integration-tests/src/test-project-setup/test_project_base.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ export abstract class TestProjectBase {
5757
/**
5858
* Deploy the project.
5959
*/
60-
async deploy(backendIdentifier: BackendIdentifier) {
60+
async deploy(
61+
backendIdentifier: BackendIdentifier,
62+
environment?: Record<string, string>
63+
) {
6164
if (backendIdentifier.type === 'sandbox') {
62-
await amplifyCli(['sandbox'], this.projectDirPath)
65+
await amplifyCli(['sandbox'], this.projectDirPath, {
66+
env: environment,
67+
})
6368
.do(waitForSandboxDeploymentToPrintTotalTime())
6469
.do(interruptSandbox())
6570
.do(rejectCleanupSandbox())
@@ -75,7 +80,10 @@ export abstract class TestProjectBase {
7580
],
7681
this.projectDirPath,
7782
{
78-
env: { CI: 'true' },
83+
env: {
84+
CI: 'true',
85+
...environment,
86+
},
7987
}
8088
).run();
8189
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { defineFunction, secret } from '@aws-amplify/backend';
2+
import { amplifySharedSecretNameKey } from '../../../shared_secret.js';
23

34
export const myFunc = defineFunction({
45
name: 'specialTestFunction',
56
entry: './func-src/handler.ts',
67
environment: {
78
TEST_SECRET: secret('amazonSecret'),
8-
TEST_SHARED_SECRET: secret('amplifySharedSecret'),
9+
TEST_SHARED_SECRET: secret(process.env[amplifySharedSecretNameKey] as string),
910
},
1011
});

0 commit comments

Comments
 (0)