Fixing tests, updating to typescript.
This commit is contained in:
parent
c33f331904
commit
f1fa0a3a6f
|
@ -4,9 +4,6 @@ import { basicTable } from "../../../../tests/utilities/structures"
|
|||
import { Table, User } from "@budibase/types"
|
||||
import { PublicAPIRequest } from "./Request"
|
||||
|
||||
const BROWSER_USER_AGENT =
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
|
||||
|
||||
describe("check public API security", () => {
|
||||
const config = setup.getConfig()
|
||||
let builderRequest: PublicAPIRequest,
|
||||
|
@ -58,7 +55,7 @@ describe("check public API security", () => {
|
|||
await config.withHeaders(
|
||||
{
|
||||
...headers,
|
||||
"User-Agent": BROWSER_USER_AGENT,
|
||||
"User-Agent": config.browserUserAgent(),
|
||||
},
|
||||
async () => {
|
||||
await config.api.row.search(
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
const setup = require("./utilities")
|
||||
const { basicScreen, powerScreen } = setup.structures
|
||||
const { checkBuilderEndpoint, runInProd } = require("./utilities/TestFunctions")
|
||||
const { roles } = require("@budibase/backend-core")
|
||||
const { BUILTIN_ROLE_IDS } = roles
|
||||
import * as setup from "./utilities"
|
||||
import { checkBuilderEndpoint, runInProd } from "./utilities/TestFunctions"
|
||||
import { roles } from "@budibase/backend-core"
|
||||
import { Screen } from "@budibase/types"
|
||||
|
||||
const { BUILTIN_ROLE_IDS } = roles
|
||||
const { basicScreen, powerScreen } = setup.structures
|
||||
const route = "/test"
|
||||
|
||||
// there are checks which are disabled in test env,
|
||||
|
@ -12,7 +13,7 @@ const route = "/test"
|
|||
describe("/routing", () => {
|
||||
let request = setup.getRequest()
|
||||
let config = setup.getConfig()
|
||||
let basic, power
|
||||
let basic: Screen, power: Screen
|
||||
|
||||
afterAll(setup.afterAll)
|
||||
|
||||
|
@ -25,26 +26,40 @@ describe("/routing", () => {
|
|||
|
||||
describe("fetch", () => {
|
||||
it("prevents a public user from accessing development app", async () => {
|
||||
await runInProd(() => {
|
||||
return request
|
||||
.get(`/api/routing/client`)
|
||||
.set(config.publicHeaders({ prodApp: false }))
|
||||
.expect(302)
|
||||
})
|
||||
await config.withHeaders(
|
||||
{
|
||||
"User-Agent": config.browserUserAgent(),
|
||||
},
|
||||
async () => {
|
||||
await runInProd(() => {
|
||||
return request
|
||||
.get(`/api/routing/client`)
|
||||
.set(config.publicHeaders({ prodApp: false }))
|
||||
.expect(302)
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("prevents a non builder from accessing development app", async () => {
|
||||
await runInProd(async () => {
|
||||
return request
|
||||
.get(`/api/routing/client`)
|
||||
.set(
|
||||
await config.roleHeaders({
|
||||
roleId: BUILTIN_ROLE_IDS.BASIC,
|
||||
prodApp: false,
|
||||
})
|
||||
)
|
||||
.expect(302)
|
||||
})
|
||||
await config.withHeaders(
|
||||
{
|
||||
"User-Agent": config.browserUserAgent(),
|
||||
},
|
||||
async () => {
|
||||
await runInProd(async () => {
|
||||
return request
|
||||
.get(`/api/routing/client`)
|
||||
.set(
|
||||
await config.roleHeaders({
|
||||
roleId: BUILTIN_ROLE_IDS.BASIC,
|
||||
prodApp: false,
|
||||
})
|
||||
)
|
||||
.expect(302)
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
it("returns the correct routing for basic user", async () => {
|
||||
const res = await request
|
|
@ -1,4 +1,6 @@
|
|||
require("../../db").init()
|
||||
import * as db from "../../db"
|
||||
|
||||
db.init()
|
||||
mockAuthWithNoCookie()
|
||||
mockWorker()
|
||||
mockUserGroups()
|
||||
|
@ -45,7 +47,7 @@ function mockAuthWithNoCookie() {
|
|||
},
|
||||
cache: {
|
||||
user: {
|
||||
getUser: async id => {
|
||||
getUser: async () => {
|
||||
return {
|
||||
_id: "us_uuid1",
|
||||
}
|
||||
|
@ -82,7 +84,7 @@ function mockAuthWithCookie() {
|
|||
},
|
||||
cache: {
|
||||
user: {
|
||||
getUser: async id => {
|
||||
getUser: async () => {
|
||||
return {
|
||||
_id: "us_uuid1",
|
||||
}
|
||||
|
@ -94,6 +96,10 @@ function mockAuthWithCookie() {
|
|||
}
|
||||
|
||||
class TestConfiguration {
|
||||
next: jest.MockedFunction<any>
|
||||
throw: jest.MockedFunction<any>
|
||||
ctx: any
|
||||
|
||||
constructor() {
|
||||
this.next = jest.fn()
|
||||
this.throw = jest.fn()
|
||||
|
@ -130,7 +136,7 @@ class TestConfiguration {
|
|||
}
|
||||
|
||||
describe("Current app middleware", () => {
|
||||
let config
|
||||
let config: TestConfiguration
|
||||
|
||||
beforeEach(() => {
|
||||
config = new TestConfiguration()
|
||||
|
@ -192,7 +198,7 @@ describe("Current app middleware", () => {
|
|||
},
|
||||
cache: {
|
||||
user: {
|
||||
getUser: async id => {
|
||||
getUser: async () => {
|
||||
return {
|
||||
_id: "us_uuid1",
|
||||
}
|
|
@ -423,6 +423,7 @@ export default class TestConfiguration {
|
|||
Accept: "application/json",
|
||||
Cookie: [`${constants.Cookie.Auth}=${authToken}`],
|
||||
[constants.Header.APP_ID]: appId,
|
||||
...this.temporaryHeaders,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -527,6 +528,10 @@ export default class TestConfiguration {
|
|||
return this.login({ userId: email, roleId, builder, prodApp })
|
||||
}
|
||||
|
||||
browserUserAgent() {
|
||||
return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
|
||||
}
|
||||
|
||||
// TENANCY
|
||||
|
||||
tenantHost() {
|
||||
|
|
Loading…
Reference in New Issue