Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Jan 6, 2025
1 parent 33b77a7 commit ea42901
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/sasl2/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { mockClient, promise } from "@xmpp/test";
// eslint-disable-next-line n/no-extraneous-import
import { datetime } from "@xmpp/time";

const username = "foo";
const password = "bar";
Expand Down Expand Up @@ -102,12 +104,24 @@ test("with function credentials", async () => {
expect(entity.jid.toString()).toBe(jid);
});

test("with FAST token", async () => {
// https://github.com/xmppjs/xmpp.js/pull/1045#discussion_r1904611099
test("with FAST token only", async () => {
const mech = "HT-SHA-256-NONE";

function onAuthenticate(authenticate, mechanisms, fast) {
expect(mechanisms).toEqual([]);
expect(fast.mechanism).toEqual(mech);
return authenticate({ token: { token: "hai", mechanism: fast.mechanism } }, null, userAgent);
return authenticate(
{
token: {
token: "hai",
expiry: datetime(new Date()),
mechanism: fast.mechanism,
},
},
null,
userAgent,
);
}

const { entity } = mockClient({ credentials: onAuthenticate });
Expand All @@ -126,7 +140,9 @@ test("with FAST token", async () => {

expect(await promise(entity, "send")).toEqual(
<authenticate xmlns="urn:xmpp:sasl:2" mechanism={mech}>
<initial-response>bnVsbACNMNimsTBnxS04m8x7wgKjBHdDUL/nXPU4J4vqxqjBIg==</initial-response>
<initial-response>
bnVsbACNMNimsTBnxS04m8x7wgKjBHdDUL/nXPU4J4vqxqjBIg==
</initial-response>
{userAgent}
<fast xmlns="urn:xmpp:fast:0" />
</authenticate>,
Expand Down

0 comments on commit ea42901

Please sign in to comment.