Skip to content
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

[Identity] Rethrow AuthenticationErrors in DeviceCodeCredential poll loop #5430

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/identity/identity/src/credentials/deviceCodeCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export class DeviceCodeCredential implements TokenCredential {
throw err;
case "bad_verification_code":
throw err;
default: // Any other error should be rethrown
throw err;
}
} else {
throw err;
Expand Down
25 changes: 25 additions & 0 deletions sdk/identity/identity/test/node/deviceCodeCredential.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,31 @@ describe("DeviceCodeCredential", function() {
});
});

it("rethrows an unexpected AuthenticationError", async function() {
const mockHttpClient = new MockAuthHttpClient({
authResponse: [
{ status: 200, parsedBody: deviceCodeResponse },
{ status: 400, parsedBody: pendingResponse },
{ status: 400, parsedBody: pendingResponse },
{ status: 401, parsedBody: { error: "invalid_client", error_description: "The request body must contain..."} }
]
});

const credential = new DeviceCodeCredential(
"tenant",
"client",
(details) => assert.equal(details.message, deviceCodeResponse.message),
mockHttpClient.identityClientOptions
);

await assertRejects(credential.getToken("scope"), (error) => {
const authError = error as AuthenticationError;
assert.strictEqual(error.name, "AuthenticationError");
assert.strictEqual(authError.errorResponse.error, "invalid_client");
return true;
});
});

it("cancels polling when abort signal is raised", async function() {
const mockHttpClient = new MockAuthHttpClient({
authResponse: [
Expand Down