@lobb-js/lobb-ext-auth 0.12.0 → 0.13.0

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.
Files changed (41) hide show
  1. package/dist/lib/components/pages/loginPage/index.svelte +1 -1
  2. package/dist/lib/components/pages/settings/pages/activityFeed.svelte +1 -1
  3. package/dist/lib/components/pages/settings/pages/rolesAndPermissions.svelte +1 -1
  4. package/dist/lib/components/pages/settings/pages/users.svelte +1 -1
  5. package/extensions/auth/studio/lib/components/pages/loginPage/index.svelte +1 -1
  6. package/extensions/auth/studio/lib/components/pages/settings/pages/activityFeed.svelte +1 -1
  7. package/extensions/auth/studio/lib/components/pages/settings/pages/rolesAndPermissions.svelte +1 -1
  8. package/extensions/auth/studio/lib/components/pages/settings/pages/users.svelte +1 -1
  9. package/package.json +5 -5
  10. package/extensions/auth/tests/collections/extend_users_collection.test.ts +0 -61
  11. package/extensions/auth/tests/collections/shares.test.ts +0 -657
  12. package/extensions/auth/tests/configs/auth.ts +0 -101
  13. package/extensions/auth/tests/configs/auth_no_roles.ts +0 -65
  14. package/extensions/auth/tests/configs/auth_public_full_access.ts +0 -69
  15. package/extensions/auth/tests/configs/auth_with_admin_extra_fields.ts +0 -53
  16. package/extensions/auth/tests/configs/auth_with_different_admin_creds.ts +0 -81
  17. package/extensions/auth/tests/configs/auth_with_extend_users.ts +0 -79
  18. package/extensions/auth/tests/configs/auth_with_refresh_token.ts +0 -86
  19. package/extensions/auth/tests/configs/auth_with_short_access_token_only.ts +0 -95
  20. package/extensions/auth/tests/configs/auth_with_short_time_refresh_token.ts +0 -86
  21. package/extensions/auth/tests/configs/social_blog.ts +0 -146
  22. package/extensions/auth/tests/controllers/change_password.test.ts +0 -113
  23. package/extensions/auth/tests/controllers/dashboardAccessRoles.test.ts +0 -29
  24. package/extensions/auth/tests/controllers/login.test.ts +0 -101
  25. package/extensions/auth/tests/controllers/logout.test.ts +0 -89
  26. package/extensions/auth/tests/controllers/me.test.ts +0 -376
  27. package/extensions/auth/tests/controllers/register.test.ts +0 -45
  28. package/extensions/auth/tests/database/adminExtraFields.test.ts +0 -50
  29. package/extensions/auth/tests/database/db.test.ts +0 -64
  30. package/extensions/auth/tests/database/differentAdminCreds.test.ts +0 -51
  31. package/extensions/auth/tests/middlewares/adminAuthGuard.test.ts +0 -157
  32. package/extensions/auth/tests/middlewares/adminProtection.test.ts +0 -59
  33. package/extensions/auth/tests/middlewares/publicAllowBasic.test.ts +0 -137
  34. package/extensions/auth/tests/middlewares/publicPreventBasic.test.ts +0 -108
  35. package/extensions/auth/tests/permissions.test.ts +0 -127
  36. package/extensions/auth/tests/socialBlog.test.ts +0 -253
  37. package/extensions/auth/tests/utils/addArticles.ts +0 -22
  38. package/extensions/auth/tests/utils/addSocialBlogArticles.ts +0 -52
  39. package/extensions/auth/tests/utils/data/articles.ts +0 -65
  40. package/extensions/auth/tests/utils/data/socialBlogArticles.ts +0 -56
  41. package/extensions/auth/tests/workflows/shareIntersection.test.ts +0 -158
@@ -1,146 +0,0 @@
1
- import type { Config } from "@lobb-js/core";
2
- import auth from "../../index.ts";
3
-
4
- export const socialBlogConfig: Config = {
5
- project: {
6
- name: "Lobb",
7
- force_sync: true,
8
- support_email: "support@lobb.com",
9
- },
10
- database: {
11
- host: "localhost",
12
- port: 5432,
13
- username: "test",
14
- password: "test",
15
- database: "*",
16
-
17
- },
18
- web_server: {
19
- host: "0.0.0.0",
20
- port: 0,
21
- },
22
- extensions: [
23
- auth({
24
- admin: {
25
- password: "admin",
26
- email: "admin@test.com",
27
- },
28
- extend_users: {
29
- fields: {
30
- name: {
31
- type: "string",
32
- length: 255,
33
- },
34
- },
35
- },
36
- roles: {
37
- public: {
38
- permissions: {
39
- auth_users: {
40
- create: {
41
- payloadGuard: ({ payload }) => {
42
- if (payload.role === "author") {
43
- return true;
44
- }
45
- },
46
- },
47
- read: {
48
- filter: {
49
- role: "author",
50
- },
51
- fields: {
52
- email: true,
53
- },
54
- },
55
- },
56
- articles: {
57
- read: {
58
- filter: {
59
- status: "public",
60
- },
61
- },
62
- },
63
- },
64
- },
65
- author: {
66
- permissions: {
67
- auth_users: {
68
- read: {
69
- filter: {
70
- role: "author",
71
- },
72
- fields: {
73
- email: true,
74
- },
75
- },
76
- },
77
- articles: {
78
- create: {
79
- fields: {
80
- title: true,
81
- body: true,
82
- },
83
- mutate: {
84
- author_id: ({ value, user }) => {
85
- return user ? user.id : value;
86
- },
87
- },
88
- },
89
- read: {
90
- filter: {
91
- $or: [
92
- {
93
- status: "public",
94
- },
95
- {
96
- author_id: ({ user }) => {
97
- return user ? user.id : null;
98
- },
99
- },
100
- ],
101
- },
102
- },
103
- },
104
- },
105
- },
106
- },
107
- }),
108
- ],
109
- collections: {
110
- articles: {
111
- indexes: {},
112
- fields: {
113
- id: {
114
- type: "integer",
115
- },
116
- image: {
117
- type: "string",
118
- length: 255,
119
- },
120
- title: {
121
- type: "string",
122
- length: 255,
123
- required: true,
124
- },
125
- description: {
126
- type: "string",
127
- length: 255,
128
- },
129
- body: {
130
- type: "text",
131
- required: true,
132
- },
133
- status: {
134
- type: "string",
135
- length: 255,
136
- default: "private",
137
- enum: ["public", "private"],
138
- },
139
- author_id: {
140
- type: "integer",
141
- required: true,
142
- },
143
- },
144
- },
145
- },
146
- };
@@ -1,113 +0,0 @@
1
- import { Lobb } from "@lobb-js/core";
2
- import { afterAll, beforeAll, describe, it, expect } from "bun:test";
3
- import { authConfig } from "../configs/auth.ts";
4
-
5
- describe("Change Password Request", () => {
6
- let lobb: Lobb;
7
- let baseUrl: string;
8
-
9
- beforeAll(async () => {
10
- lobb = await Lobb.init(authConfig);
11
- baseUrl = `http://127.0.0.1:${lobb.webServer.port}`;
12
- });
13
-
14
- afterAll(async () => {
15
- await lobb.close();
16
- });
17
-
18
- it("should fail if an access token doesnt exist", async () => {
19
- const response = await fetch(
20
- `${baseUrl}/api/collections/auth_users/me`,
21
- {
22
- method: "PATCH",
23
- body: JSON.stringify({
24
- data: {
25
- password: "new_pass",
26
- },
27
- }),
28
- },
29
- );
30
- const data = await response.json();
31
-
32
- expect(response.status).toEqual(400);
33
- expect(
34
- data.message,
35
- ).toEqual("You need to provide an access token.");
36
- });
37
-
38
- it("should fail if the token is wrong", async () => {
39
- const paswordChangeResponse = await fetch(
40
- `${baseUrl}/api/collections/auth_users/me`,
41
- {
42
- method: "PATCH",
43
- headers: {
44
- "Authorization": `Bearer wrong_token`,
45
- },
46
- body: JSON.stringify({
47
- data: {
48
- password: "new_pass",
49
- },
50
- }),
51
- },
52
- );
53
- const data = await paswordChangeResponse.json();
54
-
55
- expect(paswordChangeResponse.status).toEqual(400);
56
- expect(
57
- data.message,
58
- ).toEqual("You need to provide an access token.");
59
- });
60
-
61
- it("should succeed in changing the password", async () => {
62
- const response = await fetch(
63
- `${baseUrl}/api/collections/auth_sessions`,
64
- {
65
- method: "POST",
66
- headers: {
67
- "Content-Type": "application/json",
68
- },
69
- body: JSON.stringify({
70
- data: {
71
- email: "admin@test.com",
72
- password: "admin",
73
- },
74
- }),
75
- },
76
- );
77
- const loginData = await response.json();
78
-
79
- const paswordChangeResponse = await fetch(
80
- `${baseUrl}/api/collections/auth_users/me`,
81
- {
82
- method: "PATCH",
83
- headers: {
84
- "Authorization": `Bearer ${loginData.data.access_token.token}`,
85
- },
86
- body: JSON.stringify({
87
- data: {
88
- password: "new_pass",
89
- },
90
- }),
91
- },
92
- );
93
- const data = await paswordChangeResponse.json();
94
-
95
- expect(paswordChangeResponse.status).toEqual(200);
96
-
97
- const secondLoginResponse = await fetch(
98
- `${baseUrl}/api/collections/auth_sessions`,
99
- {
100
- method: "POST",
101
- body: JSON.stringify({
102
- data: {
103
- email: "admin@test.com",
104
- password: "new_pass",
105
- },
106
- }),
107
- },
108
- );
109
- const secondLoginData = await secondLoginResponse.json();
110
-
111
- expect(secondLoginResponse.status).toEqual(200);
112
- });
113
- });
@@ -1,29 +0,0 @@
1
- import { Lobb } from "@lobb-js/core";
2
- import { afterAll, beforeAll, describe, it, expect } from "bun:test";
3
- import { authConfig } from "../configs/auth.ts";
4
-
5
- describe("Login", () => {
6
- let lobb: Lobb;
7
- let baseUrl: string;
8
-
9
- beforeAll(async () => {
10
- lobb = await Lobb.init(authConfig);
11
- baseUrl = `http://127.0.0.1:${lobb.webServer.port}`;
12
- });
13
-
14
- afterAll(async () => {
15
- await lobb.close();
16
- });
17
-
18
- it("should return the dashboard_access_roles", async () => {
19
- const response = await fetch(
20
- `${baseUrl}/api/meta?pick=extensions.auth.dashboard_access_roles`,
21
- );
22
- const data = await response.json();
23
-
24
- expect(response.status).toEqual(200);
25
- expect(
26
- data,
27
- ).toEqual(["admin"]);
28
- });
29
- });
@@ -1,101 +0,0 @@
1
- import { Lobb } from "@lobb-js/core";
2
- import { afterAll, beforeAll, describe, it, expect } from "bun:test";
3
- import { authConfig } from "../configs/auth.ts";
4
-
5
- describe("Login", () => {
6
- let lobb: Lobb;
7
- let baseUrl: string;
8
-
9
- beforeAll(async () => {
10
- lobb = await Lobb.init(authConfig);
11
- baseUrl = `http://127.0.0.1:${lobb.webServer.port}`;
12
- await lobb.collectionService.deleteMany({
13
- collectionName: "auth_sessions",
14
- });
15
- });
16
-
17
- afterAll(async () => {
18
- await lobb.close();
19
- });
20
-
21
- it("should fail when passing wrong password", async () => {
22
- const response = await fetch(
23
- `${baseUrl}/api/collections/auth_sessions`,
24
- {
25
- method: "POST",
26
- headers: {
27
- "Content-Type": "application/json",
28
- },
29
- body: JSON.stringify({
30
- data: {
31
- email: "admin@test.com",
32
- password: "wrong_password",
33
- },
34
- }),
35
- },
36
- );
37
- const data = await response.json();
38
-
39
- expect(response.status).toEqual(401);
40
- expect(
41
- data.message,
42
- ).toEqual("The password provided is incorrect. Please verify and try again.");
43
- });
44
-
45
- it("should fail when passing a non existing email", async () => {
46
- const response = await fetch(
47
- `${baseUrl}/api/collections/auth_sessions`,
48
- {
49
- method: "POST",
50
- headers: {
51
- "Content-Type": "application/json",
52
- },
53
- body: JSON.stringify({
54
- data: {
55
- email: "non_exist_user@gmail.com",
56
- password: "admin",
57
- },
58
- }),
59
- },
60
- );
61
- const data = await response.json();
62
-
63
- expect(response.status).toEqual(404);
64
- expect(
65
- data.message,
66
- ).toEqual("The user with this email (non_exist_user@gmail.com) doesnt exist.");
67
- });
68
-
69
- it("should login successfully", async () => {
70
- const response = await fetch(
71
- `${baseUrl}/api/collections/auth_sessions`,
72
- {
73
- method: "POST",
74
- headers: {
75
- "Content-Type": "application/json",
76
- },
77
- body: JSON.stringify({
78
- data: {
79
- email: "admin@test.com",
80
- password: "admin",
81
- },
82
- }),
83
- },
84
- );
85
- const result = await response.json();
86
-
87
- expect(result).toMatchObject({
88
- data: {
89
- access_token: {},
90
- user: {
91
- email: "admin@test.com",
92
- role: "admin",
93
- },
94
- },
95
- });
96
- expect(Object.keys(result.data.access_token)).toEqual([
97
- "token",
98
- "expires_at",
99
- ]);
100
- });
101
- });
@@ -1,89 +0,0 @@
1
- import { Lobb } from "@lobb-js/core";
2
- import { afterAll, beforeAll, describe, it, expect } from "bun:test";
3
- import { authConfig } from "../configs/auth.ts";
4
-
5
- describe("Logout", () => {
6
- let lobb: Lobb;
7
- let baseUrl: string;
8
-
9
- beforeAll(async () => {
10
- lobb = await Lobb.init(authConfig);
11
- baseUrl = `http://127.0.0.1:${lobb.webServer.port}`;
12
- await lobb.collectionService.deleteMany({
13
- collectionName: "auth_sessions",
14
- });
15
- });
16
-
17
- afterAll(async () => {
18
- await lobb.close();
19
- });
20
-
21
- it("should throw an error if a session wasnt passed", async () => {
22
- const response = await fetch(
23
- `${baseUrl}/api/collections/auth_sessions`,
24
- {
25
- method: "DELETE",
26
- },
27
- );
28
- await response.json();
29
-
30
- expect(response.status).toEqual(400);
31
- });
32
-
33
- it("should return 204 when deleting a non existing session", async () => {
34
- const response = await fetch(
35
- `${baseUrl}/api/collections/auth_sessions`,
36
- {
37
- method: "DELETE",
38
- headers: {
39
- "Authorization": "Bearer NON_EXISTING_SESSION_ID",
40
- },
41
- },
42
- );
43
- await response.text();
44
-
45
- expect(response.status).toEqual(204);
46
- });
47
-
48
- it("should work and return 200", async () => {
49
- const response1 = await fetch(
50
- `${baseUrl}/api/collections/auth_sessions`,
51
- {
52
- method: "POST",
53
- headers: {
54
- "Authorization": "Bearer NON_EXISTING_SESSION_ID",
55
- },
56
- body: JSON.stringify({
57
- data: {
58
- email: "admin@test.com",
59
- password: "admin",
60
- },
61
- }),
62
- },
63
- );
64
- const result = await response1.json();
65
-
66
- expect((await lobb.collectionService.findAll({
67
- collectionName: "auth_sessions",
68
- })).data.length).toEqual(1);
69
-
70
- const session_token = result.data.access_token.token;
71
-
72
- const response = await fetch(
73
- `${baseUrl}/api/collections/auth_sessions`,
74
- {
75
- method: "DELETE",
76
- headers: {
77
- "Authorization": `Bearer ${session_token}`,
78
- },
79
- },
80
- );
81
-
82
- expect(response.status).toEqual(204);
83
-
84
- // check if the session was really deleted
85
- expect((await lobb.collectionService.findAll({
86
- collectionName: "auth_sessions",
87
- })).data.length).toEqual(0);
88
- });
89
- });