Skip to content

Commit 271a678

Browse files
committed
address comment: keep readWrite if any write tool is enabled but not metadata
1 parent 34051b7 commit 271a678

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

src/common/atlas/roles.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ export function getDefaultRoleFromConfig(config: UserConfig): DatabaseUserRole {
1313
};
1414
}
1515

16-
// If all write tools are enabled, use readWriteAnyDatabase
16+
// If any of the write tools are enabled, use readWriteAnyDatabase
1717
if (
18-
!config.disabledTools?.includes("create") &&
19-
!config.disabledTools?.includes("update") &&
20-
!config.disabledTools?.includes("delete") &&
21-
!config.disabledTools?.includes("metadata")
18+
!config.disabledTools?.includes("create") ||
19+
!config.disabledTools?.includes("update") ||
20+
!config.disabledTools?.includes("delete")
2221
) {
2322
return {
2423
roleName: "readWriteAnyDatabase",

tests/unit/common/roles.test.ts

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ describe("getDefaultRoleFromConfig", () => {
1818
disabledTools: [],
1919
};
2020

21+
const readWriteConfigWithDeleteDisabled: UserConfig = {
22+
...defaultConfig,
23+
readOnly: false,
24+
disabledTools: ["delete"],
25+
};
26+
27+
const readWriteConfigWithCreateDisabled: UserConfig = {
28+
...defaultConfig,
29+
readOnly: false,
30+
disabledTools: ["create"],
31+
};
32+
33+
const readWriteConfigWithUpdateDisabled: UserConfig = {
34+
...defaultConfig,
35+
readOnly: false,
36+
disabledTools: ["update"],
37+
};
38+
39+
const readWriteConfigWithAllToolsDisabled: UserConfig = {
40+
...defaultConfig,
41+
readOnly: false,
42+
disabledTools: ["create", "update", "delete"],
43+
};
44+
2145
it("should return the correct role for a read-only config", () => {
2246
const role = getDefaultRoleFromConfig(readOnlyConfig);
2347
expect(role).toEqual({
@@ -42,14 +66,35 @@ describe("getDefaultRoleFromConfig", () => {
4266
});
4367
});
4468

45-
for (const tool of ["create", "update", "delete", "metadata"]) {
46-
it(`should return the correct role for a config with ${tool} disabled`, () => {
47-
const config = { ...defaultConfig, disabledTools: [tool] };
48-
const role = getDefaultRoleFromConfig(config);
49-
expect(role).toEqual({
50-
roleName: "readAnyDatabase",
51-
databaseName: "admin",
52-
});
69+
it("should return the correct role for a read-write config with delete disabled", () => {
70+
const role = getDefaultRoleFromConfig(readWriteConfigWithDeleteDisabled);
71+
expect(role).toEqual({
72+
roleName: "readWriteAnyDatabase",
73+
databaseName: "admin",
74+
});
75+
});
76+
77+
it("should return the correct role for a read-write config with create disabled", () => {
78+
const role = getDefaultRoleFromConfig(readWriteConfigWithCreateDisabled);
79+
expect(role).toEqual({
80+
roleName: "readWriteAnyDatabase",
81+
databaseName: "admin",
5382
});
54-
}
83+
});
84+
85+
it("should return the correct role for a read-write config with update disabled", () => {
86+
const role = getDefaultRoleFromConfig(readWriteConfigWithUpdateDisabled);
87+
expect(role).toEqual({
88+
roleName: "readAnyDatabase",
89+
databaseName: "admin",
90+
});
91+
});
92+
93+
it("should return the correct role for a read-write config with all tools disabled", () => {
94+
const role = getDefaultRoleFromConfig(readWriteConfigWithAllToolsDisabled);
95+
expect(role).toEqual({
96+
roleName: "readAnyDatabase",
97+
databaseName: "admin",
98+
});
99+
});
55100
});

0 commit comments

Comments
 (0)