Skip to content

Commit

Permalink
add test for policy name endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
abaez committed Mar 14, 2020
1 parent e20f98f commit 40054e2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions agent/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@ func TestACL_HTTP(t *testing.T) {
require.True(t, ok)
require.Equal(t, policyMap[idMap["policy-read-all-nodes"]], policy)
})

t.Run("Read Name", func(t *testing.T) {
policyName := "policy-read-all-nodes"
req, _ := http.NewRequest("GET", "/v1/acl/policy/name/"+policyName+"?token=root", nil)
resp := httptest.NewRecorder()
raw, err := a.srv.ACLPolicyCRUD(resp, req)
require.NoError(t, err)
policy, ok := raw.(*structs.ACLPolicy)
require.True(t, ok)
require.Equal(t, policyMap[idMap[policyName]], policy)
})
})

t.Run("Role", func(t *testing.T) {
Expand Down
39 changes: 39 additions & 0 deletions agent/consul/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,45 @@ func TestACLEndpoint_PolicyRead(t *testing.T) {
}
}

func TestACLEndpoint_PolicyReadByName(t *testing.T) {
t.Parallel()
dir1, s1 := testServerWithConfig(t, func(c *Config) {
c.ACLDatacenter = "dc1"
c.ACLsEnabled = true
c.ACLMasterToken = "root"
})
defer os.RemoveAll(dir1)
defer s1.Shutdown()
codec := rpcClient(t, s1)
defer codec.Close()

testrpc.WaitForLeader(t, s1.RPC, "dc1")

policy, err := upsertTestPolicy(codec, "root", "dc1")
if err != nil {
t.Fatalf("err: %v", err)
}

acl := ACL{srv: s1}

req := structs.ACLPolicyGetRequest{
Datacenter: "dc1",
PolicyName: policy.Name,
QueryOptions: structs.QueryOptions{Token: "root"},
}

resp := structs.ACLPolicyResponse{}

err = acl.PolicyRead(&req, &resp)
if err != nil {
t.Fatalf("err: %v", err)
}

if !reflect.DeepEqual(resp.Policy, policy) {
t.Fatalf("tokens are not equal: %v != %v", resp.Policy, policy)
}
}

func TestACLEndpoint_PolicyBatchRead(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 40054e2

Please sign in to comment.