Fixes post merge.
This commit is contained in:
parent
0357d1c8e4
commit
242a529b2e
|
@ -1,6 +1,6 @@
|
||||||
import { doInTenant, getTenantIDFromCtx } from "../tenancy"
|
import { doInTenant, getTenantIDFromCtx } from "../tenancy"
|
||||||
import { buildMatcherRegex, matches } from "./matchers"
|
import { buildMatcherRegex, matches } from "./matchers"
|
||||||
import { Headers } from "../constants"
|
import { Header } from "../constants"
|
||||||
import {
|
import {
|
||||||
BBContext,
|
BBContext,
|
||||||
EndpointMatcher,
|
EndpointMatcher,
|
||||||
|
@ -29,7 +29,7 @@ const tenancy = (
|
||||||
}
|
}
|
||||||
|
|
||||||
const tenantId = getTenantIDFromCtx(ctx, tenantOpts)
|
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)
|
return doInTenant(tenantId, next)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { doWithDB } from "../db"
|
import {
|
||||||
import { queryPlatformView } from "../db/views"
|
doWithDB,
|
||||||
import { StaticDatabases, ViewName } from "../db/constants"
|
queryPlatformView,
|
||||||
import { getGlobalDBName } from "../db/tenancy"
|
StaticDatabases,
|
||||||
|
getGlobalDBName,
|
||||||
|
ViewName,
|
||||||
|
} from "../db"
|
||||||
import {
|
import {
|
||||||
DEFAULT_TENANT_ID,
|
DEFAULT_TENANT_ID,
|
||||||
getTenantId,
|
getTenantId,
|
||||||
|
@ -15,7 +18,7 @@ import {
|
||||||
TenantResolutionStrategy,
|
TenantResolutionStrategy,
|
||||||
GetTenantIdOptions,
|
GetTenantIdOptions,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { Headers } from "../constants"
|
import { Header } from "../constants"
|
||||||
|
|
||||||
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
|
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
|
||||||
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name
|
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name
|
||||||
|
@ -200,7 +203,7 @@ export const getTenantIDFromCtx = (
|
||||||
|
|
||||||
// header
|
// header
|
||||||
if (isAllowed(TenantResolutionStrategy.HEADER)) {
|
if (isAllowed(TenantResolutionStrategy.HEADER)) {
|
||||||
const headerTenantId = ctx.request.headers[Headers.TENANT_ID]
|
const headerTenantId = ctx.request.headers[Header.TENANT_ID]
|
||||||
if (headerTenantId) {
|
if (headerTenantId) {
|
||||||
return headerTenantId as string
|
return headerTenantId as string
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,18 +20,18 @@ describe("tenancy middleware", () => {
|
||||||
const user = await config.createTenant()
|
const user = await config.createTenant()
|
||||||
await config.createSession(user)
|
await config.createSession(user)
|
||||||
const res = await config.api.self.getSelf(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 () => {
|
it("should get tenant id from header", async () => {
|
||||||
const tenantId = structures.uuid()
|
const tenantId = structures.uuid()
|
||||||
const headers = {
|
const headers = {
|
||||||
[constants.Headers.TENANT_ID]: tenantId,
|
[constants.Header.TENANT_ID]: tenantId,
|
||||||
}
|
}
|
||||||
const res = await config.request
|
const res = await config.request
|
||||||
.get(`/api/global/configs/checklist`)
|
.get(`/api/global/configs/checklist`)
|
||||||
.set(headers)
|
.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 () => {
|
it("should get tenant id from query param", async () => {
|
||||||
|
@ -39,7 +39,7 @@ describe("tenancy middleware", () => {
|
||||||
const res = await config.request.get(
|
const res = await config.request.get(
|
||||||
`/api/global/configs/checklist?tenantId=${tenantId}`
|
`/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 () => {
|
it("should get tenant id from subdomain", async () => {
|
||||||
|
@ -50,7 +50,7 @@ describe("tenancy middleware", () => {
|
||||||
const res = await config.request
|
const res = await config.request
|
||||||
.get(`/api/global/configs/checklist`)
|
.get(`/api/global/configs/checklist`)
|
||||||
.set(headers)
|
.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 () => {
|
it("should get tenant id from path variable", async () => {
|
||||||
|
@ -61,13 +61,13 @@ describe("tenancy middleware", () => {
|
||||||
username: user.email,
|
username: user.email,
|
||||||
password: user.password,
|
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 () => {
|
it("should throw when no tenant id is found", async () => {
|
||||||
const res = await config.request.get(`/api/global/configs/checklist`)
|
const res = await config.request.get(`/api/global/configs/checklist`)
|
||||||
expect(res.status).toBe(403)
|
expect(res.status).toBe(403)
|
||||||
expect(res.text).toBe("Tenant id not set")
|
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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue