Skip to content

Commit

Permalink
use Unauthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Lin committed Jul 31, 2018
1 parent fc2a600 commit 2ac5683
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/server/handler_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func createNetworkHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
if !ok {
response.Forbidden(req.Request, resp.ResponseWriter, fmt.Errorf("User ID is empty"))
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func createNetworkHandler(ctx *web.Context) {
if err != nil {
switch err {
case mgo.ErrNotFound:
response.Forbidden(req.Request, resp.ResponseWriter, err)
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized"))
return
default:
response.InternalServerError(req.Request, resp.ResponseWriter, err)
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func createPodHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
if !ok {
response.Forbidden(req.Request, resp.ResponseWriter, fmt.Errorf("User ID is empty"))
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
}

Expand Down Expand Up @@ -61,7 +61,7 @@ func createPodHandler(ctx *web.Context) {
if err != nil {
switch err {
case mgo.ErrNotFound:
response.Forbidden(req.Request, resp.ResponseWriter, err)
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized"))
return
default:
response.InternalServerError(req.Request, resp.ResponseWriter, err)
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func createServiceHandler(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
if !ok {
response.Forbidden(req.Request, resp.ResponseWriter, fmt.Errorf("User ID is empty"))
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
}

Expand Down Expand Up @@ -62,7 +62,7 @@ func createServiceHandler(ctx *web.Context) {
if err != nil {
switch err {
case mgo.ErrNotFound:
response.Forbidden(req.Request, resp.ResponseWriter, err)
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized"))
return
default:
response.InternalServerError(req.Request, resp.ResponseWriter, err)
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func signInUserHandler(ctx *web.Context) {
if err != nil {
switch err {
case mgo.ErrNotFound:
response.Forbidden(req.Request, resp.ResponseWriter, fmt.Errorf("Failed to login. Incorrect authentication credentials"))
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: Failed to login. Incorrect authentication credentials"))
return
default:
response.InternalServerError(req.Request, resp.ResponseWriter, err)
Expand All @@ -100,7 +100,7 @@ func signInUserHandler(ctx *web.Context) {

// when authenticating not pass
if !passed {
response.Forbidden(req.Request, resp.ResponseWriter, fmt.Errorf("Failed to login. Incorrect authentication credentials"))
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: Failed to login. Incorrect authentication credentials"))
return
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/handler_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (suite *UserTestSuite) TestSignInFailedUser() {
httpRequest.Header.Add("Content-Type", "application/json")
httpWriter := httptest.NewRecorder()
suite.wc.Dispatch(httpWriter, httpRequest)
assertResponseCode(suite.T(), http.StatusForbidden, httpWriter)
assertResponseCode(suite.T(), http.StatusUnauthorized, httpWriter)
}

func (suite *UserTestSuite) TestCreateUser() {
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func createVolume(ctx *web.Context) {
sp, req, resp := ctx.ServiceProvider, ctx.Request, ctx.Response
uuid, ok := req.Attribute("UserID").(string)
if !ok {
response.Forbidden(req.Request, resp.ResponseWriter, fmt.Errorf("User ID is empty"))
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized: User ID is empty"))
return
}

Expand Down Expand Up @@ -57,7 +57,7 @@ func createVolume(ctx *web.Context) {
if err != nil {
switch err {
case mgo.ErrNotFound:
response.Forbidden(req.Request, resp.ResponseWriter, err)
response.Unauthorized(req.Request, resp.ResponseWriter, fmt.Errorf("Unauthorized"))
return
default:
response.InternalServerError(req.Request, resp.ResponseWriter, err)
Expand Down

0 comments on commit 2ac5683

Please sign in to comment.