Skip to content

Commit c5abda8

Browse files
authored
Update 3p-e2e pipelines and native auth e2e tests (#8200)
1 parent 71c8a9d commit c5abda8

File tree

12 files changed

+3934
-178
lines changed

12 files changed

+3934
-178
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,8 @@ temp-cache.json
285285
# Jest JUnit reporter
286286
junit.xml
287287

288+
# MSAL Native Auth config files (contains sensitive data)
289+
samples/msal-browser-samples/NativeAuthSample/nativeAuthConfig.json
290+
288291
# ApiExtractor
289-
temp/
292+
temp/

.pipelines/3p-e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extends:
7878
- "pop"
7979
- "customizable-e2e-test"
8080
- "ExpressSample"
81+
- "NativeAuthSample"
8182
debug: ${{ parameters.debug }}
8283
npmInstallTimeout: ${{ parameters.npmInstallTimeout }}
8384
- ${{ if eq(parameters.runNodeTests, true) }}:

package-lock.json

Lines changed: 394 additions & 171 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
module.exports = {
2-
displayName: "Native Auth Sample App",
2+
displayName: "Native Auth Sample App E2E tests",
33
globals: {
44
__PORT__: 30670,
55
__STARTCMD__: "npm start -- --port 30670",
66
},
7-
testMatch: ["<rootDir>/test/**/*.spec.ts"],
8-
preset: "../../../../e2eTestUtils/jest-puppeteer-utils/jest-preset.js",
9-
transform: {
10-
"^.+\\.ts?$": "ts-jest",
11-
},
7+
preset: "../../e2eTestUtils/jest-puppeteer-utils/jest-preset.js",
128
};

samples/msal-browser-samples/NativeAuthSample/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@
1818
"@azure/msal-browser": "^4.0.0",
1919
"@types/express": "^4.17.3",
2020
"@types/jest": "^29.5.0",
21+
"e2e-test-utils": "file:../../e2eTestUtils",
2122
"jest": "^29.5.0",
2223
"jest-junit": "^16.0.0",
2324
"jose": "^2.0.7",
2425
"ts-jest": "^29.1.0",
2526
"typescript": "^4.9.5"
27+
},
28+
"jest-junit": {
29+
"suiteNameTemplate": "Native Auth Sample Tests",
30+
"outputDirectory": ".",
31+
"outputName": "test-results.xml"
2632
}
2733
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* Test configuration for Native Auth Sample E2E tests
3+
* Contains tenant information, proxy settings, timeouts, and test user data
4+
*/
5+
6+
import * as fs from 'fs';
7+
import * as path from 'path';
8+
9+
/**
10+
* Default test configuration
11+
* Update these values based on your test environment
12+
*/
13+
export const testConfig = {
14+
tenant: {
15+
name: "MSIDLABCIAM6",
16+
id: "fe362aec-5d43-45d1-b730-9755e60dc3b9",
17+
labKeyVaultName: "MSIDLABCIAM6"
18+
},
19+
20+
proxy: {
21+
port: 30001,
22+
enabled: true
23+
},
24+
25+
timeouts: {
26+
standard: 45000, // 45 seconds
27+
auth: 60000, // 60 seconds
28+
test: 120000 // 120 seconds
29+
},
30+
31+
screenshots: {
32+
enabled: true,
33+
baseFolderName: "./screenshots"
34+
}
35+
};
36+
37+
38+
/**
39+
* Utility functions
40+
*/
41+
export const getTenantInfo = () => ({
42+
name: testConfig.tenant.name,
43+
id: testConfig.tenant.id
44+
});
45+
46+
export const getProxyPort = () => testConfig.proxy.port;
47+
48+
export const getLabKeyVaultName = () => testConfig.tenant.labKeyVaultName;
49+
50+
/**
51+
* Constants for nativeAuthConfig.json keys
52+
* These represent the existing keys in the configuration file
53+
*/
54+
export const NATIVE_AUTH_CONFIG_KEYS = {
55+
// Root level
56+
NATIVE_AUTH: 'native_auth',
57+
58+
// Native auth configuration keys
59+
EMAIL_PASSWORD_CLIENT_ID: 'native_auth.email_password_client_id',
60+
EMAIL_CODE_CLIENT_ID: 'native_auth.email_code_client_id',
61+
EMAIL_PASSWORD_ATTRIBUTES_CLIENT_ID: 'native_auth.email_password_attributes_client_id',
62+
EMAIL_CODE_ATTRIBUTES_CLIENT_ID: 'native_auth.email_code_attributes_client_id',
63+
TENANT_SUBDOMAIN: 'native_auth.tenant_subdomain',
64+
TENANT_ID: 'native_auth.tenant_id',
65+
SIGN_IN_EMAIL_PASSWORD_USERNAME: 'native_auth.sign_in_email_password_username',
66+
SIGN_IN_EMAIL_CODE_USERNAME: 'native_auth.sign_in_email_code_username',
67+
RESET_PASSWORD_USERNAME: 'native_auth.reset_password_username',
68+
PASSWORD_SIGN_IN_EMAIL_CODE: 'native_auth.password_sign_in_email_code',
69+
PASSWORD_PROVIDER: 'native_auth.password_provider',
70+
KEYVAULT_URL: 'native_auth.keyvault_url'
71+
} as const;
72+
73+
/**
74+
* Utility function to parse nativeAuthConfig.json and read values based on keys
75+
*/
76+
export class NativeAuthConfigParser {
77+
private static configCache: any = null;
78+
private static readonly CONFIG_PATH = path.join(__dirname, '..', 'nativeAuthConfig.json');
79+
80+
/**
81+
* Load and parse the nativeAuthConfig.json file
82+
* @returns Parsed configuration object
83+
*/
84+
private static loadConfig(): any {
85+
if (!this.configCache) {
86+
try {
87+
const configData = fs.readFileSync(this.CONFIG_PATH, 'utf8');
88+
this.configCache = JSON.parse(configData);
89+
} catch (error) {
90+
throw new Error(`Failed to load native auth config from ${this.CONFIG_PATH}: ${error}`);
91+
}
92+
}
93+
return this.configCache;
94+
}
95+
96+
/**
97+
* Get a value from the native auth configuration using dot notation
98+
* @param key - The key to retrieve (supports dot notation like 'native_auth.email_password_client_id')
99+
* @returns The value associated with the key
100+
*/
101+
static getValue(key: string): any {
102+
const config = this.loadConfig();
103+
const keys = key.split('.');
104+
let value: any = config;
105+
106+
for (const k of keys) {
107+
if (value && typeof value === 'object' && k in value) {
108+
value = value[k];
109+
} else {
110+
throw new Error(`Key '${key}' not found in native auth configuration`);
111+
}
112+
}
113+
114+
return value;
115+
}
116+
117+
}
118+
119+
/**
120+
* Convenience function to get a value from native auth config
121+
* @param key - The key to retrieve (supports dot notation)
122+
* @returns The value associated with the key
123+
*/
124+
export const getNativeAuthConfigValue = (key: string): any => {
125+
return NativeAuthConfigParser.getValue(key);
126+
};
127+
128+
/**
129+
* Parsed native auth configuration values
130+
* These are the actual values from nativeAuthConfig.json
131+
*/
132+
export const nativeAuthConfig = {
133+
emailPasswordClientId: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.EMAIL_PASSWORD_CLIENT_ID),
134+
emailCodeClientId: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.EMAIL_CODE_CLIENT_ID),
135+
emailPasswordAttributesClientId: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.EMAIL_PASSWORD_ATTRIBUTES_CLIENT_ID),
136+
emailCodeAttributesClientId: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.EMAIL_CODE_ATTRIBUTES_CLIENT_ID),
137+
tenantSubdomain: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.TENANT_SUBDOMAIN),
138+
tenantId: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.TENANT_ID),
139+
signInEmailPasswordUsername: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.SIGN_IN_EMAIL_PASSWORD_USERNAME),
140+
signInEmailCodeUsername: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.SIGN_IN_EMAIL_CODE_USERNAME),
141+
resetPasswordUsername: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.RESET_PASSWORD_USERNAME),
142+
passwordSignInEmailCode: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.PASSWORD_SIGN_IN_EMAIL_CODE),
143+
passwordProvider: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.PASSWORD_PROVIDER),
144+
keyvaultUrl: getNativeAuthConfigValue(NATIVE_AUTH_CONFIG_KEYS.KEYVAULT_URL)
145+
};
146+
147+
/**
148+
* Test data for negative test cases and other test-specific scenarios
149+
* These should not be replaced with real configuration values
150+
*/
151+
export const testData = {
152+
// Negative test case emails
153+
invalidUserEmail: "test123@test",
154+
nonRegisteredEmail: "[email protected]",
155+
incorrectPassword: "incorrect-password",
156+
invalidPassword: "invalid-password!",
157+
invalidOtpCode: "12345678"
158+
};
159+
160+
161+
/**
162+
* Get test users object with real account information
163+
* @returns Object containing test user accounts
164+
*/
165+
export const getTestUsers = () => ({
166+
signInEmailPassword: nativeAuthConfig.signInEmailPasswordUsername,
167+
signInEmailCode: nativeAuthConfig.signInEmailCodeUsername,
168+
resetPassword: nativeAuthConfig.resetPasswordUsername,
169+
});
170+
171+
/**
172+
* Get test data for negative test cases
173+
* @returns Object containing test data for negative scenarios
174+
*/
175+
export const getTestData = () => testData;

0 commit comments

Comments
 (0)