Updating server test cases with the header for appId.

This commit is contained in:
Michael Drury 2020-11-03 15:00:39 +00:00
parent 19bcecf9f3
commit 4f28bd9430
3 changed files with 17 additions and 8 deletions

View File

@ -1,3 +1,4 @@
export const getAppIdFromPath = () => {
return location.pathname.split("/")[1]
let appId = location.pathname.split("/")[1]
return appId.startsWith("app_") ? appId : undefined
}

View File

@ -27,15 +27,19 @@ exports.defaultHeaders = appId => {
const builderUser = {
userId: "BUILDER",
accessLevelId: BUILDER_LEVEL_ID,
appId,
}
const builderToken = jwt.sign(builderUser, env.JWT_SECRET)
return {
const headers = {
Accept: "application/json",
Cookie: [`budibase:builder=${builderToken}:local`],
Cookie: [`budibase:builder:local=${builderToken}`],
}
if (appId) {
headers["x-budibase-app-id"] = appId
}
return headers
}
exports.createTable = async (request, appId, table) => {
@ -209,7 +213,10 @@ const createUserWithPermissions = async (
const loginResult = await request
.post(`/api/authenticate`)
.set({ Cookie: `budibase:${appId}:local=${anonToken}` })
.set({
Cookie: `budibase:${appId}:local=${anonToken}`,
"x-budibase-app-id": appId,
})
.send({ username, password })
// returning necessary request headers

View File

@ -20,10 +20,11 @@ module.exports = async (ctx, next) => {
// do everything we can to make sure the appId is held correctly
// we hold it in state as a
let appId = getAppId(ctx)
if (appId) {
const cookieAppId = ctx.cookies.get(getCookieName("currentapp"))
if (appId && cookieAppId !== appId) {
setCookie(ctx, "currentapp", appId)
} else {
appId = ctx.cookies.get(getCookieName("currentapp"))
} else if (cookieAppId) {
appId = cookieAppId
}
const appToken = ctx.cookies.get(getCookieName(appId))