Skip to content

Commit

Permalink
Changes ACL clone response to 403 if not authorized, or if token does…
Browse files Browse the repository at this point in the history
…n't exist.

Fixes #1113
  • Loading branch information
slackpad committed Jul 15, 2017
1 parent a61f71d commit efe8fec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 3 additions & 4 deletions agent/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ func (s *HTTPServer) ACLClone(resp http.ResponseWriter, req *http.Request) (inte
return nil, err
}

// Bail if the ACL is not found
// Bail if the ACL is not found, this could be a 404 or a 403, so
// always just return a 403.
if len(out.ACLs) == 0 {
resp.WriteHeader(404)
fmt.Fprint(resp, "Target ACL not found")
return nil, nil
return nil, errPermissionDenied
}

// Create a new ACL
Expand Down
9 changes: 8 additions & 1 deletion agent/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@ func TestACL_Clone(t *testing.T) {

id := makeTestACL(t, a.srv)

req, _ := http.NewRequest("PUT", "/v1/acl/clone/"+id+"?token=root", nil)
req, _ := http.NewRequest("PUT", "/v1/acl/clone/"+id, nil)
resp := httptest.NewRecorder()
_, err := a.srv.ACLClone(resp, req)
if !isPermissionDenied(err) {
t.Fatalf("err: %v", err)
}

req, _ = http.NewRequest("PUT", "/v1/acl/clone/"+id+"?token=root", nil)
resp = httptest.NewRecorder()
obj, err := a.srv.ACLClone(resp, req)
if err != nil {
t.Fatalf("err: %v", err)
Expand Down

0 comments on commit efe8fec

Please sign in to comment.