@@ -15,6 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
import { Mocked , mocked } from "jest-mock" ;
18
+ import fetchMock from "fetch-mock-jest" ;
18
19
19
20
import { logger } from "../../src/logger" ;
20
21
import { ClientEvent , IMatrixClientCreateOpts , ITurnServerResponse , MatrixClient , Store } from "../../src/client" ;
@@ -76,6 +77,7 @@ import { SecretStorageKeyDescriptionAesV1, ServerSideSecretStorageImpl } from ".
76
77
import { CryptoBackend } from "../../src/common-crypto/CryptoBackend" ;
77
78
import { KnownMembership } from "../../src/@types/membership" ;
78
79
import { RoomMessageEventContent } from "../../src/@types/events" ;
80
+ import { mockOpenIdConfiguration } from "../test-utils/oidc.ts" ;
79
81
80
82
jest . useFakeTimers ( ) ;
81
83
@@ -265,13 +267,17 @@ describe("MatrixClient", function () {
265
267
266
268
if ( next . error ) {
267
269
// eslint-disable-next-line
268
- return Promise . reject ( {
269
- errcode : ( < MatrixError > next . error ) . errcode ,
270
- httpStatus : ( < MatrixError > next . error ) . httpStatus ,
271
- name : ( < MatrixError > next . error ) . errcode ,
272
- message : "Expected testing error" ,
273
- data : next . error ,
274
- } ) ;
270
+ return Promise . reject (
271
+ new MatrixError (
272
+ {
273
+ errcode : ( < MatrixError > next . error ) . errcode ,
274
+ name : ( < MatrixError > next . error ) . errcode ,
275
+ message : "Expected testing error" ,
276
+ data : next . error ,
277
+ } ,
278
+ ( < MatrixError > next . error ) . httpStatus ,
279
+ ) ,
280
+ ) ;
275
281
}
276
282
return Promise . resolve ( next . data ) ;
277
283
}
@@ -3489,6 +3495,63 @@ describe("MatrixClient", function () {
3489
3495
} ) ;
3490
3496
} ) ;
3491
3497
3498
+ describe ( "getAuthMetadata" , ( ) => {
3499
+ beforeEach ( ( ) => {
3500
+ fetchMock . mockReset ( ) ;
3501
+ // This request is made by oidc-client-ts so is not intercepted by httpLookups
3502
+ fetchMock . get ( "https://auth.org/jwks" , {
3503
+ status : 200 ,
3504
+ headers : {
3505
+ "Content-Type" : "application/json" ,
3506
+ } ,
3507
+ keys : [ ] ,
3508
+ } ) ;
3509
+ } ) ;
3510
+
3511
+ it ( "should use unstable prefix" , async ( ) => {
3512
+ const metadata = mockOpenIdConfiguration ( ) ;
3513
+ httpLookups = [
3514
+ {
3515
+ method : "GET" ,
3516
+ path : `/auth_metadata` ,
3517
+ data : metadata ,
3518
+ prefix : "/_matrix/client/unstable/org.matrix.msc2965" ,
3519
+ } ,
3520
+ ] ;
3521
+
3522
+ await expect ( client . getAuthMetadata ( ) ) . resolves . toEqual ( {
3523
+ ...metadata ,
3524
+ signingKeys : [ ] ,
3525
+ } ) ;
3526
+ expect ( httpLookups . length ) . toEqual ( 0 ) ;
3527
+ } ) ;
3528
+
3529
+ it ( "should fall back to auth_issuer + openid-configuration" , async ( ) => {
3530
+ const metadata = mockOpenIdConfiguration ( ) ;
3531
+ httpLookups = [
3532
+ {
3533
+ method : "GET" ,
3534
+ path : `/auth_metadata` ,
3535
+ error : new MatrixError ( { errcode : "M_UNRECOGNIZED" } , 404 ) ,
3536
+ prefix : "/_matrix/client/unstable/org.matrix.msc2965" ,
3537
+ } ,
3538
+ {
3539
+ method : "GET" ,
3540
+ path : `/auth_issuer` ,
3541
+ data : { issuer : metadata . issuer } ,
3542
+ prefix : "/_matrix/client/unstable/org.matrix.msc2965" ,
3543
+ } ,
3544
+ ] ;
3545
+ fetchMock . get ( "https://auth.org/.well-known/openid-configuration" , metadata ) ;
3546
+
3547
+ await expect ( client . getAuthMetadata ( ) ) . resolves . toEqual ( {
3548
+ ...metadata ,
3549
+ signingKeys : [ ] ,
3550
+ } ) ;
3551
+ expect ( httpLookups . length ) . toEqual ( 0 ) ;
3552
+ } ) ;
3553
+ } ) ;
3554
+
3492
3555
describe ( "identityHashedLookup" , ( ) => {
3493
3556
it ( "should return hashed lookup results" , async ( ) => {
3494
3557
const ID_ACCESS_TOKEN = "hello_id_server_please_let_me_make_a_request" ;
0 commit comments