Skip to content

Commit 9b3d7e7

Browse files
committed
test: move validation
1 parent 12a76f3 commit 9b3d7e7

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/cmap/auth/mongodb_oidc/azure_service_workflow.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,20 @@ export class AzureServiceWorkflow extends ServiceWorkflow {
5353
throw new MongoAzureError(TOKEN_AUDIENCE_MISSING_ERROR);
5454
}
5555
let token;
56-
let response;
5756
const entry = this.cache.getEntry(tokenAudience);
5857
if (entry?.isValid()) {
5958
token = entry.token;
6059
} else {
6160
this.cache.deleteEntry(tokenAudience);
62-
response = await getAzureTokenData(tokenAudience);
61+
const response = await getAzureTokenData(tokenAudience);
62+
if (isEndpointResultInvalid(response)) {
63+
throw new MongoAzureError(ENDPOINT_RESULT_ERROR);
64+
}
6365
console.log('response', response);
6466
this.cache.addEntry(tokenAudience, response);
6567
token = response.access_token;
6668
}
6769
console.log('token', token);
68-
if (isEndpointResultInvalid(response)) {
69-
this.cache.deleteEntry(tokenAudience);
70-
throw new MongoAzureError(ENDPOINT_RESULT_ERROR);
71-
}
7270
return token;
7371
}
7472
}
@@ -92,8 +90,6 @@ async function getAzureTokenData(tokenAudience: string): Promise<AzureAccessToke
9290
* the expires_in required field.
9391
*/
9492
function isEndpointResultInvalid(token: unknown): boolean {
95-
console.log('token in validation', token);
9693
if (token == null || typeof token !== 'object') return true;
97-
console.log('test', 'access_token' in token, 'expires_in' in token);
9894
return !('access_token' in token) && !('expires_in' in token);
9995
}

0 commit comments

Comments
 (0)