libinjection_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package exprhelpers
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestLibinjectionHelpers(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. function func(params ...any) (any, error)
  10. params []any
  11. expectResult any
  12. }{
  13. {
  14. name: "LibInjectionIsSQLI",
  15. function: LibInjectionIsSQLI,
  16. params: []any{"?__f__73=73&&__f__75=75&delivery=1&max=24.9&min=15.9&n=12&o=2&p=(select(0)from(select(sleep(15)))v)/*'%2B(select(0)from(select(sleep(15)))v)%2B'\x22%2B(select(0)from(select(sleep(15)))v)%2B\x22*/&rating=4"},
  17. expectResult: true,
  18. },
  19. {
  20. name: "LibInjectionIsSQLI - no match",
  21. function: LibInjectionIsSQLI,
  22. params: []any{"?bla=42&foo=bar"},
  23. expectResult: false,
  24. },
  25. {
  26. name: "LibInjectionIsSQLI - no match 2",
  27. function: LibInjectionIsSQLI,
  28. params: []any{"https://foo.com/asdkfj?bla=42&foo=bar"},
  29. expectResult: false,
  30. },
  31. {
  32. name: "LibInjectionIsXSS",
  33. function: LibInjectionIsXSS,
  34. params: []any{"<script>alert('XSS')</script>"},
  35. expectResult: true,
  36. },
  37. {
  38. name: "LibInjectionIsXSS - no match",
  39. function: LibInjectionIsXSS,
  40. params: []any{"?bla=42&foo=bar"},
  41. expectResult: false,
  42. },
  43. {
  44. name: "LibInjectionIsXSS - no match 2",
  45. function: LibInjectionIsXSS,
  46. params: []any{"https://foo.com/asdkfj?bla=42&foo[]=bar&foo"},
  47. expectResult: false,
  48. },
  49. }
  50. for _, test := range tests {
  51. t.Run(test.name, func(t *testing.T) {
  52. result, _ := test.function(test.params...)
  53. assert.Equal(t, test.expectResult, result)
  54. })
  55. }
  56. }