diff --git a/authentication.go b/authentication.go index 057201a..d0475bf 100644 --- a/authentication.go +++ b/authentication.go @@ -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.) diff --git a/authentication_test.go b/authentication_test.go index 2b86764..d213702 100644 --- a/authentication_test.go +++ b/authentication_test.go @@ -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") + } } diff --git a/jira.go b/jira.go index 385b1a3..e8647a7 100644 --- a/jira.go +++ b/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.