client - should recognise new cookie format

This commit is contained in:
Michael Shanks 2020-06-19 07:04:55 +01:00
parent 2436ea525d
commit bd927564b2
3 changed files with 7 additions and 5 deletions

View File

@ -2,8 +2,10 @@ export const getAppId = cookie => {
const base64Token = cookie const base64Token = cookie
.split(";") .split(";")
.find(c => c.trim().startsWith("budibase:token")) .find(c => c.trim().startsWith("budibase:token"))
.split("=")[1] .substring(lengthOfKey)
const user = JSON.parse(atob(base64Token.split(".")[1])) const user = JSON.parse(atob(base64Token.split(".")[1]))
return user.appId return user.appId
} }
const lengthOfKey = "budibase:token=".length

View File

@ -18,7 +18,7 @@ describe("screenRouting", () => {
it("should load correct screen, for initial URL, when appRootPath is something", async () => { it("should load correct screen, for initial URL, when appRootPath is something", async () => {
const { page, screens } = pageWith3Screens() 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] const rootDiv = dom.window.document.body.children[0]
expect(rootDiv.children.length).toBe(1) expect(rootDiv.children.length).toBe(1)
@ -50,8 +50,8 @@ describe("screenRouting", () => {
const { dom, app } = await load( const { dom, app } = await load(
page, page,
screens, screens,
"/testApp/screen2", "/TEST_APP_ID/screen2",
"/testApp" "127.0.0.1"
) )
app.routeTo()("/screen3") app.routeTo()("/screen3")

View File

@ -7,7 +7,7 @@ export const load = async (page, screens, url, host = "test.com") => {
const fullUrl = `http://${host}${url}` const fullUrl = `http://${host}${url}`
const cookieJar = new jsdom.CookieJar() const cookieJar = new jsdom.CookieJar()
const cookie = btoa('{}{"appId":"TEST_APP_ID"}signature') const cookie = `${btoa("{}")}.${btoa('{"appId":"TEST_APP_ID"}')}.signature`
cookieJar.setCookie( cookieJar.setCookie(
`budibase:token=${cookie};domain=${host};path=/`, `budibase:token=${cookie};domain=${host};path=/`,
fullUrl, fullUrl,