git-lfs/httputil/request_test.go

46 lines
1.2 KiB
Go
Raw Normal View History

package httputil
import (
"net/http"
"testing"
2016-07-18 19:10:56 +00:00
"github.com/stretchr/testify/assert"
)
2016-07-18 19:10:56 +00:00
type AuthenticateHeaderTestCase struct {
ExpectedAuthType string
Headers map[string][]string
}
2016-07-18 19:10:56 +00:00
func (c *AuthenticateHeaderTestCase) Assert(t *testing.T) {
2016-07-21 17:07:46 +00:00
t.Logf("lfs/httputil: asserting auth type: %q for: %v", c.ExpectedAuthType, c.Headers)
2016-07-18 19:10:56 +00:00
assert.Equal(t, c.ExpectedAuthType, GetAuthType(c.HttpResponse()))
}
2016-07-18 19:10:56 +00:00
func (c *AuthenticateHeaderTestCase) HttpResponse() *http.Response {
res := &http.Response{Header: make(http.Header)}
2016-07-18 19:10:56 +00:00
for k, vv := range c.Headers {
for _, v := range vv {
res.Header.Add(k, v)
}
}
2016-07-18 19:10:56 +00:00
return res
}
2016-07-18 19:10:56 +00:00
func TestGetAuthType(t *testing.T) {
for _, c := range []AuthenticateHeaderTestCase{
2016-07-21 17:07:46 +00:00
{basicAuthType, map[string][]string{}},
{ntlmAuthType, map[string][]string{"WWW-Authenticate": {"Basic", "NTLM", "Bearer"}}},
{ntlmAuthType, map[string][]string{"LFS-Authenticate": {"Basic", "NTLM", "Bearer"}}},
{ntlmAuthType, map[string][]string{"LFS-Authenticate": {"Basic", "Ntlm"}}},
{ntlmAuthType, map[string][]string{"Www-Authenticate": {"Basic", "Ntlm"}}},
{ntlmAuthType, map[string][]string{"WWW-Authenticate": {"Basic"},
2016-07-18 19:10:56 +00:00
"LFS-Authenticate": {"Ntlm"}}},
} {
c.Assert(t)
}
}