mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-14 23:45:03 +02:00
Added tests for new authentication
Fixed some existing tests to work as expected
This commit is contained in:
@ -74,6 +74,29 @@ func TestAuthenticationService_AcquireSessionCookie_Success(t *testing.T) {
|
|||||||
if testClient.Authentication.Authenticated() != true {
|
if testClient.Authentication.Authenticated() != true {
|
||||||
t.Error("Expected true, but result was false")
|
t.Error("Expected true, but result was false")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if testClient.Authentication.authType != authTypeSession {
|
||||||
|
t.Error("Expected authType %d. Got %d", authTypeSession, testClient.Authentication.authType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAuthenticationService_SetBasicAuth(t *testing.T) {
|
||||||
|
// Skip setup() because we don't want a fully setup client
|
||||||
|
testClient = new(Client)
|
||||||
|
|
||||||
|
testClient.Authentication.SetBasicAuth("test-user", "test-password")
|
||||||
|
|
||||||
|
if testClient.Authentication.username != "test-user" {
|
||||||
|
t.Error("Expected username test-user. Got %s", testClient.Authentication.username)
|
||||||
|
}
|
||||||
|
|
||||||
|
if testClient.Authentication.password != "test-password" {
|
||||||
|
t.Error("Expected password test-password. Got %s", testClient.Authentication.password)
|
||||||
|
}
|
||||||
|
|
||||||
|
if testClient.Authentication.authType != authTypeBasic {
|
||||||
|
t.Error("Expected authType %d. Got %d", authTypeBasic, testClient.Authentication.authType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuthenticationService_Authenticated(t *testing.T) {
|
func TestAuthenticationService_Authenticated(t *testing.T) {
|
||||||
|
50
jira_test.go
50
jira_test.go
@ -201,6 +201,7 @@ func TestClient_NewRequest_SessionCookies(t *testing.T) {
|
|||||||
|
|
||||||
cookie := &http.Cookie{Name: "testcookie", Value: "testvalue"}
|
cookie := &http.Cookie{Name: "testcookie", Value: "testvalue"}
|
||||||
c.session = &Session{Cookies: []*http.Cookie{cookie}}
|
c.session = &Session{Cookies: []*http.Cookie{cookie}}
|
||||||
|
c.Authentication.authType = authTypeSession
|
||||||
|
|
||||||
inURL := "rest/api/2/issue/"
|
inURL := "rest/api/2/issue/"
|
||||||
inBody := &Issue{Key: "MESOS"}
|
inBody := &Issue{Key: "MESOS"}
|
||||||
@ -221,6 +222,28 @@ func TestClient_NewRequest_SessionCookies(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_NewRequest_BasicAuth(t *testing.T) {
|
||||||
|
c, err := NewClient(nil, testJIRAInstanceURL)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("An error occured. Expected nil. Got %+v.", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Authentication.SetBasicAuth("test-user", "test-password")
|
||||||
|
|
||||||
|
inURL := "rest/api/2/issue/"
|
||||||
|
inBody := &Issue{Key: "MESOS"}
|
||||||
|
req, err := c.NewRequest("GET", inURL, inBody)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("An error occured. Expected nil. Got %+v.", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
username, password, ok := req.BasicAuth()
|
||||||
|
if !ok || username != "test-user" || password != "test-password" {
|
||||||
|
t.Errorf("An error occured. Expected basic auth username %s and password %s. Got username %s and password %s.", "test-user", "test-password", username, password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If a nil body is passed to gerrit.NewRequest, make sure that nil is also passed to http.NewRequest.
|
// If a nil body is passed to gerrit.NewRequest, make sure that nil is also passed to http.NewRequest.
|
||||||
// In most cases, passing an io.Reader that returns no content is fine,
|
// In most cases, passing an io.Reader that returns no content is fine,
|
||||||
// since there is no difference between an HTTP request body that is an empty string versus one that is not set at all.
|
// since there is no difference between an HTTP request body that is an empty string versus one that is not set at all.
|
||||||
@ -247,6 +270,7 @@ func TestClient_NewMultiPartRequest(t *testing.T) {
|
|||||||
|
|
||||||
cookie := &http.Cookie{Name: "testcookie", Value: "testvalue"}
|
cookie := &http.Cookie{Name: "testcookie", Value: "testvalue"}
|
||||||
c.session = &Session{Cookies: []*http.Cookie{cookie}}
|
c.session = &Session{Cookies: []*http.Cookie{cookie}}
|
||||||
|
c.Authentication.authType = authTypeSession
|
||||||
|
|
||||||
inURL := "rest/api/2/issue/"
|
inURL := "rest/api/2/issue/"
|
||||||
inBuf := bytes.NewBufferString("teststring")
|
inBuf := bytes.NewBufferString("teststring")
|
||||||
@ -271,6 +295,32 @@ func TestClient_NewMultiPartRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_NewMultiPartRequest_BasicAuth(t *testing.T) {
|
||||||
|
c, err := NewClient(nil, testJIRAInstanceURL)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("An error occured. Expected nil. Got %+v.", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Authentication.SetBasicAuth("test-user", "test-password")
|
||||||
|
|
||||||
|
inURL := "rest/api/2/issue/"
|
||||||
|
inBuf := bytes.NewBufferString("teststring")
|
||||||
|
req, err := c.NewMultiPartRequest("GET", inURL, inBuf)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("An error occured. Expected nil. Got %+v.", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
username, password, ok := req.BasicAuth()
|
||||||
|
if !ok || username != "test-user" || password != "test-password" {
|
||||||
|
t.Errorf("An error occured. Expected basic auth username %s and password %s. Got username %s and password %s.", "test-user", "test-password", username, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Header.Get("X-Atlassian-Token") != "nocheck" {
|
||||||
|
t.Errorf("An error occured. Unexpected X-Atlassian-Token header value. Expected nocheck, actual %s.", req.Header.Get("X-Atlassian-Token"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_Do(t *testing.T) {
|
func TestClient_Do(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
Reference in New Issue
Block a user