@budibase/worker 2.1.40-alpha.4 → 2.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +24 -14
- package/{src/tests/jestSetup.ts → scripts/jestSetup.js} +3 -12
- package/scripts/localdomain.js +7 -33
- package/src/api/controllers/global/auth.ts +43 -51
- package/src/api/controllers/global/{configs.ts → configs.js} +114 -119
- package/src/api/controllers/global/{email.ts → email.js} +5 -6
- package/src/api/controllers/global/roles.js +68 -0
- package/src/api/controllers/global/self.ts +2 -2
- package/src/api/controllers/global/users.ts +2 -4
- package/src/api/controllers/global/{workspaces.ts → workspaces.js} +18 -15
- package/src/api/controllers/system/{environment.ts → environment.js} +2 -3
- package/src/api/controllers/system/restore.ts +1 -1
- package/src/api/controllers/system/{status.ts → status.js} +3 -4
- package/src/api/controllers/system/tenants.ts +51 -8
- package/src/api/index.ts +8 -31
- package/src/api/routes/global/{auth.ts → auth.js} +48 -31
- package/src/api/routes/global/{configs.ts → configs.js} +23 -22
- package/src/api/routes/global/{email.ts → email.js} +10 -9
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/roles.js +12 -0
- package/src/api/routes/global/self.ts +2 -2
- package/src/api/routes/global/templates.ts +4 -4
- package/src/api/routes/global/tests/auth.spec.ts +64 -134
- package/src/api/routes/global/tests/configs.spec.ts +35 -34
- package/src/api/routes/global/tests/email.spec.ts +3 -4
- package/src/api/routes/global/tests/realEmail.spec.ts +3 -2
- package/src/api/routes/global/tests/self.spec.ts +4 -3
- package/src/api/routes/global/tests/users.spec.ts +59 -51
- package/src/api/routes/global/{users.ts → users.js} +32 -26
- package/src/api/routes/global/{workspaces.ts → workspaces.js} +10 -9
- package/src/api/routes/index.ts +1 -2
- package/src/api/routes/system/accounts.ts +1 -1
- package/src/api/routes/system/environment.js +8 -0
- package/src/api/routes/system/migrations.ts +1 -1
- package/src/api/routes/system/restore.ts +1 -1
- package/src/api/routes/system/status.js +8 -0
- package/src/api/routes/system/tenants.js +12 -0
- package/src/api/routes/system/tests/accounts.spec.ts +6 -5
- package/src/api/routes/validation/users.ts +3 -3
- package/src/constants/{index.ts → index.js} +64 -57
- package/src/constants/templates/{index.ts → index.js} +19 -23
- package/src/db/index.js +11 -0
- package/src/environment.ts +7 -9
- package/src/index.ts +16 -15
- package/src/middleware/{cloudRestricted.ts → cloudRestricted.js} +4 -5
- package/src/tests/TestConfiguration.ts +50 -99
- package/src/tests/api/accounts.ts +8 -5
- package/src/tests/api/auth.ts +6 -3
- package/src/tests/api/configs.ts +8 -15
- package/src/tests/api/email.ts +6 -3
- package/src/tests/api/index.ts +0 -15
- package/src/tests/api/self.ts +6 -11
- package/src/tests/api/users.ts +8 -40
- package/src/tests/controllers.js +7 -0
- package/src/tests/index.ts +1 -5
- package/src/tests/structures/accounts.ts +24 -0
- package/src/tests/structures/{configs.ts → configs.js} +11 -11
- package/src/tests/structures/index.ts +3 -5
- package/src/tests/structures/users.ts +0 -1
- package/src/utilities/appService.js +33 -0
- package/src/utilities/{email.ts → email.js} +45 -78
- package/src/utilities/fileSystem.js +5 -0
- package/src/utilities/{index.ts → index.js} +1 -1
- package/src/utilities/{redis.ts → redis.js} +24 -29
- package/src/utilities/templates.js +49 -0
- package/src/utilities/users.js +17 -0
- package/tsconfig.build.json +3 -2
- package/tsconfig.json +1 -3
- package/__mocks__/aws-sdk.ts +0 -15
- package/__mocks__/oauth.ts +0 -57
- package/coverage/clover.xml +0 -2153
- package/coverage/coverage-final.json +0 -78
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -431
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +0 -925
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +0 -1405
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +0 -196
- package/coverage/lcov-report/src/api/controllers/global/index.html +0 -236
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +0 -187
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +0 -283
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +0 -577
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +0 -316
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +0 -796
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +0 -244
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +0 -148
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +0 -124
- package/coverage/lcov-report/src/api/controllers/system/index.html +0 -191
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +0 -124
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +0 -124
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +0 -133
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +0 -154
- package/coverage/lcov-report/src/api/index.html +0 -116
- package/coverage/lcov-report/src/api/index.ts.html +0 -583
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +0 -349
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +0 -457
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +0 -193
- package/coverage/lcov-report/src/api/routes/global/index.html +0 -236
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +0 -124
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +0 -133
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +0 -139
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +0 -196
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +0 -409
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +0 -196
- package/coverage/lcov-report/src/api/routes/index.html +0 -116
- package/coverage/lcov-report/src/api/routes/index.ts.html +0 -196
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +0 -142
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +0 -109
- package/coverage/lcov-report/src/api/routes/system/index.html +0 -191
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +0 -142
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +0 -109
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +0 -109
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +0 -124
- package/coverage/lcov-report/src/api/routes/validation/index.html +0 -131
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +0 -88
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +0 -235
- package/coverage/lcov-report/src/constants/index.html +0 -116
- package/coverage/lcov-report/src/constants/index.ts.html +0 -613
- package/coverage/lcov-report/src/constants/templates/index.html +0 -116
- package/coverage/lcov-report/src/constants/templates/index.ts.html +0 -316
- package/coverage/lcov-report/src/db/index.html +0 -116
- package/coverage/lcov-report/src/db/index.ts.html +0 -115
- package/coverage/lcov-report/src/environment.ts.html +0 -373
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/index.ts.html +0 -394
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +0 -139
- package/coverage/lcov-report/src/middleware/index.html +0 -116
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +0 -145
- package/coverage/lcov-report/src/migrations/functions/index.html +0 -116
- package/coverage/lcov-report/src/migrations/index.html +0 -116
- package/coverage/lcov-report/src/migrations/index.ts.html +0 -271
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +0 -262
- package/coverage/lcov-report/src/sdk/accounts/index.html +0 -131
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +0 -88
- package/coverage/lcov-report/src/sdk/index.html +0 -116
- package/coverage/lcov-report/src/sdk/index.ts.html +0 -106
- package/coverage/lcov-report/src/sdk/users/events.ts.html +0 -577
- package/coverage/lcov-report/src/sdk/users/index.html +0 -146
- package/coverage/lcov-report/src/sdk/users/index.ts.html +0 -88
- package/coverage/lcov-report/src/sdk/users/users.ts.html +0 -1903
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +0 -1051
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +0 -160
- package/coverage/lcov-report/src/tests/api/auth.ts.html +0 -220
- package/coverage/lcov-report/src/tests/api/base.ts.html +0 -133
- package/coverage/lcov-report/src/tests/api/configs.ts.html +0 -226
- package/coverage/lcov-report/src/tests/api/email.ts.html +0 -148
- package/coverage/lcov-report/src/tests/api/environment.ts.html +0 -130
- package/coverage/lcov-report/src/tests/api/index.html +0 -296
- package/coverage/lcov-report/src/tests/api/index.ts.html +0 -205
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +0 -151
- package/coverage/lcov-report/src/tests/api/restore.ts.html +0 -127
- package/coverage/lcov-report/src/tests/api/self.ts.html +0 -163
- package/coverage/lcov-report/src/tests/api/status.ts.html +0 -121
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +0 -130
- package/coverage/lcov-report/src/tests/api/users.ts.html +0 -511
- package/coverage/lcov-report/src/tests/controllers.ts.html +0 -100
- package/coverage/lcov-report/src/tests/index.html +0 -146
- package/coverage/lcov-report/src/tests/index.ts.html +0 -139
- package/coverage/lcov-report/src/tests/mocks/email.js.html +0 -115
- package/coverage/lcov-report/src/tests/mocks/index.html +0 -131
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +0 -106
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +0 -313
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +0 -118
- package/coverage/lcov-report/src/tests/structures/index.html +0 -161
- package/coverage/lcov-report/src/tests/structures/index.ts.html +0 -151
- package/coverage/lcov-report/src/tests/structures/users.ts.html +0 -196
- package/coverage/lcov-report/src/utilities/appService.ts.html +0 -181
- package/coverage/lcov-report/src/utilities/email.ts.html +0 -850
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +0 -100
- package/coverage/lcov-report/src/utilities/index.html +0 -206
- package/coverage/lcov-report/src/utilities/index.ts.html +0 -112
- package/coverage/lcov-report/src/utilities/redis.ts.html +0 -424
- package/coverage/lcov-report/src/utilities/templates.ts.html +0 -232
- package/coverage/lcov-report/src/utilities/users.ts.html +0 -133
- package/coverage/lcov.info +0 -3958
- package/jest.config.ts +0 -29
- package/src/api/controllers/global/roles.ts +0 -66
- package/src/api/routes/global/roles.ts +0 -16
- package/src/api/routes/global/tests/license.spec.ts +0 -31
- package/src/api/routes/global/tests/roles.spec.ts +0 -27
- package/src/api/routes/global/tests/templates.spec.ts +0 -35
- package/src/api/routes/global/tests/workspaces.spec.ts +0 -29
- package/src/api/routes/system/environment.ts +0 -8
- package/src/api/routes/system/status.ts +0 -8
- package/src/api/routes/system/tenants.ts +0 -13
- package/src/api/routes/system/tests/environment.spec.ts +0 -29
- package/src/api/routes/system/tests/migrations.spec.ts +0 -63
- package/src/api/routes/system/tests/restore.spec.ts +0 -36
- package/src/api/routes/system/tests/status.spec.ts +0 -48
- package/src/api/routes/system/tests/tenants.spec.ts +0 -61
- package/src/db/index.ts +0 -10
- package/src/middleware/tests/tenancy.spec.ts +0 -73
- package/src/tests/api/base.ts +0 -16
- package/src/tests/api/environment.ts +0 -15
- package/src/tests/api/migrations.ts +0 -22
- package/src/tests/api/restore.ts +0 -14
- package/src/tests/api/status.ts +0 -12
- package/src/tests/api/tenants.ts +0 -15
- package/src/tests/controllers.ts +0 -5
- package/src/utilities/appService.ts +0 -32
- package/src/utilities/fileSystem.ts +0 -5
- package/src/utilities/templates.ts +0 -49
- package/src/utilities/users.ts +0 -16
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
import { TestConfiguration, mocks } from "../../../../tests"
|
|
2
|
+
import { TestConfiguration, mocks, API } from "../../../../tests"
|
|
3
3
|
const sendMailMock = mocks.email.mock()
|
|
4
4
|
import { events } from "@budibase/backend-core"
|
|
5
5
|
|
|
6
|
-
const expectSetAuthCookie = (res: any) => {
|
|
7
|
-
expect(
|
|
8
|
-
res.get("Set-Cookie").find((c: string) => c.startsWith("budibase:auth"))
|
|
9
|
-
).toBeDefined()
|
|
10
|
-
}
|
|
11
|
-
|
|
12
6
|
describe("/api/global/auth", () => {
|
|
13
7
|
const config = new TestConfiguration()
|
|
8
|
+
const api = new API(config)
|
|
14
9
|
|
|
15
10
|
beforeAll(async () => {
|
|
16
11
|
await config.beforeAll()
|
|
@@ -24,155 +19,90 @@ describe("/api/global/auth", () => {
|
|
|
24
19
|
jest.clearAllMocks()
|
|
25
20
|
})
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
describe("POST /api/global/auth/logout", () => {
|
|
33
|
-
it("should logout", async () => {
|
|
34
|
-
await config.api.auth.logout()
|
|
35
|
-
expect(events.auth.logout).toBeCalledTimes(1)
|
|
36
|
-
|
|
37
|
-
// TODO: Verify sessions deleted
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe("POST /api/global/auth/:tenantId/reset", () => {
|
|
42
|
-
it("should generate password reset email", async () => {
|
|
43
|
-
const { res, code } = await config.api.auth.requestPasswordReset(
|
|
44
|
-
sendMailMock
|
|
45
|
-
)
|
|
46
|
-
const user = await config.getUser("test@test.com")
|
|
47
|
-
|
|
48
|
-
expect(res.body).toEqual({
|
|
49
|
-
message: "Please check your email for a reset link.",
|
|
50
|
-
})
|
|
51
|
-
expect(sendMailMock).toHaveBeenCalled()
|
|
52
|
-
|
|
53
|
-
expect(code).toBeDefined()
|
|
54
|
-
expect(events.user.passwordResetRequested).toBeCalledTimes(1)
|
|
55
|
-
expect(events.user.passwordResetRequested).toBeCalledWith(user)
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
describe("POST /api/global/auth/:tenantId/reset/update", () => {
|
|
60
|
-
it("should reset password", async () => {
|
|
61
|
-
const { code } = await config.api.auth.requestPasswordReset(
|
|
62
|
-
sendMailMock
|
|
63
|
-
)
|
|
64
|
-
const user = await config.getUser("test@test.com")
|
|
65
|
-
delete user.password
|
|
66
|
-
|
|
67
|
-
const res = await config.api.auth.updatePassword(code)
|
|
22
|
+
it("should logout", async () => {
|
|
23
|
+
await api.auth.logout()
|
|
24
|
+
expect(events.auth.logout).toBeCalledTimes(1)
|
|
25
|
+
})
|
|
68
26
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
27
|
+
it("should be able to generate password reset email", async () => {
|
|
28
|
+
const { res, code } = await api.auth.requestPasswordReset(sendMailMock)
|
|
29
|
+
const user = await config.getUser("test@test.com")
|
|
72
30
|
|
|
73
|
-
|
|
74
|
-
|
|
31
|
+
expect(res.body).toEqual({
|
|
32
|
+
message: "Please check your email for a reset link.",
|
|
75
33
|
})
|
|
76
|
-
|
|
34
|
+
expect(sendMailMock).toHaveBeenCalled()
|
|
77
35
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
describe("GET /api/global/auth/init", () => {})
|
|
36
|
+
expect(code).toBeDefined()
|
|
37
|
+
expect(events.user.passwordResetRequested).toBeCalledTimes(1)
|
|
38
|
+
expect(events.user.passwordResetRequested).toBeCalledWith(user)
|
|
82
39
|
})
|
|
83
40
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
describe("GET /api/global/auth/:tenantId/datasource/:provider/callback", () => {})
|
|
41
|
+
it("should allow resetting user password with code", async () => {
|
|
42
|
+
const { code } = await api.auth.requestPasswordReset(sendMailMock)
|
|
43
|
+
const user = await config.getUser("test@test.com")
|
|
44
|
+
delete user.password
|
|
90
45
|
|
|
91
|
-
|
|
46
|
+
const res = await api.auth.updatePassword(code)
|
|
92
47
|
|
|
93
|
-
|
|
48
|
+
expect(res.body).toEqual({ message: "password reset successfully." })
|
|
49
|
+
expect(events.user.passwordReset).toBeCalledTimes(1)
|
|
50
|
+
expect(events.user.passwordReset).toBeCalledWith(user)
|
|
94
51
|
})
|
|
95
52
|
|
|
96
|
-
describe("
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
describe("GET /api/global/auth/:tenantId/google", () => {})
|
|
100
|
-
|
|
101
|
-
describe("GET /api/global/auth/:tenantId/google/callback", () => {})
|
|
53
|
+
describe("oidc", () => {
|
|
54
|
+
const auth = require("@budibase/backend-core/auth")
|
|
102
55
|
|
|
103
|
-
|
|
56
|
+
const passportSpy = jest.spyOn(auth.passport, "authenticate")
|
|
57
|
+
let oidcConf
|
|
58
|
+
let chosenConfig: any
|
|
59
|
+
let configId: string
|
|
104
60
|
|
|
105
|
-
|
|
61
|
+
// mock the oidc strategy implementation and return value
|
|
62
|
+
let strategyFactory = jest.fn()
|
|
63
|
+
let mockStrategyReturn = jest.fn()
|
|
64
|
+
let mockStrategyConfig = jest.fn()
|
|
65
|
+
auth.oidc.fetchStrategyConfig = mockStrategyConfig
|
|
106
66
|
|
|
107
|
-
|
|
108
|
-
|
|
67
|
+
strategyFactory.mockReturnValue(mockStrategyReturn)
|
|
68
|
+
auth.oidc.strategyFactory = strategyFactory
|
|
109
69
|
|
|
110
|
-
describe("oidc", () => {
|
|
111
70
|
beforeEach(async () => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// for associated mocking inside passport
|
|
71
|
+
oidcConf = await config.saveOIDCConfig()
|
|
72
|
+
chosenConfig = oidcConf.config.configs[0]
|
|
73
|
+
configId = chosenConfig.uuid
|
|
74
|
+
mockStrategyConfig.mockReturnValue(chosenConfig)
|
|
117
75
|
})
|
|
118
76
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const chosenConfig = oidcConf.config.configs[0]
|
|
122
|
-
return chosenConfig.uuid
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const mockGetWellKnownConfig = () => {
|
|
126
|
-
mocks.fetch.mockReturnValue({
|
|
127
|
-
ok: true,
|
|
128
|
-
json: () => ({
|
|
129
|
-
issuer: "test",
|
|
130
|
-
authorization_endpoint: "http://localhost/auth",
|
|
131
|
-
token_endpoint: "http://localhost/token",
|
|
132
|
-
userinfo_endpoint: "http://localhost/userinfo",
|
|
133
|
-
}),
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// MULTI TENANT
|
|
138
|
-
describe("GET /api/global/auth/:tenantId/oidc/configs/:configId", () => {
|
|
139
|
-
it("redirects to auth provider", async () => {
|
|
140
|
-
const configId = await generateOidcConfig()
|
|
141
|
-
|
|
142
|
-
const res = await config.api.configs.getOIDCConfig(configId)
|
|
143
|
-
|
|
144
|
-
expect(res.status).toBe(302)
|
|
145
|
-
const location: string = res.get("location")
|
|
146
|
-
expect(
|
|
147
|
-
location.startsWith(
|
|
148
|
-
"http://localhost/auth?response_type=code&client_id=clientId&redirect_uri=http%3A%2F%2Flocalhost%3A10000%2Fapi%2Fglobal%2Fauth%2Fdefault%2Foidc%2Fcallback&scope=openid%20profile%20email%20offline_access"
|
|
149
|
-
)
|
|
150
|
-
).toBe(true)
|
|
151
|
-
})
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
expect(strategyFactory).toBeCalledWith(chosenConfig, expect.any(Function))
|
|
152
79
|
})
|
|
153
80
|
|
|
154
|
-
describe("
|
|
155
|
-
it("
|
|
156
|
-
|
|
157
|
-
const preAuthRes = await config.api.configs.getOIDCConfig(configId)
|
|
158
|
-
|
|
159
|
-
const res = await config.api.configs.OIDCCallback(configId, preAuthRes)
|
|
81
|
+
describe("oidc configs", () => {
|
|
82
|
+
it("should load strategy and delegate to passport", async () => {
|
|
83
|
+
await api.configs.getOIDCConfig(configId)
|
|
160
84
|
|
|
161
|
-
expect(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
expect(location).toBe("/")
|
|
166
|
-
expectSetAuthCookie(res)
|
|
85
|
+
expect(passportSpy).toBeCalledWith(mockStrategyReturn, {
|
|
86
|
+
scope: ["profile", "email", "offline_access"],
|
|
87
|
+
})
|
|
88
|
+
expect(passportSpy.mock.calls.length).toBe(1)
|
|
167
89
|
})
|
|
168
90
|
})
|
|
169
91
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
92
|
+
describe("oidc callback", () => {
|
|
93
|
+
it("should load strategy and delegate to passport", async () => {
|
|
94
|
+
await api.configs.OIDCCallback(configId)
|
|
95
|
+
|
|
96
|
+
expect(passportSpy).toBeCalledWith(
|
|
97
|
+
mockStrategyReturn,
|
|
98
|
+
{
|
|
99
|
+
successRedirect: "/",
|
|
100
|
+
failureRedirect: "/error",
|
|
101
|
+
},
|
|
102
|
+
expect.anything()
|
|
103
|
+
)
|
|
104
|
+
expect(passportSpy.mock.calls.length).toBe(1)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
177
107
|
})
|
|
178
108
|
})
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// mock the email system
|
|
2
2
|
jest.mock("nodemailer")
|
|
3
|
-
import { TestConfiguration, structures, mocks } from "../../../../tests"
|
|
3
|
+
import { TestConfiguration, structures, mocks, API } from "../../../../tests"
|
|
4
4
|
mocks.email.mock()
|
|
5
|
-
import {
|
|
5
|
+
import { Configs, events } from "@budibase/backend-core"
|
|
6
6
|
|
|
7
7
|
describe("configs", () => {
|
|
8
8
|
const config = new TestConfiguration()
|
|
9
|
+
const api = new API(config)
|
|
9
10
|
|
|
10
11
|
beforeAll(async () => {
|
|
11
12
|
await config.beforeAll()
|
|
@@ -27,7 +28,7 @@ describe("configs", () => {
|
|
|
27
28
|
_rev,
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const res = await
|
|
31
|
+
const res = await api.configs.saveConfig(data)
|
|
31
32
|
|
|
32
33
|
return {
|
|
33
34
|
...data,
|
|
@@ -49,20 +50,20 @@ describe("configs", () => {
|
|
|
49
50
|
it("should create activated google config", async () => {
|
|
50
51
|
await saveGoogleConfig()
|
|
51
52
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
52
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
53
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
|
|
53
54
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
54
55
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
55
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
56
|
-
await config.deleteConfig(
|
|
56
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Configs.GOOGLE)
|
|
57
|
+
await config.deleteConfig(Configs.GOOGLE)
|
|
57
58
|
})
|
|
58
59
|
|
|
59
60
|
it("should create deactivated google config", async () => {
|
|
60
61
|
await saveGoogleConfig({ activated: false })
|
|
61
62
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
62
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
63
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
|
|
63
64
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
64
65
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
65
|
-
await config.deleteConfig(
|
|
66
|
+
await config.deleteConfig(Configs.GOOGLE)
|
|
66
67
|
})
|
|
67
68
|
})
|
|
68
69
|
|
|
@@ -76,11 +77,11 @@ describe("configs", () => {
|
|
|
76
77
|
googleConf._rev
|
|
77
78
|
)
|
|
78
79
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
79
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
80
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
|
|
80
81
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
81
82
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
82
|
-
expect(events.auth.SSODeactivated).toBeCalledWith(
|
|
83
|
-
await config.deleteConfig(
|
|
83
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Configs.GOOGLE)
|
|
84
|
+
await config.deleteConfig(Configs.GOOGLE)
|
|
84
85
|
})
|
|
85
86
|
|
|
86
87
|
it("should update google config to activated", async () => {
|
|
@@ -92,11 +93,11 @@ describe("configs", () => {
|
|
|
92
93
|
googleConf._rev
|
|
93
94
|
)
|
|
94
95
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
95
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
96
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
|
|
96
97
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
97
98
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
98
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
99
|
-
await config.deleteConfig(
|
|
99
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Configs.GOOGLE)
|
|
100
|
+
await config.deleteConfig(Configs.GOOGLE)
|
|
100
101
|
})
|
|
101
102
|
})
|
|
102
103
|
})
|
|
@@ -115,20 +116,20 @@ describe("configs", () => {
|
|
|
115
116
|
it("should create activated OIDC config", async () => {
|
|
116
117
|
await saveOIDCConfig()
|
|
117
118
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
118
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
119
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
|
|
119
120
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
120
121
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
121
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
122
|
-
await config.deleteConfig(
|
|
122
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Configs.OIDC)
|
|
123
|
+
await config.deleteConfig(Configs.OIDC)
|
|
123
124
|
})
|
|
124
125
|
|
|
125
126
|
it("should create deactivated OIDC config", async () => {
|
|
126
127
|
await saveOIDCConfig({ activated: false })
|
|
127
128
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
|
128
|
-
expect(events.auth.SSOCreated).toBeCalledWith(
|
|
129
|
+
expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
|
|
129
130
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
130
131
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
131
|
-
await config.deleteConfig(
|
|
132
|
+
await config.deleteConfig(Configs.OIDC)
|
|
132
133
|
})
|
|
133
134
|
})
|
|
134
135
|
|
|
@@ -142,11 +143,11 @@ describe("configs", () => {
|
|
|
142
143
|
oidcConf._rev
|
|
143
144
|
)
|
|
144
145
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
145
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
146
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
|
|
146
147
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
|
147
148
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
|
148
|
-
expect(events.auth.SSODeactivated).toBeCalledWith(
|
|
149
|
-
await config.deleteConfig(
|
|
149
|
+
expect(events.auth.SSODeactivated).toBeCalledWith(Configs.OIDC)
|
|
150
|
+
await config.deleteConfig(Configs.OIDC)
|
|
150
151
|
})
|
|
151
152
|
|
|
152
153
|
it("should update OIDC config to activated", async () => {
|
|
@@ -158,11 +159,11 @@ describe("configs", () => {
|
|
|
158
159
|
oidcConf._rev
|
|
159
160
|
)
|
|
160
161
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
|
161
|
-
expect(events.auth.SSOUpdated).toBeCalledWith(
|
|
162
|
+
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
|
|
162
163
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
|
163
164
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
|
164
|
-
expect(events.auth.SSOActivated).toBeCalledWith(
|
|
165
|
-
await config.deleteConfig(
|
|
165
|
+
expect(events.auth.SSOActivated).toBeCalledWith(Configs.OIDC)
|
|
166
|
+
await config.deleteConfig(Configs.OIDC)
|
|
166
167
|
})
|
|
167
168
|
})
|
|
168
169
|
})
|
|
@@ -179,11 +180,11 @@ describe("configs", () => {
|
|
|
179
180
|
|
|
180
181
|
describe("create", () => {
|
|
181
182
|
it("should create SMTP config", async () => {
|
|
182
|
-
await config.deleteConfig(
|
|
183
|
+
await config.deleteConfig(Configs.SMTP)
|
|
183
184
|
await saveSMTPConfig()
|
|
184
185
|
expect(events.email.SMTPUpdated).not.toBeCalled()
|
|
185
186
|
expect(events.email.SMTPCreated).toBeCalledTimes(1)
|
|
186
|
-
await config.deleteConfig(
|
|
187
|
+
await config.deleteConfig(Configs.SMTP)
|
|
187
188
|
})
|
|
188
189
|
})
|
|
189
190
|
|
|
@@ -194,7 +195,7 @@ describe("configs", () => {
|
|
|
194
195
|
await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
|
|
195
196
|
expect(events.email.SMTPCreated).not.toBeCalled()
|
|
196
197
|
expect(events.email.SMTPUpdated).toBeCalledTimes(1)
|
|
197
|
-
await config.deleteConfig(
|
|
198
|
+
await config.deleteConfig(Configs.SMTP)
|
|
198
199
|
})
|
|
199
200
|
})
|
|
200
201
|
})
|
|
@@ -211,7 +212,7 @@ describe("configs", () => {
|
|
|
211
212
|
|
|
212
213
|
describe("create", () => {
|
|
213
214
|
it("should create settings config with default settings", async () => {
|
|
214
|
-
await config.deleteConfig(
|
|
215
|
+
await config.deleteConfig(Configs.SETTINGS)
|
|
215
216
|
|
|
216
217
|
await saveSettingsConfig()
|
|
217
218
|
|
|
@@ -222,7 +223,7 @@ describe("configs", () => {
|
|
|
222
223
|
|
|
223
224
|
it("should create settings config with non-default settings", async () => {
|
|
224
225
|
config.modeSelf()
|
|
225
|
-
await config.deleteConfig(
|
|
226
|
+
await config.deleteConfig(Configs.SETTINGS)
|
|
226
227
|
const conf = {
|
|
227
228
|
company: "acme",
|
|
228
229
|
logoUrl: "http://example.com",
|
|
@@ -234,14 +235,14 @@ describe("configs", () => {
|
|
|
234
235
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
235
236
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
236
237
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
237
|
-
config.
|
|
238
|
+
config.modeAccount()
|
|
238
239
|
})
|
|
239
240
|
})
|
|
240
241
|
|
|
241
242
|
describe("update", () => {
|
|
242
243
|
it("should update settings config", async () => {
|
|
243
244
|
config.modeSelf()
|
|
244
|
-
await config.deleteConfig(
|
|
245
|
+
await config.deleteConfig(Configs.SETTINGS)
|
|
245
246
|
const settingsConfig = await saveSettingsConfig()
|
|
246
247
|
settingsConfig.config.company = "acme"
|
|
247
248
|
settingsConfig.config.logoUrl = "http://example.com"
|
|
@@ -256,7 +257,7 @@ describe("configs", () => {
|
|
|
256
257
|
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
|
257
258
|
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
|
258
259
|
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
|
259
|
-
config.
|
|
260
|
+
config.modeAccount()
|
|
260
261
|
})
|
|
261
262
|
})
|
|
262
263
|
})
|
|
@@ -265,7 +266,7 @@ describe("configs", () => {
|
|
|
265
266
|
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
|
266
267
|
await config.saveSmtpConfig()
|
|
267
268
|
|
|
268
|
-
const res = await
|
|
269
|
+
const res = await api.configs.getConfigChecklist()
|
|
269
270
|
const checklist = res.body
|
|
270
271
|
|
|
271
272
|
expect(checklist.apps.checked).toBeFalsy()
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
import { TestConfiguration, mocks } from "../../../../tests"
|
|
2
|
+
import { TestConfiguration, mocks, API } from "../../../../tests"
|
|
3
3
|
const sendMailMock = mocks.email.mock()
|
|
4
4
|
import { EmailTemplatePurpose } from "../../../../constants"
|
|
5
5
|
|
|
6
6
|
describe("/api/global/email", () => {
|
|
7
7
|
const config = new TestConfiguration()
|
|
8
|
+
const api = new API(config)
|
|
8
9
|
|
|
9
10
|
beforeAll(async () => {
|
|
10
11
|
await config.beforeAll()
|
|
@@ -19,9 +20,7 @@ describe("/api/global/email", () => {
|
|
|
19
20
|
await config.saveSmtpConfig()
|
|
20
21
|
await config.saveSettingsConfig()
|
|
21
22
|
|
|
22
|
-
const res = await
|
|
23
|
-
EmailTemplatePurpose.INVITATION
|
|
24
|
-
)
|
|
23
|
+
const res = await api.emails.sendEmail(EmailTemplatePurpose.INVITATION)
|
|
25
24
|
|
|
26
25
|
expect(res.body.message).toBeDefined()
|
|
27
26
|
expect(sendMailMock).toHaveBeenCalled()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TestConfiguration } from "../../../../tests"
|
|
1
|
+
import { TestConfiguration, API } from "../../../../tests"
|
|
2
2
|
import { EmailTemplatePurpose } from "../../../../constants"
|
|
3
3
|
const nodemailer = require("nodemailer")
|
|
4
4
|
const fetch = require("node-fetch")
|
|
@@ -8,6 +8,7 @@ jest.setTimeout(30000)
|
|
|
8
8
|
|
|
9
9
|
describe("/api/global/email", () => {
|
|
10
10
|
const config = new TestConfiguration()
|
|
11
|
+
const api = new API(config)
|
|
11
12
|
|
|
12
13
|
beforeAll(async () => {
|
|
13
14
|
await config.beforeAll()
|
|
@@ -34,7 +35,7 @@ describe("/api/global/email", () => {
|
|
|
34
35
|
await Promise.race([config.saveEtherealSmtpConfig(), timeout()])
|
|
35
36
|
await Promise.race([config.saveSettingsConfig(), timeout()])
|
|
36
37
|
|
|
37
|
-
const res = await
|
|
38
|
+
const res = await api.emails.sendEmail(purpose).timeout(20000)
|
|
38
39
|
// ethereal hiccup, can't test right now
|
|
39
40
|
if (res.status >= 300) {
|
|
40
41
|
return
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
import { TestConfiguration, mocks } from "../../../../tests"
|
|
2
|
+
import { TestConfiguration, API, mocks } from "../../../../tests"
|
|
3
3
|
import { events } from "@budibase/backend-core"
|
|
4
4
|
|
|
5
5
|
describe("/api/global/self", () => {
|
|
6
6
|
const config = new TestConfiguration()
|
|
7
|
+
const api = new API(config)
|
|
7
8
|
|
|
8
9
|
beforeAll(async () => {
|
|
9
10
|
await config.beforeAll()
|
|
@@ -23,7 +24,7 @@ describe("/api/global/self", () => {
|
|
|
23
24
|
await config.createSession(user)
|
|
24
25
|
|
|
25
26
|
delete user.password
|
|
26
|
-
const res = await
|
|
27
|
+
const res = await api.self.updateSelf(user)
|
|
27
28
|
|
|
28
29
|
const dbUser = await config.getUser(user.email)
|
|
29
30
|
user._rev = dbUser._rev
|
|
@@ -39,7 +40,7 @@ describe("/api/global/self", () => {
|
|
|
39
40
|
await config.createSession(user)
|
|
40
41
|
|
|
41
42
|
user.password = "newPassword"
|
|
42
|
-
const res = await
|
|
43
|
+
const res = await api.self.updateSelf(user)
|
|
43
44
|
|
|
44
45
|
const dbUser = await config.getUser(user.email)
|
|
45
46
|
user._rev = dbUser._rev
|