|
| 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