Skip to content

Commit d4fec26

Browse files
committed
add more limits
1 parent dd003e6 commit d4fec26

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/tools/args.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export const AtlasArgs = {
4141
cidrBlock: (): z.ZodString => CommonArgs.string().cidr(),
4242

4343
region: (): z.ZodString =>
44-
CommonArgs.string().regex(
45-
/^[a-zA-Z0-9_-]+$/,
46-
"Region can only contain letters, numbers, hyphens, and underscores"
47-
),
44+
CommonArgs.string()
45+
.min(1, "Region is required")
46+
.max(50, "Region must be 50 characters or less")
47+
.regex(/^[a-zA-Z0-9_-]+$/, "Region can only contain letters, numbers, hyphens, and underscores"),
4848
};

tests/unit/args.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { AtlasArgs, CommonArgs } from "../../src/tools/args.js";
33

4-
describe("Atlas Validators", () => {
4+
describe("Tool args", () => {
55
describe("CommonArgs", () => {
66
describe("string", () => {
77
it("should return a ZodString schema", () => {
@@ -19,9 +19,24 @@ describe("Atlas Validators", () => {
1919

2020
it("should not allow special characters and unicode symbols", () => {
2121
const schema = CommonArgs.string();
22+
23+
// Unicode characters
2224
expect(() => schema.parse("héllo")).toThrow();
2325
expect(() => schema.parse("测试")).toThrow();
26+
expect(() => schema.parse("café")).toThrow();
27+
28+
// Emojis
2429
expect(() => schema.parse("🚀")).toThrow();
30+
expect(() => schema.parse("hello😀")).toThrow();
31+
32+
// Control characters (below ASCII 32)
33+
expect(() => schema.parse("hello\nworld")).toThrow();
34+
expect(() => schema.parse("hello\tworld")).toThrow();
35+
expect(() => schema.parse("hello\0world")).toThrow();
36+
37+
// Extended ASCII characters (above ASCII 126)
38+
expect(() => schema.parse("hello\x80")).toThrow();
39+
expect(() => schema.parse("hello\xFF")).toThrow();
2540
});
2641

2742
it("should reject non-string values", () => {
@@ -246,9 +261,22 @@ describe("Atlas Validators", () => {
246261
});
247262
});
248263

264+
it("should accept exactly 50 characters", () => {
265+
const schema = AtlasArgs.region();
266+
const maxLengthRegion = "a".repeat(50);
267+
expect(schema.parse(maxLengthRegion)).toBe(maxLengthRegion);
268+
});
269+
249270
it("should reject invalid region names", () => {
250271
const schema = AtlasArgs.region();
251272

273+
// Empty string
274+
expect(() => schema.parse("")).toThrow("Region is required");
275+
276+
// Too long (over 50 characters)
277+
const longRegion = "a".repeat(51);
278+
expect(() => schema.parse(longRegion)).toThrow("Region must be 50 characters or less");
279+
252280
// Invalid characters
253281
expect(() => schema.parse("US EAST 1")).toThrow(
254282
"Region can only contain letters, numbers, hyphens, and underscores"

0 commit comments

Comments
 (0)