2015-01-06 18:40:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestACL_CreateDestroy(t *testing.T) {
|
2015-05-08 17:27:24 +00:00
|
|
|
t.Parallel()
|
2015-06-13 21:51:30 +00:00
|
|
|
c, s := makeACLClient(t)
|
2015-03-03 02:18:38 +00:00
|
|
|
defer s.Stop()
|
2015-01-06 23:26:50 +00:00
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
acl := c.ACL()
|
|
|
|
|
|
|
|
ae := ACLEntry{
|
|
|
|
Name: "API test",
|
|
|
|
Type: ACLClientType,
|
|
|
|
Rules: `key "" { policy = "deny" }`,
|
|
|
|
}
|
|
|
|
|
|
|
|
id, wm, err := acl.Create(&ae, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wm.RequestTime == 0 {
|
|
|
|
t.Fatalf("bad: %v", wm)
|
|
|
|
}
|
|
|
|
|
|
|
|
if id == "" {
|
|
|
|
t.Fatalf("invalid: %v", id)
|
|
|
|
}
|
|
|
|
|
|
|
|
ae2, _, err := acl.Info(id, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ae2.Name != ae.Name || ae2.Type != ae.Type || ae2.Rules != ae.Rules {
|
|
|
|
t.Fatalf("Bad: %#v", ae2)
|
|
|
|
}
|
|
|
|
|
|
|
|
wm, err = acl.Destroy(id, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wm.RequestTime == 0 {
|
|
|
|
t.Fatalf("bad: %v", wm)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestACL_CloneDestroy(t *testing.T) {
|
2015-05-08 17:27:24 +00:00
|
|
|
t.Parallel()
|
2015-06-13 21:51:30 +00:00
|
|
|
c, s := makeACLClient(t)
|
2015-03-03 02:18:38 +00:00
|
|
|
defer s.Stop()
|
2015-01-06 23:26:50 +00:00
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
acl := c.ACL()
|
|
|
|
|
2015-06-13 21:51:30 +00:00
|
|
|
id, wm, err := acl.Clone(c.config.Token, nil)
|
2015-01-06 18:40:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wm.RequestTime == 0 {
|
|
|
|
t.Fatalf("bad: %v", wm)
|
|
|
|
}
|
|
|
|
|
|
|
|
if id == "" {
|
|
|
|
t.Fatalf("invalid: %v", id)
|
|
|
|
}
|
|
|
|
|
|
|
|
wm, err = acl.Destroy(id, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wm.RequestTime == 0 {
|
|
|
|
t.Fatalf("bad: %v", wm)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestACL_Info(t *testing.T) {
|
2015-05-08 17:27:24 +00:00
|
|
|
t.Parallel()
|
2015-06-13 21:51:30 +00:00
|
|
|
c, s := makeACLClient(t)
|
2015-03-03 02:18:38 +00:00
|
|
|
defer s.Stop()
|
2015-01-06 23:26:50 +00:00
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
acl := c.ACL()
|
|
|
|
|
2015-06-13 21:51:30 +00:00
|
|
|
ae, qm, err := acl.Info(c.config.Token, nil)
|
2015-01-06 18:40:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if qm.LastIndex == 0 {
|
|
|
|
t.Fatalf("bad: %v", qm)
|
|
|
|
}
|
|
|
|
if !qm.KnownLeader {
|
|
|
|
t.Fatalf("bad: %v", qm)
|
|
|
|
}
|
|
|
|
|
2015-06-13 21:51:30 +00:00
|
|
|
if ae == nil || ae.ID != c.config.Token || ae.Type != ACLManagementType {
|
2015-01-06 18:40:00 +00:00
|
|
|
t.Fatalf("bad: %#v", ae)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestACL_List(t *testing.T) {
|
2015-05-08 17:27:24 +00:00
|
|
|
t.Parallel()
|
2015-06-13 21:51:30 +00:00
|
|
|
c, s := makeACLClient(t)
|
2015-03-03 02:18:38 +00:00
|
|
|
defer s.Stop()
|
2015-01-06 23:26:50 +00:00
|
|
|
|
2015-01-06 18:40:00 +00:00
|
|
|
acl := c.ACL()
|
|
|
|
|
|
|
|
acls, qm, err := acl.List(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(acls) < 2 {
|
|
|
|
t.Fatalf("bad: %v", acls)
|
|
|
|
}
|
|
|
|
|
|
|
|
if qm.LastIndex == 0 {
|
|
|
|
t.Fatalf("bad: %v", qm)
|
|
|
|
}
|
|
|
|
if !qm.KnownLeader {
|
|
|
|
t.Fatalf("bad: %v", qm)
|
|
|
|
}
|
|
|
|
}
|