-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When rendered in an iframe, silent rejects
... with an appropriate error. * Get rid of the decorator function because it is only used once * Add EnvironmentError * tests resolves #902
- Loading branch information
1 parent
3288ca8
commit 394486f
Showing
4 changed files
with
113 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { AuthError } from "./AuthError"; | ||
import { IdToken } from "../IdToken"; | ||
import { StringUtils } from "../utils/StringUtils"; | ||
|
||
export const EnvironmentErrorMessage = { | ||
noResolveInIframe: { | ||
code: "no_resolve_in_iframe", | ||
desc: `Msal.js does not currently support resolving a silent token request in an iframe` | ||
} | ||
}; | ||
|
||
/** | ||
* Error thrown when there is an error in the client code running on the browser. | ||
*/ | ||
export class EnvironmentError extends AuthError { | ||
|
||
constructor(errorCode: string, errorMessage?: string) { | ||
super(errorCode, errorMessage); | ||
this.name = "EnvironmentError"; | ||
|
||
Object.setPrototypeOf(this, EnvironmentError.prototype); | ||
} | ||
|
||
static createNoResolveInIframeError(): EnvironmentError { | ||
const { code, desc } = EnvironmentErrorMessage.noResolveInIframe | ||
return new EnvironmentError(code, desc); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as mocha from "mocha"; | ||
import { expect } from "chai"; | ||
import { EnvironmentError, EnvironmentErrorMessage } from "../../src/error/EnvironmentError"; | ||
import { AuthError } from "../../src"; | ||
|
||
describe("EnvironmentError.ts Class", () => { | ||
it("EnvironmentError object can be created", () => { | ||
|
||
const TEST_ERROR_CODE: string = "test"; | ||
const TEST_ERROR_MSG: string = "This is a test error"; | ||
let environmentError = new EnvironmentError(TEST_ERROR_CODE, TEST_ERROR_MSG); | ||
let err: EnvironmentError; | ||
|
||
try { | ||
throw environmentError; | ||
} catch (error) { | ||
err = error; | ||
} | ||
|
||
expect(err instanceof EnvironmentError).to.be.true; | ||
expect(err instanceof AuthError).to.be.true; | ||
expect(err instanceof Error).to.be.true; | ||
expect(err.errorCode).to.equal(TEST_ERROR_CODE); | ||
expect(err.errorMessage).to.equal(TEST_ERROR_MSG); | ||
expect(err.message).to.equal(TEST_ERROR_MSG); | ||
expect(err.name).to.equal("EnvironmentError"); | ||
expect(err.stack).to.include("EnvironmentError.spec.js"); | ||
}); | ||
|
||
it("createNoResolveInIframeError creates a EnvironmentError object", () => { | ||
|
||
const serverUnavailableError = EnvironmentError.createNoResolveInIframeError(); | ||
let err: EnvironmentError; | ||
|
||
try { | ||
throw serverUnavailableError; | ||
} catch (error) { | ||
err = error; | ||
} | ||
|
||
expect(err.errorCode).to.equal(EnvironmentErrorMessage.noResolveInIframe.code); | ||
expect(err.errorMessage).to.equal(EnvironmentErrorMessage.noResolveInIframe.desc); | ||
expect(err.message).to.equal(EnvironmentErrorMessage.noResolveInIframe.desc); | ||
expect(err.name).to.equal("EnvironmentError"); | ||
expect(err.stack).to.include("EnvironmentError.spec.js"); | ||
}); | ||
|
||
|
||
}); | ||
|