From bd927564b28f9484d249a53c66314b4e2178b350 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Fri, 19 Jun 2020 07:04:55 +0100 Subject: [PATCH] client - should recognise new cookie format --- packages/client/src/render/getAppId.js | 4 +++- packages/client/tests/screenRouting.spec.js | 6 +++--- packages/client/tests/testAppDef.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/client/src/render/getAppId.js b/packages/client/src/render/getAppId.js index 75753e381d..8ac2dbc79b 100644 --- a/packages/client/src/render/getAppId.js +++ b/packages/client/src/render/getAppId.js @@ -2,8 +2,10 @@ export const getAppId = cookie => { const base64Token = cookie .split(";") .find(c => c.trim().startsWith("budibase:token")) - .split("=")[1] + .substring(lengthOfKey) const user = JSON.parse(atob(base64Token.split(".")[1])) return user.appId } + +const lengthOfKey = "budibase:token=".length diff --git a/packages/client/tests/screenRouting.spec.js b/packages/client/tests/screenRouting.spec.js index d0b2c1b4d5..3e4818961d 100644 --- a/packages/client/tests/screenRouting.spec.js +++ b/packages/client/tests/screenRouting.spec.js @@ -18,7 +18,7 @@ describe("screenRouting", () => { it("should load correct screen, for initial URL, when appRootPath is something", async () => { const { page, screens } = pageWith3Screens() - const { dom } = await load(page, screens, "/TEST_APP_ID/screen2", "localhost") + const { dom } = await load(page, screens, "/TEST_APP_ID/screen2", "127.0.0.1") const rootDiv = dom.window.document.body.children[0] expect(rootDiv.children.length).toBe(1) @@ -50,8 +50,8 @@ describe("screenRouting", () => { const { dom, app } = await load( page, screens, - "/testApp/screen2", - "/testApp" + "/TEST_APP_ID/screen2", + "127.0.0.1" ) app.routeTo()("/screen3") diff --git a/packages/client/tests/testAppDef.js b/packages/client/tests/testAppDef.js index bafba601e9..76bb3784b0 100644 --- a/packages/client/tests/testAppDef.js +++ b/packages/client/tests/testAppDef.js @@ -7,7 +7,7 @@ export const load = async (page, screens, url, host = "test.com") => { const fullUrl = `http://${host}${url}` const cookieJar = new jsdom.CookieJar() - const cookie = btoa('{}{"appId":"TEST_APP_ID"}signature') + const cookie = `${btoa("{}")}.${btoa('{"appId":"TEST_APP_ID"}')}.signature` cookieJar.setCookie( `budibase:token=${cookie};domain=${host};path=/`, fullUrl,