1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-01-05 22:53:53 +02:00

Removes check for statuscode as jiraclient already does it. Adds test for nonok status code returned

This commit is contained in:
Bidesh Thapaliya 2016-09-27 12:18:30 +02:00
parent 435fdb84eb
commit d3ec8f16c0
2 changed files with 37 additions and 3 deletions

View File

@ -133,9 +133,6 @@ func (s *AuthenticationService) GetCurrentUser() (*Session, error) {
if err != nil {
return nil, fmt.Errorf("Error sending request to get user info : %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Getting user info failed with status : %d", resp.StatusCode)
}
defer resp.Body.Close()
ret := new(Session)

View File

@ -86,6 +86,43 @@ func TestAuthenticationService_Authenticated(t *testing.T) {
}
}
func TestAuthenticationService_GetUserInfo_NonOkStatusCode_Fail(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/auth/1/session", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
testMethod(t, r, "POST")
testRequestURL(t, r, "/rest/auth/1/session")
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("Error in read body: %s", err)
}
if bytes.Index(b, []byte(`"username":"foo"`)) < 0 {
t.Error("No username found")
}
if bytes.Index(b, []byte(`"password":"bar"`)) < 0 {
t.Error("No password found")
}
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"}}`)
}
if r.Method == "GET" {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/auth/1/session")
w.WriteHeader(http.StatusForbidden)
}
})
testClient.Authentication.AcquireSessionCookie("foo", "bar")
_, err := testClient.Authentication.GetCurrentUser()
if err == nil {
t.Errorf("Non nil error expect, recieved nil")
}
}
func TestAuthenticationService_GetUserInfo_FailWithoutLogin(t *testing.T) {
// no setup() required here
testClient = new(Client)