-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fixed bug where dev-provided certificate was not being attached to client assertion #7088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
}); | ||
|
||
test("acquireTokenByClientCredential handles AuthErrors as expected", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted the test acquireTokenByClientCredential handles AuthErrors as expected
.
This test doesn't accomplish anything
test("ensures that developer-provided certificate is attached to client assertion", async () => { | ||
const getClientAssertionSpy: jest.SpyInstance = jest.spyOn( | ||
ClientApplication.prototype, | ||
<any>"getClientAssertion" | ||
); | ||
}; | ||
|
||
const appConfig: Configuration = { | ||
auth: { | ||
clientId: TEST_CONSTANTS.CLIENT_ID, | ||
authority: TEST_CONSTANTS.DEFAULT_AUTHORITY, // contains "common" | ||
clientAssertion: "testAssertion", | ||
}, | ||
}; | ||
const cryptoKeys: CryptoKeys = new CryptoKeys(); | ||
config.auth.clientCertificate = { | ||
thumbprint: cryptoKeys.thumbprint, | ||
privateKey: cryptoKeys.privateKey, | ||
}; | ||
delete config.auth.clientSecret; | ||
const client: ConfidentialClientApplication = | ||
new ConfidentialClientApplication(config); | ||
|
||
const request: ClientCredentialRequest = { | ||
scopes: TEST_CONSTANTS.DEFAULT_GRAPH_SCOPE, | ||
skipCache: false, | ||
}; | ||
const request: ClientCredentialRequest = { | ||
scopes: TEST_CONSTANTS.DEFAULT_GRAPH_SCOPE, | ||
skipCache: false, | ||
}; | ||
|
||
const authApp = new ConfidentialClientApplication(appConfig); | ||
authApp.SetAppTokenProvider(testProvider); | ||
const authResult = (await client.acquireTokenByClientCredential( | ||
request | ||
)) as AuthenticationResult; | ||
expect(authResult.accessToken).toEqual( | ||
CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT.body.access_token | ||
); | ||
|
||
await expect( | ||
authApp.acquireTokenByClientCredential(request) | ||
).rejects.toMatchObject( | ||
createClientAuthError(ClientAuthErrorCodes.missingTenantIdError) | ||
); | ||
const clientAssertion: ClientAssertion = await getClientAssertionSpy | ||
.mock.results[0].value; | ||
expect(clientAssertion.assertion.length).toBeGreaterThan(1); | ||
expect(clientAssertion.assertionType).toBe( | ||
Constants.JWT_BEARER_ASSERTION_TYPE | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the relevant unit test I added for the bug fix
Fixes acquireTokenByClientCredential broken for clientCertificate #7082
Applied boy-scout-rule to
ConfidentialClientApplication.spec.ts
(contains unit tests). I've been waiting for a good opportunity to do this. The ConfidentialClientApplication tests are now in line with the other test files: All Managed Identity sources, ClientCredentialClient, OnBehalfOfClient and UsernamePasswordClient.