@@ -3,16 +3,15 @@ import sinon from "sinon";
3
3
import { Authority } from "../../src/authority/Authority" ;
4
4
import { INetworkModule , NetworkRequestOptions } from "../../src/network/INetworkModule" ;
5
5
import { Constants } from "../../src/utils/Constants" ;
6
- import { AuthorityType } from "../../src/authority/AuthorityType" ;
7
6
import {
8
- DEFAULT_TENANT_DISCOVERY_RESPONSE ,
9
7
TEST_URIS ,
10
8
RANDOM_TEST_GUID ,
11
9
DEFAULT_OPENID_CONFIG_RESPONSE
12
10
} from "../utils/StringConstants" ;
13
- import { ClientConfigurationErrorMessage } from "../../src/error/ClientConfigurationError" ;
11
+ import { ClientConfigurationErrorMessage , ClientConfigurationError } from "../../src/error/ClientConfigurationError" ;
14
12
import { ClientAuthErrorMessage } from "../../src" ;
15
13
import { ClientTestUtils } from "../client/ClientTestUtils" ;
14
+ import { TrustedAuthority } from "../../src/authority/TrustedAuthority" ;
16
15
17
16
describe ( "Authority.ts Class Unit Tests" , ( ) => {
18
17
afterEach ( ( ) => {
@@ -123,6 +122,7 @@ describe("Authority.ts Class Unit Tests", () => {
123
122
expect ( ( ) => authority . authorizationEndpoint ) . to . throw ( ClientAuthErrorMessage . endpointResolutionError . desc ) ;
124
123
expect ( ( ) => authority . tokenEndpoint ) . to . throw ( ClientAuthErrorMessage . endpointResolutionError . desc ) ;
125
124
expect ( ( ) => authority . endSessionEndpoint ) . to . throw ( ClientAuthErrorMessage . endpointResolutionError . desc ) ;
125
+ expect ( ( ) => authority . deviceCodeEndpoint ) . to . throw ( ClientAuthErrorMessage . endpointResolutionError . desc ) ;
126
126
expect ( ( ) => authority . selfSignedJwtAudience ) . to . throw ( ClientAuthErrorMessage . endpointResolutionError . desc ) ;
127
127
} ) ;
128
128
} ) ;
@@ -169,5 +169,34 @@ describe("Authority.ts Class Unit Tests", () => {
169
169
expect ( authority . endSessionEndpoint ) . to . be . eq ( DEFAULT_OPENID_CONFIG_RESPONSE . body . end_session_endpoint . replace ( "{tenant}" , "common" ) ) ;
170
170
expect ( authority . selfSignedJwtAudience ) . to . be . eq ( DEFAULT_OPENID_CONFIG_RESPONSE . body . issuer . replace ( "{tenant}" , "common" ) ) ;
171
171
} ) ;
172
+
173
+ it ( "Attempts to set instance metadata from network if not set" , async ( ) => {
174
+ sinon . restore ( ) ;
175
+ let setFromNetwork = false ;
176
+ sinon . stub ( TrustedAuthority , "getTrustedHostList" ) . returns ( [ ] ) ;
177
+ sinon . stub ( TrustedAuthority , "IsInTrustedHostList" ) . returns ( true ) ;
178
+ sinon . stub ( TrustedAuthority , "setTrustedAuthoritiesFromNetwork" ) . callsFake ( async ( ) => {
179
+ setFromNetwork = true ;
180
+ } ) ;
181
+
182
+ await authority . resolveEndpointsAsync ( ) ;
183
+ expect ( setFromNetwork ) . to . be . true ;
184
+ } ) ;
185
+
186
+ it ( "throws untrustedAuthority error if host is not in TrustedHostList" , async ( ) => {
187
+ sinon . restore ( ) ;
188
+ sinon . stub ( TrustedAuthority , "getTrustedHostList" ) . returns ( [ "testAuthority" ] ) ;
189
+ sinon . stub ( TrustedAuthority , "IsInTrustedHostList" ) . returns ( false ) ;
190
+
191
+ let err = null ;
192
+ try {
193
+ await authority . resolveEndpointsAsync ( ) ;
194
+ } catch ( e ) {
195
+ expect ( e ) . to . be . instanceOf ( ClientConfigurationError ) ;
196
+ err = e ;
197
+ }
198
+ expect ( err . errorMessage ) . to . equal ( ClientConfigurationErrorMessage . untrustedAuthority . desc ) ;
199
+ expect ( err . errorCode ) . to . equal ( ClientConfigurationErrorMessage . untrustedAuthority . code ) ;
200
+ } ) ;
172
201
} ) ;
173
202
} ) ;
0 commit comments