@@ -40,21 +40,39 @@ describe("probeMatrix", () => {
4040 } ) ;
4141 } ) ;
4242
43- it ( "trims provided userId before client creation" , async ( ) => {
44- await probeMatrix ( {
43+ it ( "authenticates a configured userId instead of trusting the local client identity" , async ( ) => {
44+ createMatrixClientMock . mockImplementation ( async ( params : { userId ?: string } ) => {
45+ return {
46+ getUserId : vi . fn ( async ( ) => {
47+ if ( params . userId ) {
48+ return params . userId ;
49+ }
50+ throw Object . assign ( new Error ( "Invalid access token" ) , {
51+ statusCode : 401 ,
52+ } ) ;
53+ } ) ,
54+ } ;
55+ } ) ;
56+
57+ const result = await probeMatrix ( {
4558 homeserver : "https://matrix.example.org" ,
46- accessToken : "tok " ,
59+ accessToken : "expired-token " ,
4760 userId : " @bot:example.org " ,
4861 timeoutMs : 500 ,
4962 } ) ;
5063
5164 expect ( createMatrixClientMock ) . toHaveBeenCalledWith ( {
5265 homeserver : "https://matrix.example.org" ,
53- userId : "@bot:example.org" ,
54- accessToken : "tok " ,
66+ userId : undefined ,
67+ accessToken : "expired-token " ,
5568 persistStorage : false ,
5669 localTimeoutMs : 500 ,
5770 } ) ;
71+ expect ( result ) . toMatchObject ( {
72+ ok : false ,
73+ status : 401 ,
74+ error : "Invalid access token" ,
75+ } ) ;
5876 } ) ;
5977
6078 it ( "passes accountId through to client creation" , async ( ) => {
@@ -68,7 +86,7 @@ describe("probeMatrix", () => {
6886
6987 expect ( createMatrixClientMock ) . toHaveBeenCalledWith ( {
7088 homeserver : "https://matrix.example.org" ,
71- userId : "@bot:example.org" ,
89+ userId : undefined ,
7290 accessToken : "tok" ,
7391 persistStorage : false ,
7492 localTimeoutMs : 500 ,
@@ -112,7 +130,7 @@ describe("probeMatrix", () => {
112130
113131 expect ( createMatrixClientMock ) . toHaveBeenCalledWith ( {
114132 homeserver : "https://matrix.example.org" ,
115- userId : "@bot:example.org" ,
133+ userId : undefined ,
116134 accessToken : "tok" ,
117135 deviceId : "ABCDEF" ,
118136 persistStorage : false ,
0 commit comments