1
0
Fork 0
mirror of synced 2024-09-30 17:18:14 +13:00

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
.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

View file

@ -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")

View file

@ -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,