@budibase/worker 2.22.10 → 2.22.12
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 +7 -6
- package/src/api/routes/global/tests/auth.spec.ts +43 -49
- package/__mocks__/aws-sdk.ts +0 -15
- package/__mocks__/node-fetch.ts +0 -23
- package/__mocks__/oauth.ts +0 -57
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.22.
|
|
4
|
+
"version": "2.22.12",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"author": "Budibase",
|
|
38
38
|
"license": "GPL-3.0",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@budibase/backend-core": "2.22.
|
|
41
|
-
"@budibase/pro": "2.22.
|
|
42
|
-
"@budibase/string-templates": "2.22.
|
|
43
|
-
"@budibase/types": "2.22.
|
|
40
|
+
"@budibase/backend-core": "2.22.12",
|
|
41
|
+
"@budibase/pro": "2.22.12",
|
|
42
|
+
"@budibase/string-templates": "2.22.12",
|
|
43
|
+
"@budibase/types": "2.22.12",
|
|
44
44
|
"@koa/router": "8.0.8",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
46
46
|
"@types/global-agent": "2.1.1",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"@types/supertest": "2.0.14",
|
|
87
87
|
"@types/uuid": "8.3.4",
|
|
88
88
|
"jest": "29.7.0",
|
|
89
|
+
"nock": "^13.5.4",
|
|
89
90
|
"nodemon": "2.0.15",
|
|
90
91
|
"rimraf": "3.0.2",
|
|
91
92
|
"supertest": "6.3.3",
|
|
@@ -108,5 +109,5 @@
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
},
|
|
111
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "f8c374b0bfe6868c5aa13b086d97e80a15ee72d9"
|
|
112
113
|
}
|
|
@@ -13,6 +13,8 @@ import { events, constants } from "@budibase/backend-core"
|
|
|
13
13
|
import { Response } from "superagent"
|
|
14
14
|
|
|
15
15
|
import * as userSdk from "../../../../sdk/users"
|
|
16
|
+
import nock from "nock"
|
|
17
|
+
import * as jwt from "jsonwebtoken"
|
|
16
18
|
|
|
17
19
|
function getAuthCookie(response: Response) {
|
|
18
20
|
return response.headers["set-cookie"]
|
|
@@ -274,45 +276,9 @@ describe("/api/global/auth", () => {
|
|
|
274
276
|
})
|
|
275
277
|
})
|
|
276
278
|
|
|
277
|
-
describe("init", () => {
|
|
278
|
-
describe("POST /api/global/auth/init", () => {})
|
|
279
|
-
|
|
280
|
-
describe("GET /api/global/auth/init", () => {})
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
describe("datasource", () => {
|
|
284
|
-
// MULTI TENANT
|
|
285
|
-
|
|
286
|
-
describe("GET /api/global/auth/:tenantId/datasource/:provider", () => {})
|
|
287
|
-
|
|
288
|
-
describe("GET /api/global/auth/:tenantId/datasource/:provider/callback", () => {})
|
|
289
|
-
|
|
290
|
-
// SINGLE TENANT
|
|
291
|
-
|
|
292
|
-
describe("GET /api/global/auth/datasource/:provider/callback", () => {})
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
describe("google", () => {
|
|
296
|
-
// MULTI TENANT
|
|
297
|
-
|
|
298
|
-
describe("GET /api/global/auth/:tenantId/google", () => {})
|
|
299
|
-
|
|
300
|
-
describe("GET /api/global/auth/:tenantId/google/callback", () => {})
|
|
301
|
-
|
|
302
|
-
// SINGLE TENANT
|
|
303
|
-
|
|
304
|
-
describe("GET /api/global/auth/google/callback", () => {})
|
|
305
|
-
|
|
306
|
-
describe("GET /api/admin/auth/google/callback", () => {})
|
|
307
|
-
})
|
|
308
|
-
|
|
309
279
|
describe("oidc", () => {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
mockGetWellKnownConfig()
|
|
313
|
-
|
|
314
|
-
// see: __mocks__/oauth
|
|
315
|
-
// for associated mocking inside passport
|
|
280
|
+
afterEach(() => {
|
|
281
|
+
nock.cleanAll()
|
|
316
282
|
})
|
|
317
283
|
|
|
318
284
|
const generateOidcConfig = async () => {
|
|
@@ -321,21 +287,16 @@ describe("/api/global/auth", () => {
|
|
|
321
287
|
return chosenConfig.uuid
|
|
322
288
|
}
|
|
323
289
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
290
|
+
// MULTI TENANT
|
|
291
|
+
describe("GET /api/global/auth/:tenantId/oidc/configs/:configId", () => {
|
|
292
|
+
it("redirects to auth provider", async () => {
|
|
293
|
+
nock("http://someconfigurl").get("/").times(1).reply(200, {
|
|
328
294
|
issuer: "test",
|
|
329
295
|
authorization_endpoint: "http://localhost/auth",
|
|
330
296
|
token_endpoint: "http://localhost/token",
|
|
331
297
|
userinfo_endpoint: "http://localhost/userinfo",
|
|
332
|
-
})
|
|
333
|
-
})
|
|
334
|
-
}
|
|
298
|
+
})
|
|
335
299
|
|
|
336
|
-
// MULTI TENANT
|
|
337
|
-
describe("GET /api/global/auth/:tenantId/oidc/configs/:configId", () => {
|
|
338
|
-
it("redirects to auth provider", async () => {
|
|
339
300
|
const configId = await generateOidcConfig()
|
|
340
301
|
|
|
341
302
|
const res = await config.api.configs.getOIDCConfig(configId)
|
|
@@ -352,10 +313,43 @@ describe("/api/global/auth", () => {
|
|
|
352
313
|
|
|
353
314
|
describe("GET /api/global/auth/:tenantId/oidc/callback", () => {
|
|
354
315
|
it("logs in", async () => {
|
|
316
|
+
nock("http://someconfigurl").get("/").times(2).reply(200, {
|
|
317
|
+
issuer: "test",
|
|
318
|
+
authorization_endpoint: "http://localhost/auth",
|
|
319
|
+
token_endpoint: "http://localhost/token",
|
|
320
|
+
userinfo_endpoint: "http://localhost/userinfo",
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
const token = jwt.sign(
|
|
324
|
+
{
|
|
325
|
+
iss: "test",
|
|
326
|
+
sub: "sub",
|
|
327
|
+
aud: "clientId",
|
|
328
|
+
exp: Math.floor(Date.now() / 1000) + 60 * 60,
|
|
329
|
+
email: "oauth@example.com",
|
|
330
|
+
},
|
|
331
|
+
"secret"
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
nock("http://localhost").post("/token").reply(200, {
|
|
335
|
+
access_token: "access",
|
|
336
|
+
refresh_token: "refresh",
|
|
337
|
+
id_token: token,
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
nock("http://localhost").get("/userinfo?schema=openid").reply(200, {
|
|
341
|
+
sub: "sub",
|
|
342
|
+
email: "oauth@example.com",
|
|
343
|
+
})
|
|
344
|
+
|
|
355
345
|
const configId = await generateOidcConfig()
|
|
356
346
|
const preAuthRes = await config.api.configs.getOIDCConfig(configId)
|
|
357
|
-
|
|
358
347
|
const res = await config.api.configs.OIDCCallback(configId, preAuthRes)
|
|
348
|
+
if (res.status > 399) {
|
|
349
|
+
throw new Error(
|
|
350
|
+
`OIDC callback failed with status ${res.status}: ${res.text}`
|
|
351
|
+
)
|
|
352
|
+
}
|
|
359
353
|
|
|
360
354
|
expect(events.auth.login).toHaveBeenCalledWith(
|
|
361
355
|
"oidc",
|
package/__mocks__/aws-sdk.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const mockS3 = {
|
|
2
|
-
headBucket: jest.fn().mockReturnThis(),
|
|
3
|
-
deleteObject: jest.fn().mockReturnThis(),
|
|
4
|
-
deleteObjects: jest.fn().mockReturnThis(),
|
|
5
|
-
createBucket: jest.fn().mockReturnThis(),
|
|
6
|
-
listObjects: jest.fn().mockReturnThis(),
|
|
7
|
-
promise: jest.fn().mockReturnThis(),
|
|
8
|
-
catch: jest.fn(),
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const AWS = {
|
|
12
|
-
S3: jest.fn(() => mockS3),
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default AWS
|
package/__mocks__/node-fetch.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
module FetchMock {
|
|
3
|
-
const fetch = jest.requireActual("node-fetch")
|
|
4
|
-
|
|
5
|
-
const func = async (url: any, opts: any) => {
|
|
6
|
-
if (url.includes("http://someconfigurl")) {
|
|
7
|
-
return {
|
|
8
|
-
ok: true,
|
|
9
|
-
json: () => ({
|
|
10
|
-
issuer: "test",
|
|
11
|
-
authorization_endpoint: "http://localhost/auth",
|
|
12
|
-
token_endpoint: "http://localhost/token",
|
|
13
|
-
userinfo_endpoint: "http://localhost/userinfo",
|
|
14
|
-
}),
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return fetch(url, opts)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
func.Headers = fetch.Headers
|
|
21
|
-
|
|
22
|
-
module.exports = func
|
|
23
|
-
}
|
package/__mocks__/oauth.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import * as jwt from "jsonwebtoken"
|
|
2
|
-
|
|
3
|
-
const mockOAuth2 = {
|
|
4
|
-
getOAuthAccessToken: (code: string, p: any, cb: any) => {
|
|
5
|
-
const err = null
|
|
6
|
-
const accessToken = "access_token"
|
|
7
|
-
const refreshToken = "refresh_token"
|
|
8
|
-
|
|
9
|
-
const exp = new Date()
|
|
10
|
-
exp.setDate(exp.getDate() + 1)
|
|
11
|
-
|
|
12
|
-
const iat = new Date()
|
|
13
|
-
iat.setDate(iat.getDate() - 1)
|
|
14
|
-
|
|
15
|
-
const claims = {
|
|
16
|
-
iss: "test",
|
|
17
|
-
sub: "sub",
|
|
18
|
-
aud: "clientId",
|
|
19
|
-
exp: exp.getTime() / 1000,
|
|
20
|
-
iat: iat.getTime() / 1000,
|
|
21
|
-
email: "oauth@example.com",
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const idToken = jwt.sign(claims, "secret")
|
|
25
|
-
|
|
26
|
-
const params = {
|
|
27
|
-
id_token: idToken,
|
|
28
|
-
}
|
|
29
|
-
return cb(err, accessToken, refreshToken, params)
|
|
30
|
-
},
|
|
31
|
-
_request: (
|
|
32
|
-
method: string,
|
|
33
|
-
url: string,
|
|
34
|
-
headers: any,
|
|
35
|
-
postBody: any,
|
|
36
|
-
accessToken: string,
|
|
37
|
-
cb: any
|
|
38
|
-
) => {
|
|
39
|
-
const err = null
|
|
40
|
-
const body = {
|
|
41
|
-
sub: "sub",
|
|
42
|
-
user_id: "userId",
|
|
43
|
-
name: "OAuth",
|
|
44
|
-
family_name: "2",
|
|
45
|
-
given_name: "OAuth",
|
|
46
|
-
middle_name: "",
|
|
47
|
-
}
|
|
48
|
-
const res = {}
|
|
49
|
-
return cb(err, JSON.stringify(body), res)
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const oauth = {
|
|
54
|
-
OAuth2: jest.fn(() => mockOAuth2),
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export = oauth
|