forked from ritik4ever/stellar-goal-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.test.ts
More file actions
80 lines (72 loc) · 2.98 KB
/
Copy pathschemas.test.ts
File metadata and controls
80 lines (72 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { describe, expect, it } from "vitest";
import { createCampaignPayloadSchema } from "./schemas";
describe("createCampaignPayloadSchema - Input Sanitization", () => {
const basePayload = {
creator: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
acceptedTokens: ["USDC"],
targetAmount: 100,
deadline: Math.floor(Date.now() / 1000) + 3600,
};
it("should successfully validate and trim valid inputs", () => {
const result = createCampaignPayloadSchema.safeParse({
...basePayload,
title: " Valid Campaign Title ",
description: " This is a valid campaign description that meets the length requirements. ",
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.title).toBe("Valid Campaign Title");
expect(result.data.description).toBe("This is a valid campaign description that meets the length requirements.");
}
});
it("should reject titles with only whitespace", () => {
const result = createCampaignPayloadSchema.safeParse({
...basePayload,
title: " ",
description: "This is a valid campaign description that meets the length requirements.",
});
expect(result.success).toBe(false);
});
it("should escape HTML tags in title and description during parsing", () => {
const result = createCampaignPayloadSchema.safeParse({
...basePayload,
title: "<h1>Test</h1>",
description: "<h1>Test</h1> with at least 20 characters",
});
expect(result.success).toBe(true);
if (result.success) {
expect(result.data.title).toBe("<h1>Test</h1>");
expect(result.data.description).toBe("<h1>Test</h1> with at least 20 characters");
}
});
it("should reject script tags in title", () => {
const result = createCampaignPayloadSchema.safeParse({
...basePayload,
title: "Campaign <script>alert(1)</script>",
description: "This is a valid campaign description that meets the length requirements.",
});
expect(result.success).toBe(false);
});
it("should reject SQL comment sequences in title", () => {
const result1 = createCampaignPayloadSchema.safeParse({
...basePayload,
title: "Campaign -- SQL Injection",
description: "This is a valid campaign description that meets the length requirements.",
});
expect(result1.success).toBe(false);
const result2 = createCampaignPayloadSchema.safeParse({
...basePayload,
title: "Campaign /* SQL Comment */",
description: "This is a valid campaign description that meets the length requirements.",
});
expect(result2.success).toBe(false);
});
it("should reject SQL comment sequences in description", () => {
const result = createCampaignPayloadSchema.safeParse({
...basePayload,
title: "Valid Campaign",
description: "This is a valid campaign description that meets the length requirements. -- SQL injection",
});
expect(result.success).toBe(false);
});
});