From dcd00a3afe9c405cd9ad07bf625d96164fe99215 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Thu, 21 Dec 2023 15:27:27 -0600 Subject: [PATCH] fix: Should ignore SEAM_API_KEY with fromPersonalAccessToken and fromConsoleSessionToken --- src/lib/seam/connect/parse-options.ts | 6 ++++ test/seam/connect/env.test.ts | 48 +++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/lib/seam/connect/parse-options.ts b/src/lib/seam/connect/parse-options.ts index 286808de..d88c468f 100644 --- a/src/lib/seam/connect/parse-options.ts +++ b/src/lib/seam/connect/parse-options.ts @@ -87,6 +87,12 @@ const getApiKeyFromEnv = ( if ('clientSessionToken' in options && options.clientSessionToken != null) { return null } + if ('consoleSessionToken' in options && options.consoleSessionToken != null) { + return null + } + if ('personalAccessToken' in options && options.personalAccessToken != null) { + return null + } return globalThis.process?.env?.SEAM_API_KEY } diff --git a/test/seam/connect/env.test.ts b/test/seam/connect/env.test.ts index 34b6f1f8..0609cfa7 100644 --- a/test/seam/connect/env.test.ts +++ b/test/seam/connect/env.test.ts @@ -152,7 +152,7 @@ test.serial( 'SeamHttp: SEAM_API_KEY environment variable is ignored with fromClientSessionToken', async (t) => { const { seed, endpoint } = await getTestServer(t) - env.SEAM_API_KEY = 'some-invalid-api-key-4' + env.SEAM_API_KEY = seed.seam_apikey1_token const seam = SeamHttp.fromClientSessionToken(seed.seam_cst1_token, { endpoint, }) @@ -168,7 +168,7 @@ test.serial( 'SeamHttp: SEAM_API_KEY environment variable is ignored with fromPublishableKey', async (t) => { const { seed, endpoint } = await getTestServer(t) - env.SEAM_API_KEY = 'some-invalid-api-key-5' + env.SEAM_API_KEY = seed.seam_apikey1_token const seam = await SeamHttp.fromPublishableKey( seed.seam_pk1_token, seed.john_user_identifier_key, @@ -184,6 +184,50 @@ test.serial( }, ) +// UPSTREAM: Fake does not support JWT. +// https://github.com/seamapi/fake-seam-connect/issues/124 +test.serial.failing( + 'SeamHttp: SEAM_API_KEY environment variable is ignored with fromConsoleSessionToken', + async (t) => { + const { seed, endpoint } = await getTestServer(t) + env.SEAM_API_KEY = seed.seam_apikey1_token + const seam = SeamHttp.fromConsoleSessionToken( + 'ey_TODO', + seed.seed_workspace_1, + { + endpoint, + }, + ) + const device = await seam.devices.get({ + device_id: seed.august_device_1, + }) + t.is(device.workspace_id, seed.seed_workspace_1) + t.is(device.device_id, seed.august_device_1) + }, +) + +// UPSTREAM: Fake does not support personal access token. +// https://github.com/seamapi/fake-seam-connect/issues/126 +test.serial.failing( + 'SeamHttp: SEAM_API_KEY environment variable is ignored with personalAccessToken', + async (t) => { + const { seed, endpoint } = await getTestServer(t) + env.SEAM_API_KEY = seed.seam_apikey1_token + const seam = SeamHttp.fromPersonalAccessToken( + 'seam_at_TODO', + seed.seed_workspace_1, + { + endpoint, + }, + ) + const device = await seam.devices.get({ + device_id: seed.august_device_1, + }) + t.is(device.workspace_id, seed.seed_workspace_1) + t.is(device.device_id, seed.august_device_1) + }, +) + test.serial( 'SeamHttp: SEAM_ENDPOINT environment variable is used with fromPublishableKey', async (t) => {