Core components of the web application. https://write.as
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.5 KiB

  1. package logger
  2. import (
  3. "testing"
  4. )
  5. type scrubTest struct {
  6. Input string
  7. Expected string
  8. }
  9. var uris = []scrubTest{
  10. scrubTest{Input: "/1234567890123", Expected: "/[scrubbed]"},
  11. scrubTest{Input: "/acnsd8ndsklao", Expected: "/[scrubbed]"},
  12. scrubTest{Input: "/ACNSD8NDSKLAO", Expected: "/[scrubbed]"},
  13. scrubTest{Input: "/acNsD8NdSKlaO", Expected: "/[scrubbed]"},
  14. scrubTest{Input: "/acnsd8ndsklao.txt", Expected: "/[scrubbed].txt"},
  15. scrubTest{Input: "/8sj2kkjsn192.json", Expected: "/[scrubbed].json"},
  16. scrubTest{Input: "/acnsd8Ndsklao", Expected: "/[scrubbed]"},
  17. scrubTest{Input: "/12345678901", Expected: "/12345678901"},
  18. scrubTest{Input: "GET /8s9dja0vjbklj", Expected: "GET /[scrubbed]"},
  19. scrubTest{Input: "POST /8s9dja0vjbklj?delete=true", Expected: "POST /[scrubbed]?delete=true"},
  20. scrubTest{Input: "GET /8s9dja0vjbkl", Expected: "GET /[scrubbed]"},
  21. scrubTest{Input: "GET /asdf90as.txt", Expected: "GET /asdf90as.txt"},
  22. scrubTest{Input: "GET /api/999999999999", Expected: "GET /api/[scrubbed]"},
  23. scrubTest{Input: "DELETE /api/?id=8s9dja0vjbkl&t=123456789012345678901234567890ab", Expected: "DELETE /api/?id=[scrubbed]&t=[scrubbed]"},
  24. scrubTest{Input: "DELETE /api/8s9dja0vjbkl?t=123456789012345678901234567890ab", Expected: "DELETE /api/[scrubbed]?t=[scrubbed]"},
  25. }
  26. func TestScrubID(t *testing.T) {
  27. var scrubRes string
  28. for i := range uris {
  29. scrubRes = ScrubID(uris[i].Input)
  30. if scrubRes != uris[i].Expected {
  31. t.Errorf("#%d got %v, expected %v", i, scrubRes, uris[i].Expected)
  32. }
  33. }
  34. }