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 ea42901 commit 2e8f725
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/client-core/src/fast/fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function fast({ sasl2 }, { saveToken, fetchToken } = {}) {
streamFeatures,
features,
}) {
if (isTokenValid({ token, mechanisms: fast.mechanisms })) {
if (!isTokenValid(token, fast.mechanisms)) {
return false;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ export default function fast({ sasl2 }, { saveToken, fetchToken } = {}) {
return fast;
}

export function isTokenValid({ token, mechanisms }) {
export function isTokenValid(token, mechanisms) {
// Avoid an error round trip if the server does not support the token mechanism anymore
if (!mechanisms.includes(token.mechanism)) {
return false;
Expand Down
32 changes: 13 additions & 19 deletions packages/client-core/src/fast/isTokenValid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,42 @@ yesterday.setDate(yesterday.getDate() - 1);

it("returns false if the token.mechanism is not available", async () => {
expect(
isTokenValid({
mechanisms: ["foo"],
token: {
isTokenValid(
{
expires: datetime(tomorrow),
mechanism: "bar",
},
}),
["foo"],
),
);
});

it("returns true if the token.mechanism is available", async () => {
expect(
isTokenValid({
mechanisms: ["foo"],
token: {
expires: datetime(tomorrow),
mechanism: "foo",
},
}),
isTokenValid({ expires: datetime(tomorrow), mechanism: "foo" }, ["foo"]),
);
});

it("returns false if the token is expired", async () => {
expect(
isTokenValid({
mechanisms: ["foo"],
token: {
isTokenValid(
{
expires: datetime(yesterday),
mechanism: "foo",
},
}),
["foo"],
),
);
});

it("returns true if the token is not expired", async () => {
expect(
isTokenValid({
mechanisms: ["foo"],
token: {
isTokenValid(
{
expires: datetime(tomorrow),
mechanism: "foo",
},
}),
["foo"],
),
);
});
3 changes: 0 additions & 3 deletions packages/sasl2/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
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 @@ -115,7 +113,6 @@ test("with FAST token only", async () => {
{
token: {
token: "hai",
expiry: datetime(new Date()),
mechanism: fast.mechanism,
},
},
Expand Down

0 comments on commit 2e8f725

Please sign in to comment.