utils_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package rtmp
  2. import "testing"
  3. func Test_secretMatch(t *testing.T) {
  4. tests := []struct {
  5. name string
  6. streamKey string
  7. path string
  8. want bool
  9. }{
  10. {"positive", "abc", "/live/abc", true},
  11. {"negative", "abc", "/live/def", false},
  12. {"positive with numbers", "abc123", "/live/abc123", true},
  13. {"negative with numbers", "abc123", "/live/def456", false},
  14. {"positive with url chars", "one/two/three", "/live/one/two/three", true},
  15. {"negative with url chars", "one/two/three", "/live/four/five/six", false},
  16. {"check the entire secret", "three", "/live/one/two/three", false},
  17. {"with /live/ in secret", "one/live/three", "/live/one/live/three", true},
  18. {"bad path", "anything", "nonsense", false},
  19. {"missing secret", "abc", "/live/", false},
  20. {"missing secret and missing last slash", "abc", "/live", false},
  21. {"streamkey before /live/", "streamkey", "/streamkey/live", false},
  22. {"missing /live/", "anything", "/something/else", false},
  23. {"stuff before and after /live/", "after", "/before/live/after", false},
  24. }
  25. for _, tt := range tests {
  26. t.Run(tt.name, func(t *testing.T) {
  27. if got := secretMatch(tt.streamKey, tt.path); got != tt.want {
  28. t.Errorf("secretMatch() = %v, want %v", got, tt.want)
  29. }
  30. })
  31. }
  32. }