Skip to content

Commit 566c5d3

Browse files
committed
test: fix logic
1 parent afb8813 commit 566c5d3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/cmap/auth/mongodb_oidc/azure_service_workflow.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@ export class AzureServiceWorkflow extends ServiceWorkflow {
5353
throw new MongoAzureError(TOKEN_AUDIENCE_MISSING_ERROR);
5454
}
5555
let token;
56+
let response;
5657
const entry = this.cache.getEntry(tokenAudience);
5758
if (entry?.isValid()) {
5859
token = entry.token;
5960
} else {
6061
this.cache.deleteEntry(tokenAudience);
61-
const response = await getAzureTokenData(tokenAudience);
62+
response = await getAzureTokenData(tokenAudience);
6263
console.log('response', response);
6364
this.cache.addEntry(tokenAudience, response);
6465
token = response.access_token;
6566
}
6667
console.log('token', token);
67-
if (isEndpointResultInvalid(token)) {
68+
if (isEndpointResultInvalid(response)) {
6869
this.cache.deleteEntry(tokenAudience);
6970
throw new MongoAzureError(ENDPOINT_RESULT_ERROR);
7071
}
@@ -88,9 +89,9 @@ async function getAzureTokenData(tokenAudience: string): Promise<AzureAccessToke
8889
/**
8990
* Determines if a result returned from the endpoint is invalid.
9091
* This means the result is nullish, doesn't contain the access_token required field,
91-
* the expires_in required field, and does not contain extra fields.
92+
* the expires_in required field.
9293
*/
9394
function isEndpointResultInvalid(token: unknown): boolean {
9495
if (token == null || typeof token !== 'object') return true;
95-
return !('access_token' in token) || !('expires_in' in token);
96+
return !('access_token' in token) && !('expires_in' in token);
9697
}

0 commit comments

Comments
 (0)