MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestDetectSQLInjection

Function TestDetectSQLInjection

internal/waf/injectionutils/utils_sqli_test.go:16–35  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestDetectSQLInjection(t *testing.T) {
17 var a = assert.NewAssertion(t)
18 for _, isStrict := range []bool{true, false} {
19 a.IsTrue(injectionutils.DetectSQLInjection("' UNION SELECT * FROM myTable", isStrict))
20 a.IsTrue(injectionutils.DetectSQLInjection("id=1 ' UNION select * from a", isStrict))
21 a.IsTrue(injectionutils.DetectSQLInjection("asdf asd ; -1' and 1=1 union/* foo */select load_file('/etc/passwd')--", isStrict))
22 a.IsFalse(injectionutils.DetectSQLInjection("' UNION SELECT1 * FROM myTable", isStrict))
23 a.IsFalse(injectionutils.DetectSQLInjection("1234", isStrict))
24 a.IsFalse(injectionutils.DetectSQLInjection("", isStrict))
25 a.IsTrue(injectionutils.DetectSQLInjection("id=123 OR 1=1&b=2", isStrict))
26 a.IsTrue(injectionutils.DetectSQLInjection("id=123&b=456&c=1' or 2=2", isStrict))
27 a.IsFalse(injectionutils.DetectSQLInjection("?", isStrict))
28 a.IsFalse(injectionutils.DetectSQLInjection("/hello?age=22", isStrict))
29 a.IsTrue(injectionutils.DetectSQLInjection("/sql/injection?id=123 or 1=1", isStrict))
30 a.IsTrue(injectionutils.DetectSQLInjection("/sql/injection?id=123%20or%201=1", isStrict))
31 a.IsTrue(injectionutils.DetectSQLInjection("https://example.com/sql/injection?id=123%20or%201=1", isStrict))
32 a.IsTrue(injectionutils.DetectSQLInjection("id=123%20or%201=1", isStrict))
33 a.IsTrue(injectionutils.DetectSQLInjection("https://example.com/' or 1=1", isStrict))
34 }
35}
36
37func BenchmarkDetectSQLInjection(b *testing.B) {
38 runtime.GOMAXPROCS(4)

Callers

nothing calls this directly

Calls 1

DetectSQLInjectionFunction · 0.92

Tested by

no test coverage detected