|
1 | 1 | // Import Node.js Dependencies |
2 | | -import { test } from "node:test"; |
| 2 | +import { test, describe } from "node:test"; |
3 | 3 | import assert from "node:assert"; |
4 | 4 |
|
5 | 5 | // Import Internal Dependencies |
@@ -78,50 +78,35 @@ test("should not throw any warnings without hexadecimal value (and should call a |
78 | 78 | assert.strictEqual(astNode.value, "hello world!"); |
79 | 79 | }); |
80 | 80 |
|
81 | | -test("should detect shady link when an URL is bit.ly", () => { |
82 | | - const str = "const foo = 'http://bit.ly/foo'"; |
83 | | - const ast = parseScript(str); |
84 | | - const sastAnalysis = getSastAnalysis(isLiteral).execute(ast.body); |
85 | | - |
86 | | - assert.strictEqual(sastAnalysis.warnings().length, 1); |
87 | | - const warning = sastAnalysis.getWarning("shady-link"); |
88 | | - assert.strictEqual(warning.value, "http://bit.ly/foo"); |
89 | | -}); |
90 | | - |
91 | | -test("should detect shady link when an URL is ipinfo.io when protocol is http", () => { |
92 | | - const str = "const foo = 'http://ipinfo.io/json'"; |
93 | | - const ast = parseScript(str); |
94 | | - const sastAnalysis = getSastAnalysis(isLiteral).execute(ast.body); |
95 | | - assert.strictEqual(sastAnalysis.warnings().length, 1); |
96 | | - const warning = sastAnalysis.getWarning("shady-link"); |
97 | | - assert.strictEqual(warning.value, "http://ipinfo.io/json"); |
98 | | -}); |
99 | | - |
100 | | -test("should detect shady link when an URL is ipinfo.io when protocol is https", () => { |
101 | | - const str = "const foo = 'https://ipinfo.io/json'"; |
102 | | - const ast = parseScript(str); |
103 | | - const sastAnalysis = getSastAnalysis(isLiteral).execute(ast.body); |
104 | | - assert.strictEqual(sastAnalysis.warnings().length, 1); |
105 | | - const warning = sastAnalysis.getWarning("shady-link"); |
106 | | - assert.strictEqual(warning.value, "https://ipinfo.io/json"); |
107 | | -}); |
108 | | - |
109 | | -test("should detect shady link when an URL is httpbin.org when protocol is http", () => { |
110 | | - const str = "const foo = 'http://httpbin.org/ip'"; |
111 | | - const ast = parseScript(str); |
112 | | - const sastAnalysis = getSastAnalysis(isLiteral).execute(ast.body); |
113 | | - assert.strictEqual(sastAnalysis.warnings().length, 1); |
114 | | - const warning = sastAnalysis.getWarning("shady-link"); |
115 | | - assert.strictEqual(warning.value, "http://httpbin.org/ip"); |
116 | | -}); |
117 | | - |
118 | | -test("should detect shady link when an URL is httpbin.org when protocol is https", () => { |
119 | | - const str = "const foo = 'https://httpbin.org/ip'"; |
120 | | - const ast = parseScript(str); |
121 | | - const sastAnalysis = getSastAnalysis(isLiteral).execute(ast.body); |
122 | | - assert.strictEqual(sastAnalysis.warnings().length, 1); |
123 | | - const warning = sastAnalysis.getWarning("shady-link"); |
124 | | - assert.strictEqual(warning.value, "https://httpbin.org/ip"); |
| 81 | +describe("known suspicious domain", () => { |
| 82 | + const suspiciousDomains = [ |
| 83 | + "bit.ly/foo", |
| 84 | + "ipinfo.io/json", |
| 85 | + "httpbin.org/ip", |
| 86 | + "api.ipify.org/ip" |
| 87 | + ]; |
| 88 | + |
| 89 | + test("should detect shady link when an URL is known to be suspicious when protocol is http", () => { |
| 90 | + for (const suspicousDomain of suspiciousDomains) { |
| 91 | + const str = `const foo = 'http://${suspicousDomain}'`; |
| 92 | + const ast = parseScript(str); |
| 93 | + const sastAnalysis = getSastAnalysis(isLiteral).execute(ast.body); |
| 94 | + assert.strictEqual(sastAnalysis.warnings().length, 1); |
| 95 | + const warning = sastAnalysis.getWarning("shady-link"); |
| 96 | + assert.strictEqual(warning.value, `http://${suspicousDomain}`); |
| 97 | + } |
| 98 | + }); |
| 99 | + |
| 100 | + test("should detect shady link when an URL is known to be suspicious when protocol is https", () => { |
| 101 | + for (const suspicousDomain of suspiciousDomains) { |
| 102 | + const str = `const foo = 'https://${suspicousDomain}'`; |
| 103 | + const ast = parseScript(str); |
| 104 | + const sastAnalysis = getSastAnalysis(isLiteral).execute(ast.body); |
| 105 | + assert.strictEqual(sastAnalysis.warnings().length, 1); |
| 106 | + const warning = sastAnalysis.getWarning("shady-link"); |
| 107 | + assert.strictEqual(warning.value, `https://${suspicousDomain}`); |
| 108 | + } |
| 109 | + }); |
125 | 110 | }); |
126 | 111 |
|
127 | 112 | test("should detect shady link when an URL has a suspicious domain", () => { |
|
0 commit comments