From d02c5220cbe740e26d5b7f7ef62a8c1893c1b882 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Fri, 27 Sep 2024 01:08:21 +0200 Subject: [PATCH] test: stability fixes --- test/helpers.js | 9 +++++++++ test/server/index.js | 29 ++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/test/helpers.js b/test/helpers.js index f45eacf34..47935672b 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -947,6 +947,15 @@ export async function isMFASupported() { return true; } +export async function isOauth2Supported() { + const features = await getFeatureFlags(); + if (!features.includes("oauth2")) { + return false; + } + + return true; +} + /** * For example setGeneralErrorToLocalStorage("EMAIL_PASSWORD", "EMAIL_PASSWORD_SIGN_UP", page) to * set for signUp in email password diff --git a/test/server/index.js b/test/server/index.js index f76e6c3a1..b8806b170 100644 --- a/test/server/index.js +++ b/test/server/index.js @@ -66,8 +66,14 @@ const MultiFactorAuth = require("supertokens-node/recipe/multifactorauth"); const TOTPRaw = require("supertokens-node/lib/build/recipe/totp/recipe").default; const TOTP = require("supertokens-node/recipe/totp"); -const OAuth2ProviderRaw = require("supertokens-node/lib/build/recipe/oauth2provider/recipe").default; -const OAuth2Provider = require("supertokens-node/recipe/oauth2provider"); +let OAuth2ProviderRaw = undefined; +let OAuth2Provider = undefined; +try { + OAuth2ProviderRaw = require("supertokens-node/lib/build/recipe/oauth2provider/recipe").default; + OAuth2Provider = require("supertokens-node/recipe/oauth2provider"); +} catch { + // OAuth2Provider is not supported by the tested version of the node SDK +} const OTPAuth = require("otpauth"); @@ -498,15 +504,20 @@ app.get("/test/featureFlags", (req, res) => { available.push("accountlinking"); available.push("mfa"); available.push("recipeConfig"); + available.push("oauth2"); res.send({ available, }); }); -app.post("/test/create-oauth2-client", async (req, res) => { - const { client } = await OAuth2Provider.createOAuth2Client(req.body); - res.send({ client }); +app.post("/test/create-oauth2-client", async (req, res, next) => { + try { + const { client } = await OAuth2Provider.createOAuth2Client(req.body); + res.send({ client }); + } catch (e) { + next(e); + } }); app.use(errorHandler()); @@ -552,7 +563,9 @@ function initST() { UserMetadataRaw.reset(); MultiFactorAuthRaw.reset(); TOTPRaw.reset(); - OAuth2ProviderRaw.reset(); + if (OAuth2ProviderRaw) { + OAuth2ProviderRaw.reset(); + } EmailVerificationRaw.reset(); EmailPasswordRaw.reset(); @@ -751,8 +764,10 @@ function initST() { }, }), ], - ["oauth2provider", OAuth2Provider.init()], ]; + if (OAuth2Provider) { + recipeList.push(["oauth2provider", OAuth2Provider.init()]); + } passwordlessConfig = { contactMethod: "EMAIL_OR_PHONE",