@@ -224,3 +224,56 @@ test("use ANONYMOUS if username and password are not provided", async () => {
224224 const result = await promise ( entity , "send" ) ;
225225 expect ( result . attrs . mechanism ) . toEqual ( "ANONYMOUS" ) ;
226226} ) ;
227+
228+ test ( "fail if server sends a challenge during FAST login" , async ( ) => {
229+ const mech = "HT-SHA-256-NONE" ;
230+
231+ function onAuthenticate ( authenticate , mechanisms , fast ) {
232+ expect ( mechanisms ) . toEqual ( [ ] ) ;
233+ expect ( fast . mechanism ) . toEqual ( mech ) ;
234+ return authenticate (
235+ {
236+ token : {
237+ token : "hai" ,
238+ mechanism : fast . mechanism ,
239+ } ,
240+ } ,
241+ null ,
242+ userAgent ,
243+ ) ;
244+ }
245+
246+ const { entity } = mockClient ( { credentials : onAuthenticate } ) ;
247+
248+ entity . mockInput (
249+ < features xmlns = "http://etherx.jabber.org/streams" >
250+ < authentication xmlns = "urn:xmpp:sasl:2" >
251+ < inline >
252+ < fast xmlns = "urn:xmpp:fast:0" >
253+ < mechanism > { mech } </ mechanism >
254+ </ fast >
255+ </ inline >
256+ </ authentication >
257+ </ features > ,
258+ ) ;
259+
260+ expect ( await promise ( entity , "send" ) ) . toEqual (
261+ < authenticate xmlns = "urn:xmpp:sasl:2" mechanism = { mech } >
262+ < initial-response >
263+ bnVsbACNMNimsTBnxS04m8x7wgKjBHdDUL/nXPU4J4vqxqjBIg==
264+ </ initial-response >
265+ { userAgent }
266+ < fast xmlns = "urn:xmpp:fast:0" />
267+ </ authenticate > ,
268+ ) ;
269+
270+ entity . mockInput (
271+ < challenge xmlns = "urn:xmpp:sasl:2" >
272+ aGVyZXNhYnVuY2hvZmJhZGNoYWxsZW5nZWRhdGEK
273+ </ challenge > ,
274+ ) ;
275+
276+ const error = await promise ( entity , "error" ) ;
277+ expect ( error instanceof Error ) . toBe ( true ) ;
278+ expect ( error . message ) . toBe ( "HT-SHA-256-NONE does not support SASL challenges" ) ;
279+ } ) ;
0 commit comments