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