mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-14 23:45:03 +02:00
Adding basic auth and accompanying tests
This commit is contained in:
44
jira_test.go
44
jira_test.go
@ -451,3 +451,47 @@ func TestClient_Do_PagingInfoEmptyByDefault(t *testing.T) {
|
||||
t.Errorf("StartAt not equal to 0")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasicAuthTransport(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
username, password := "username", "password"
|
||||
|
||||
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
u, p, ok := r.BasicAuth()
|
||||
if !ok {
|
||||
t.Errorf("request does not contain basic auth credentials")
|
||||
}
|
||||
if u != username {
|
||||
t.Errorf("request contained basic auth username %q, want %q", u, username)
|
||||
}
|
||||
if p != password {
|
||||
t.Errorf("request contained basic auth password %q, want %q", p, password)
|
||||
}
|
||||
})
|
||||
|
||||
tp := &BasicAuthTransport{
|
||||
Username: username,
|
||||
Password: password,
|
||||
}
|
||||
basicAuthClient, _ := NewClient(tp.Client(), "/")
|
||||
req, _ := basicAuthClient.NewRequest("GET", ".", nil)
|
||||
basicAuthClient.Do(req, nil)
|
||||
}
|
||||
|
||||
func TestBasicAuthTransport_transport(t *testing.T) {
|
||||
// default transport
|
||||
tp := &BasicAuthTransport{}
|
||||
if tp.transport() != http.DefaultTransport {
|
||||
t.Errorf("Expected http.DefaultTransport to be used.")
|
||||
}
|
||||
|
||||
// custom transport
|
||||
tp = &BasicAuthTransport{
|
||||
Transport: &http.Transport{},
|
||||
}
|
||||
if tp.transport() == http.DefaultTransport {
|
||||
t.Errorf("Expected custom transport to be used.")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user