2015-01-06 18:40:00 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-06-30 20:58:55 +00:00
|
|
|
func TestAPI_ACL_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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:58:55 +00:00
|
|
|
func TestAPI_ACL_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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:58:55 +00:00
|
|
|
func TestAPI_ACL_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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:58:55 +00:00
|
|
|
func TestAPI_ACL_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)
|
|
|
|
}
|
|
|
|
}
|
2017-04-24 21:39:50 +00:00
|
|
|
|
2017-06-30 20:58:55 +00:00
|
|
|
func TestAPI_ACL_Replication(t *testing.T) {
|
2017-04-24 21:39:50 +00:00
|
|
|
t.Parallel()
|
|
|
|
c, s := makeACLClient(t)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
acl := c.ACL()
|
|
|
|
|
|
|
|
repl, qm, err := acl.Replication(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if repl == nil {
|
|
|
|
t.Fatalf("bad: %v", repl)
|
|
|
|
}
|
|
|
|
|
|
|
|
if repl.Running {
|
|
|
|
t.Fatal("bad: repl should not be running")
|
|
|
|
}
|
|
|
|
|
|
|
|
if repl.Enabled {
|
|
|
|
t.Fatal("bad: repl should not be enabled")
|
|
|
|
}
|
|
|
|
|
|
|
|
if qm.RequestTime == 0 {
|
|
|
|
t.Fatalf("bad: %v", qm)
|
|
|
|
}
|
|
|
|
}
|