@checkstack/auth-backend 0.0.3 → 0.2.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.
- package/CHANGELOG.md +174 -0
- package/drizzle/0002_lowly_squirrel_girl.sql +43 -0
- package/drizzle/0003_tranquil_sally_floyd.sql +8 -0
- package/drizzle/0004_lucky_power_man.sql +21 -0
- package/drizzle/meta/0002_snapshot.json +1017 -0
- package/drizzle/meta/0003_snapshot.json +1050 -0
- package/drizzle/meta/0004_snapshot.json +1050 -0
- package/drizzle/meta/_journal.json +21 -0
- package/package.json +1 -1
- package/src/index.ts +176 -162
- package/src/router.test.ts +11 -11
- package/src/router.ts +525 -90
- package/src/schema.ts +125 -18
- package/src/teams.test.ts +1985 -0
- package/src/utils/user.test.ts +65 -46
- package/src/utils/user.ts +21 -13
package/src/router.test.ts
CHANGED
|
@@ -17,7 +17,7 @@ describe("Auth Router", () => {
|
|
|
17
17
|
const mockUser = {
|
|
18
18
|
type: "user" as const,
|
|
19
19
|
id: "test-user",
|
|
20
|
-
|
|
20
|
+
accessRules: ["*"],
|
|
21
21
|
roles: ["admin"],
|
|
22
22
|
} as any;
|
|
23
23
|
|
|
@@ -69,8 +69,8 @@ describe("Auth Router", () => {
|
|
|
69
69
|
list: mock(() => Promise.resolve([])),
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
const
|
|
73
|
-
|
|
72
|
+
const mockAccessRuleRegistry = {
|
|
73
|
+
getAccessRules: () => [
|
|
74
74
|
{ id: "auth-backend.users.read", description: "List all users" },
|
|
75
75
|
{ id: "auth-backend.users.manage", description: "Delete users" },
|
|
76
76
|
{ id: "auth-backend.roles.read", description: "Read and list roles" },
|
|
@@ -82,13 +82,13 @@ describe("Auth Router", () => {
|
|
|
82
82
|
mockRegistry,
|
|
83
83
|
async () => {},
|
|
84
84
|
mockConfigService,
|
|
85
|
-
|
|
85
|
+
mockAccessRuleRegistry
|
|
86
86
|
);
|
|
87
87
|
|
|
88
|
-
it("
|
|
88
|
+
it("getAccessRules returns current user access rules", async () => {
|
|
89
89
|
const context = createMockRpcContext({ user: mockUser });
|
|
90
|
-
const result = await call(router.
|
|
91
|
-
expect(result.
|
|
90
|
+
const result = await call(router.accessRules, undefined, { context });
|
|
91
|
+
expect(result.accessRules).toContain("*");
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it("getUsers lists users with roles", async () => {
|
|
@@ -145,21 +145,21 @@ describe("Auth Router", () => {
|
|
|
145
145
|
expect(deletedTables.includes(schema.user)).toBe(true);
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
it("getRoles returns all roles with
|
|
148
|
+
it("getRoles returns all roles with accesss", async () => {
|
|
149
149
|
const context = createMockRpcContext({ user: mockUser });
|
|
150
150
|
mockDb.select.mockImplementationOnce(() => ({
|
|
151
151
|
from: mock(() => createChain([{ id: "admin", name: "Admin" }])),
|
|
152
152
|
}));
|
|
153
153
|
mockDb.select.mockImplementationOnce(() => ({
|
|
154
154
|
from: mock(() =>
|
|
155
|
-
createChain([{ roleId: "admin",
|
|
155
|
+
createChain([{ roleId: "admin", accessRuleId: "users.manage" }])
|
|
156
156
|
),
|
|
157
157
|
}));
|
|
158
158
|
|
|
159
159
|
const result = await call(router.getRoles, undefined, { context });
|
|
160
160
|
expect(result).toHaveLength(1);
|
|
161
161
|
expect(result[0].id).toBe("admin");
|
|
162
|
-
expect(result[0].
|
|
162
|
+
expect(result[0].accessRules).toContain("users.manage");
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
it("updateUserRoles updates user roles", async () => {
|
|
@@ -214,7 +214,7 @@ describe("Auth Router", () => {
|
|
|
214
214
|
expect(result.allowRegistration).toBe(true);
|
|
215
215
|
});
|
|
216
216
|
|
|
217
|
-
it("setRegistrationStatus updates flag and requires
|
|
217
|
+
it("setRegistrationStatus updates flag and requires access", async () => {
|
|
218
218
|
const context = createMockRpcContext({ user: mockUser });
|
|
219
219
|
const result = await call(
|
|
220
220
|
router.setRegistrationStatus,
|