@aixyz/cli 0.7.0 → 0.9.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.
@@ -0,0 +1,124 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { escapeHtml, safeJsonEmbed, buildHtml } from "./browser";
3
+
4
+ describe("escapeHtml", () => {
5
+ test("escapes ampersand", () => {
6
+ expect(escapeHtml("a&b")).toBe("a&b");
7
+ });
8
+
9
+ test("escapes less-than", () => {
10
+ expect(escapeHtml("a<b")).toBe("a&lt;b");
11
+ });
12
+
13
+ test("escapes greater-than", () => {
14
+ expect(escapeHtml("a>b")).toBe("a&gt;b");
15
+ });
16
+
17
+ test("escapes double quote", () => {
18
+ expect(escapeHtml('a"b')).toBe("a&quot;b");
19
+ });
20
+
21
+ test("escapes single quote", () => {
22
+ expect(escapeHtml("a'b")).toBe("a&#039;b");
23
+ });
24
+
25
+ test("escapes combined XSS string", () => {
26
+ expect(escapeHtml('<script>alert("xss")</script>')).toBe("&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;");
27
+ });
28
+
29
+ test("returns empty string unchanged", () => {
30
+ expect(escapeHtml("")).toBe("");
31
+ });
32
+
33
+ test("returns plain string unchanged", () => {
34
+ expect(escapeHtml("hello world")).toBe("hello world");
35
+ });
36
+ });
37
+
38
+ describe("safeJsonEmbed", () => {
39
+ test("escapes </script> in strings", () => {
40
+ const result = safeJsonEmbed("</script>");
41
+ expect(result).not.toContain("<");
42
+ expect(result).toContain("\\u003c");
43
+ });
44
+
45
+ test("encodes a simple string", () => {
46
+ expect(safeJsonEmbed("hello")).toBe('"hello"');
47
+ });
48
+
49
+ test("encodes an object", () => {
50
+ const result = safeJsonEmbed({ key: "value" });
51
+ expect(JSON.parse(result)).toEqual({ key: "value" });
52
+ });
53
+
54
+ test("escapes strings containing <", () => {
55
+ const result = safeJsonEmbed("a < b");
56
+ expect(result).not.toContain("<");
57
+ expect(result).toContain("\\u003c");
58
+ });
59
+ });
60
+
61
+ describe("buildHtml", () => {
62
+ const baseParams = {
63
+ registryAddress: "0x1234567890abcdef1234567890abcdef12345678",
64
+ calldata: "0xdeadbeef",
65
+ chainId: 11155111,
66
+ chainName: "sepolia",
67
+ nonce: "test-nonce-123",
68
+ };
69
+
70
+ test("returns valid HTML document", () => {
71
+ const html = buildHtml(baseParams);
72
+ expect(html).toStartWith("<!DOCTYPE html>");
73
+ expect(html).toContain("<html");
74
+ expect(html).toContain("</html>");
75
+ });
76
+
77
+ test("embeds chain name and ID", () => {
78
+ const html = buildHtml(baseParams);
79
+ expect(html).toContain("sepolia");
80
+ expect(html).toContain("11155111");
81
+ });
82
+
83
+ test("embeds registry address", () => {
84
+ const html = buildHtml(baseParams);
85
+ expect(html).toContain(baseParams.registryAddress);
86
+ });
87
+
88
+ test("embeds nonce in result endpoint", () => {
89
+ const html = buildHtml(baseParams);
90
+ expect(html).toContain("test-nonce-123");
91
+ });
92
+
93
+ test("displays URI when provided", () => {
94
+ const html = buildHtml({ ...baseParams, uri: "https://example.com/agent" });
95
+ expect(html).toContain("https://example.com/agent");
96
+ });
97
+
98
+ test("escapes user-provided values in HTML", () => {
99
+ const html = buildHtml({
100
+ ...baseParams,
101
+ chainName: '<script>alert("xss")</script>',
102
+ });
103
+ expect(html).not.toContain('<script>alert("xss")</script>');
104
+ expect(html).toContain("&lt;script&gt;");
105
+ });
106
+
107
+ test("shows 'Register Agent' by default (no mode)", () => {
108
+ const html = buildHtml(baseParams);
109
+ expect(html).toContain("Register Agent");
110
+ expect(html).not.toContain("Update Agent");
111
+ });
112
+
113
+ test("shows 'Register Agent' when mode is 'register'", () => {
114
+ const html = buildHtml({ ...baseParams, mode: "register" });
115
+ expect(html).toContain("Register Agent");
116
+ expect(html).not.toContain("Update Agent");
117
+ });
118
+
119
+ test("shows 'Update Agent' when mode is 'update'", () => {
120
+ const html = buildHtml({ ...baseParams, mode: "update" });
121
+ expect(html).toContain("Update Agent");
122
+ expect(html).not.toContain("Register Agent");
123
+ });
124
+ });