basicauth_test.go 561 B

1234567891011121314151617181920212223242526272829
  1. package auth
  2. import (
  3. "testing"
  4. )
  5. func TestHeaderParsing(t *testing.T) {
  6. // Basic admin:password
  7. authorization := "Basic YWRtaW46cGFzc3dvcmQ="
  8. auth, err := parseAuthHeader(authorization)
  9. if err != nil {
  10. t.Error(err)
  11. }
  12. if auth.Name != "admin" {
  13. t.Errorf("Detected name does not match: '%s'", auth.Name)
  14. }
  15. if auth.Pass != "password" {
  16. t.Errorf("Detected password does not match: '%s'", auth.Pass)
  17. }
  18. }
  19. func TestEmptyHeader(t *testing.T) {
  20. if _, err := parseAuthHeader(""); err == nil {
  21. t.Errorf("Empty headers should generate errors")
  22. }
  23. }