Skip to content

Commit f441384

Browse files
committed
CCM-12736: fix test auth race condition
1 parent b987d50 commit f441384

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

tests/test-team/helpers/auth/cognito-auth-helper.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type TestUserDynamicDetails = {
3737
campaignId?: string;
3838
campaignIds?: string[];
3939
clientId: string;
40-
password: string;
4140
clientName?: string;
4241
identityAttributes?: Partial<Record<UserIdentityAttributes, string>>;
4342
};
@@ -47,6 +46,7 @@ export type TestUserContext = TestUserStaticDetails &
4746
accessToken: string;
4847
idToken: string;
4948
refreshToken: string;
49+
password: string;
5050
};
5151

5252
export const testUsers: Record<string, TestUserStaticDetails> = {
@@ -136,17 +136,26 @@ export type TestUser = TestUserStaticDetails &
136136
* Password auth implicitly resets temp password if not logged in previously
137137
*/
138138
getAccessToken(): Promise<string>;
139+
139140
/**
140141
* Gets an ID token for a test user
141142
* Uses the same fallback logic as getAccessToken
142143
*/
143144
getIdToken(): Promise<string>;
145+
144146
/**
145147
* Sets an updated password in local state.
146148
* The password should already have been updated in Cognito
147149
* e.g. by using the change password form in the UI
148150
*/
149151
setUpdatedPassword(password: string): Promise<void>;
152+
153+
/**
154+
* Gets a users password from the state file.
155+
* This will be the latest version of a users password
156+
* Use this instead of user.password
157+
*/
158+
getPassword(): Promise<string>;
150159
};
151160

152161
export class CognitoAuthHelper {
@@ -203,11 +212,11 @@ export class CognitoAuthHelper {
203212
}
204213

205214
if (userCtx.refreshToken) {
206-
const refeshedTokens = await this.refreshUserSessionTokens(
215+
const refreshedTokens = await this.refreshUserSessionTokens(
207216
id,
208217
userCtx.refreshToken
209218
);
210-
return refeshedTokens.accessToken;
219+
return refreshedTokens.accessToken;
211220
}
212221
}
213222

@@ -223,11 +232,11 @@ export class CognitoAuthHelper {
223232
}
224233

225234
if (userCtx?.refreshToken) {
226-
const refeshedTokens = await this.refreshUserSessionTokens(
235+
const refreshedTokens = await this.refreshUserSessionTokens(
227236
id,
228237
userCtx.refreshToken
229238
);
230-
return refeshedTokens.idToken;
239+
return refreshedTokens.idToken;
231240
}
232241

233242
const authTokens = await this.passwordAuth(id);
@@ -251,7 +260,16 @@ export class CognitoAuthHelper {
251260
await CognitoAuthHelper.authContextFile.set(runId, id, {
252261
password,
253262
});
254-
this.password = password;
263+
},
264+
265+
async getPassword() {
266+
const u = await CognitoAuthHelper.authContextFile.get(runId, id);
267+
268+
if (!u) {
269+
throw new Error('User not found');
270+
}
271+
272+
return u.password;
255273
},
256274
};
257275

tests/test-team/pages/templates-mgmt-login-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class TemplateMgmtSignInPage extends TemplateMgmtBasePageNonDynamic {
3737

3838
await this.emailInput.fill(user.email);
3939

40-
await this.passwordInput.fill(user.password);
40+
await this.passwordInput.fill(await user.getPassword());
4141

4242
await this.clickSignInButton();
4343

0 commit comments

Comments
 (0)