Fixes post merge.

This commit is contained in:
mike12345567 2022-11-16 18:28:45 +00:00
parent cdc25d7032
commit f5760b6601
3 changed files with 18 additions and 15 deletions

View File

@ -1,6 +1,6 @@
import { doInTenant, getTenantIDFromCtx } from "../tenancy"
import { buildMatcherRegex, matches } from "./matchers"
import { Headers } from "../constants"
import { Header } from "../constants"
import {
BBContext,
EndpointMatcher,
@ -29,7 +29,7 @@ const tenancy = (
}
const tenantId = getTenantIDFromCtx(ctx, tenantOpts)
ctx.set(Headers.TENANT_ID, tenantId as string)
ctx.set(Header.TENANT_ID, tenantId as string)
return doInTenant(tenantId, next)
}
}

View File

@ -1,7 +1,10 @@
import { doWithDB } from "../db"
import { queryPlatformView } from "../db/views"
import { StaticDatabases, ViewName } from "../db/constants"
import { getGlobalDBName } from "../db/tenancy"
import {
doWithDB,
queryPlatformView,
StaticDatabases,
getGlobalDBName,
ViewName,
} from "../db"
import {
DEFAULT_TENANT_ID,
getTenantId,
@ -15,7 +18,7 @@ import {
TenantResolutionStrategy,
GetTenantIdOptions,
} from "@budibase/types"
import { Headers } from "../constants"
import { Header } from "../constants"
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name
@ -200,7 +203,7 @@ export const getTenantIDFromCtx = (
// header
if (isAllowed(TenantResolutionStrategy.HEADER)) {
const headerTenantId = ctx.request.headers[Headers.TENANT_ID]
const headerTenantId = ctx.request.headers[Header.TENANT_ID]
if (headerTenantId) {
return headerTenantId as string
}

View File

@ -20,18 +20,18 @@ describe("tenancy middleware", () => {
const user = await config.createTenant()
await config.createSession(user)
const res = await config.api.self.getSelf(user)
expect(res.headers[constants.Headers.TENANT_ID]).toBe(user.tenantId)
expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId)
})
it("should get tenant id from header", async () => {
const tenantId = structures.uuid()
const headers = {
[constants.Headers.TENANT_ID]: tenantId,
[constants.Header.TENANT_ID]: tenantId,
}
const res = await config.request
.get(`/api/global/configs/checklist`)
.set(headers)
expect(res.headers[constants.Headers.TENANT_ID]).toBe(tenantId)
expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
})
it("should get tenant id from query param", async () => {
@ -39,7 +39,7 @@ describe("tenancy middleware", () => {
const res = await config.request.get(
`/api/global/configs/checklist?tenantId=${tenantId}`
)
expect(res.headers[constants.Headers.TENANT_ID]).toBe(tenantId)
expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
})
it("should get tenant id from subdomain", async () => {
@ -50,7 +50,7 @@ describe("tenancy middleware", () => {
const res = await config.request
.get(`/api/global/configs/checklist`)
.set(headers)
expect(res.headers[constants.Headers.TENANT_ID]).toBe(tenantId)
expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
})
it("should get tenant id from path variable", async () => {
@ -61,13 +61,13 @@ describe("tenancy middleware", () => {
username: user.email,
password: user.password,
})
expect(res.headers[constants.Headers.TENANT_ID]).toBe(user.tenantId)
expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId)
})
it("should throw when no tenant id is found", async () => {
const res = await config.request.get(`/api/global/configs/checklist`)
expect(res.status).toBe(403)
expect(res.text).toBe("Tenant id not set")
expect(res.headers[constants.Headers.TENANT_ID]).toBe(undefined)
expect(res.headers[constants.Header.TENANT_ID]).toBe(undefined)
})
})