github.com/ohlinux/git-lfs@v1.5.4/httputil/request_test.go (about)

     1  package httputil
     2  
     3  import (
     4  	"net/http"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  type AuthenticateHeaderTestCase struct {
    11  	ExpectedAuthType string
    12  	Headers          map[string][]string
    13  }
    14  
    15  func (c *AuthenticateHeaderTestCase) Assert(t *testing.T) {
    16  	t.Logf("lfs/httputil: asserting auth type: %q for: %v", c.ExpectedAuthType, c.Headers)
    17  
    18  	assert.Equal(t, c.ExpectedAuthType, GetAuthType(c.HttpResponse()))
    19  }
    20  
    21  func (c *AuthenticateHeaderTestCase) HttpResponse() *http.Response {
    22  	res := &http.Response{Header: make(http.Header)}
    23  
    24  	for k, vv := range c.Headers {
    25  		for _, v := range vv {
    26  			res.Header.Add(k, v)
    27  		}
    28  	}
    29  
    30  	return res
    31  }
    32  
    33  func TestGetAuthType(t *testing.T) {
    34  	for _, c := range []AuthenticateHeaderTestCase{
    35  		{basicAuthType, map[string][]string{}},
    36  		{ntlmAuthType, map[string][]string{"WWW-Authenticate": {"Basic", "NTLM", "Bearer"}}},
    37  		{ntlmAuthType, map[string][]string{"LFS-Authenticate": {"Basic", "NTLM", "Bearer"}}},
    38  		{ntlmAuthType, map[string][]string{"LFS-Authenticate": {"Basic", "Ntlm"}}},
    39  		{ntlmAuthType, map[string][]string{"Www-Authenticate": {"Basic", "Ntlm"}}},
    40  		{ntlmAuthType, map[string][]string{"WWW-Authenticate": {"Basic"},
    41  			"LFS-Authenticate": {"Ntlm"}}},
    42  	} {
    43  		c.Assert(t)
    44  	}
    45  }