mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-03-19 20:57:47 +02:00
Moved Authentication() test into AuthenticationService, and add test case to validate it operates correctly
This commit is contained in:
parent
2bc0c88214
commit
bc5e20fe93
@ -63,6 +63,15 @@ func (s *AuthenticationService) AcquireSessionCookie(username, password string)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Authenticated reports if the current Client has an authenticated session with JIRA
|
||||
func (s *AuthenticationService) Authenticated() bool {
|
||||
if s != nil {
|
||||
return s.client.session != nil
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Missing API Call GET (Returns information about the currently authenticated user's session)
|
||||
// See https://docs.atlassian.com/jira/REST/latest/#auth/1/session
|
||||
// TODO Missing API Call DELETE (Logs the current user out of JIRA, destroying the existing session, if any.)
|
||||
|
@ -36,6 +36,10 @@ func TestAcquireSessionCookie_Fail(t *testing.T) {
|
||||
if res == true {
|
||||
t.Error("Expected error, but result was true")
|
||||
}
|
||||
|
||||
if testClient.Authentication.Authenticated() != false {
|
||||
t.Error("Expected false, but result was true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAcquireSessionCookie_Success(t *testing.T) {
|
||||
@ -58,6 +62,11 @@ func TestAcquireSessionCookie_Success(t *testing.T) {
|
||||
fmt.Fprint(w, `{"session":{"name":"JSESSIONID","value":"12345678901234567890"},"loginInfo":{"failedLoginCount":10,"loginCount":127,"lastFailedLoginTime":"2016-03-16T04:22:35.386+0000","previousLoginTime":"2016-03-16T04:22:35.386+0000"}}`)
|
||||
})
|
||||
|
||||
// Test before we've attempted to authenticate
|
||||
if testClient.Authentication.Authenticated() != false {
|
||||
t.Error("Expected false, but result was true")
|
||||
}
|
||||
|
||||
res, err := testClient.Authentication.AcquireSessionCookie("foo", "bar")
|
||||
if err != nil {
|
||||
t.Errorf("No error expected. Got %s", err)
|
||||
@ -65,4 +74,8 @@ func TestAcquireSessionCookie_Success(t *testing.T) {
|
||||
if res == false {
|
||||
t.Error("Expected result was true. Got false")
|
||||
}
|
||||
|
||||
if testClient.Authentication.Authenticated() != true {
|
||||
t.Error("Expected true, but result was false")
|
||||
}
|
||||
}
|
||||
|
16
jira.go
16
jira.go
@ -164,14 +164,14 @@ func (c *Client) DoNoClose(req *http.Request, v interface{}) (*http.Response, er
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// Authenticated reports if the current Client has an authenticated session with JIRA
|
||||
func (c *Client) Authenticated() bool {
|
||||
if c != nil {
|
||||
return c.session != nil
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
//// Authenticated reports if the current Client has an authenticated session with JIRA
|
||||
//func (c *Client) Authenticated() bool {
|
||||
// if c != nil {
|
||||
// return c.session != nil
|
||||
// } else {
|
||||
// return false
|
||||
// }
|
||||
//}
|
||||
|
||||
// CheckResponse checks the API response for errors, and returns them if present.
|
||||
// A response is considered an error if it has a status code outside the 200 range.
|
||||
|
Loading…
x
Reference in New Issue
Block a user