From 2e8f725b94f45620482eac4ae3e477bbd970f378 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Mon, 6 Jan 2025 23:32:20 +0100 Subject: [PATCH] f --- packages/client-core/src/fast/fast.js | 4 +-- .../client-core/src/fast/isTokenValid.test.js | 32 ++++++++----------- packages/sasl2/test.js | 3 -- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/client-core/src/fast/fast.js b/packages/client-core/src/fast/fast.js index 74586b5d..5af90be5 100644 --- a/packages/client-core/src/fast/fast.js +++ b/packages/client-core/src/fast/fast.js @@ -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; } @@ -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; diff --git a/packages/client-core/src/fast/isTokenValid.test.js b/packages/client-core/src/fast/isTokenValid.test.js index 4448d143..dc20d811 100644 --- a/packages/client-core/src/fast/isTokenValid.test.js +++ b/packages/client-core/src/fast/isTokenValid.test.js @@ -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"], + ), ); }); diff --git a/packages/sasl2/test.js b/packages/sasl2/test.js index 5c733a39..07c4ce80 100644 --- a/packages/sasl2/test.js +++ b/packages/sasl2/test.js @@ -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"; @@ -115,7 +113,6 @@ test("with FAST token only", async () => { { token: { token: "hai", - expiry: datetime(new Date()), mechanism: fast.mechanism, }, },