smithy

ref: 6edaab44f7cac0f66498294b0e05d4eeaf2c2565

pkg/go-git-http/auth/basicauth_test.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package auth

import (
	"testing"
)

func TestHeaderParsing(t *testing.T) {
	// Basic admin:password
	authorization := "Basic YWRtaW46cGFzc3dvcmQ="

	auth, err := parseAuthHeader(authorization)
	if err != nil {
		t.Error(err)
	}

	if auth.Name != "admin" {
		t.Errorf("Detected name does not match: '%s'", auth.Name)
	}
	if auth.Pass != "password" {
		t.Errorf("Detected password does not match: '%s'", auth.Pass)
	}
}

func TestEmptyHeader(t *testing.T) {
	if _, err := parseAuthHeader(""); err == nil {
		t.Errorf("Empty headers should generate errors")
	}
}