Skip to content

Commit 38ea4b3

Browse files
committed
Use constants
1 parent 40276c6 commit 38ea4b3

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

library/vulnerabilities/sql-injection/detectSQLInjection.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { basename, join } from "path";
22
import * as t from "tap";
33
import { readFileSync } from "fs";
44
import { escapeStringRegexp } from "../../helpers/escapeStringRegexp";
5-
import { detectSQLInjection } from "./detectSQLInjection";
5+
import {
6+
detectSQLInjection,
7+
SQLInjectionDetectionResult,
8+
} from "./detectSQLInjection";
69
import { SQLDialectClickHouse } from "./dialects/SQLDialectClickHouse";
710
import { SQLDialectGeneric } from "./dialects/SQLDialectGeneric";
811
import { SQLDialectMySQL } from "./dialects/SQLDialectMySQL";
@@ -339,7 +342,7 @@ function isSqlInjection(
339342
for (const dialect of dialects) {
340343
t.same(
341344
detectSQLInjection(sql, input, dialect),
342-
1,
345+
SQLInjectionDetectionResult.INJECTION_DETECTED,
343346
`${sql} (${dialect.constructor.name})`
344347
);
345348
}
@@ -359,7 +362,7 @@ function isNotSqlInjection(
359362
for (const dialect of dialects) {
360363
t.same(
361364
detectSQLInjection(sql, input, dialect),
362-
0,
365+
SQLInjectionDetectionResult.SAFE,
363366
`${sql} (${dialect.constructor.name})`
364367
);
365368
}
@@ -379,7 +382,7 @@ function isTokenizeError(
379382
for (const dialect of dialects) {
380383
t.same(
381384
detectSQLInjection(sql, input, dialect),
382-
3,
385+
SQLInjectionDetectionResult.FAILED_TO_TOKENIZE,
383386
`${sql} (${dialect.constructor.name})`
384387
);
385388
}
@@ -392,12 +395,3 @@ t.test("get human readable name", async () => {
392395
t.same(new SQLDialectSQLite().getHumanReadableName(), "SQLite");
393396
t.same(new SQLDialectClickHouse().getHumanReadableName(), "ClickHouse");
394397
});
395-
396-
t.test("it returns 3 if tokenize fails", async () => {
397-
const result = detectSQLInjection(
398-
"SELECT * FROM users WHERE id = '1",
399-
"id = '1",
400-
new SQLDialectGeneric()
401-
);
402-
t.same(result, 3);
403-
});

0 commit comments

Comments
 (0)