Skip to content

Commit db75e4f

Browse files
committed
update passwords
1 parent 92f8d2f commit db75e4f

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/tools/args.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ export const AtlasArgs = {
4545
.min(1, "Region is required")
4646
.max(50, "Region must be 50 characters or less")
4747
.regex(/^[a-zA-Z0-9_-]+$/, "Region can only contain letters, numbers, hyphens, and underscores"),
48+
49+
password: (): z.ZodString =>
50+
CommonArgs.string()
51+
.min(1, "Password is required")
52+
.max(100, "Password must be 100 characters or less")
53+
.regex(/^[^/]*$/, "String cannot contain '/'")
54+
.regex(/^[a-zA-Z0-9._-]+$/, "Password can only contain letters, numbers, dots, hyphens, and underscores"),
4855
};

src/tools/atlas/create/createDBUser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ export const CreateDBUserArgs = {
1313
// Models will generate overly simplistic passwords like SecurePassword123 or
1414
// AtlasPassword123, which are easily guessable and exploitable. We're instructing
1515
// the model not to try and generate anything and instead leave the field unset.
16-
password: z
17-
.string()
16+
password: AtlasArgs.password()
1817
.optional()
1918
.nullable()
2019
.describe(

tests/unit/args.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,26 @@ describe("Tool args", () => {
309309
);
310310
});
311311
});
312+
313+
describe("password", () => {
314+
it("should validate valid passwords", () => {
315+
const schema = AtlasArgs.password().optional();
316+
const validPasswords = ["password123", "password_123", "Password123", "test-password-123"];
317+
validPasswords.forEach((password) => {
318+
expect(schema.parse(password)).toBe(password);
319+
});
320+
expect(schema.parse(undefined)).toBeUndefined();
321+
});
322+
323+
it("should reject invalid passwords", () => {
324+
const schema = AtlasArgs.password();
325+
expect(() => schema.parse("")).toThrow("Password is required");
326+
expect(() => schema.parse("a".repeat(101))).toThrow("Password must be 100 characters or less");
327+
expect(() => schema.parse("invalid password")).toThrow(
328+
"Password can only contain letters, numbers, dots, hyphens, and underscores"
329+
);
330+
});
331+
});
312332
});
313333

314334
describe("Edge Cases and Security", () => {

0 commit comments

Comments
 (0)