@@ -2,7 +2,10 @@ import { basename, join } from "path";
22import * as t from "tap" ;
33import { readFileSync } from "fs" ;
44import { escapeStringRegexp } from "../../helpers/escapeStringRegexp" ;
5- import { detectSQLInjection } from "./detectSQLInjection" ;
5+ import {
6+ detectSQLInjection ,
7+ SQLInjectionDetectionResult ,
8+ } from "./detectSQLInjection" ;
69import { SQLDialectClickHouse } from "./dialects/SQLDialectClickHouse" ;
710import { SQLDialectGeneric } from "./dialects/SQLDialectGeneric" ;
811import { 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