Browse Source

e2e: enhance the test case of auth disabling

Hitoshi Mitake 9 years ago
parent
commit
745e1e2cf9
1 changed files with 39 additions and 0 deletions
  1. 39 0
      e2e/ctl_v3_auth_test.go

+ 39 - 0
e2e/ctl_v3_auth_test.go

@@ -52,9 +52,44 @@ func ctlV3AuthEnable(cx ctlCtx) error {
 }
 }
 
 
 func authDisableTest(cx ctlCtx) {
 func authDisableTest(cx ctlCtx) {
+	// a key that isn't granted to test-user
+	if err := ctlV3Put(cx, "hoo", "a", ""); err != nil {
+		cx.t.Fatal(err)
+	}
+
+	if err := authEnable(cx); err != nil {
+		cx.t.Fatal(err)
+	}
+
+	cx.user, cx.pass = "root", "root"
+	authSetupTestUser(cx)
+
+	// test-user doesn't have the permission, it must fail
+	cx.user, cx.pass = "test-user", "pass"
+	if err := ctlV3PutFailPerm(cx, "hoo", "bar"); err != nil {
+		cx.t.Fatal(err)
+	}
+
+	cx.user, cx.pass = "root", "root"
 	if err := ctlV3AuthDisable(cx); err != nil {
 	if err := ctlV3AuthDisable(cx); err != nil {
 		cx.t.Fatalf("authDisableTest ctlV3AuthDisable error (%v)", err)
 		cx.t.Fatalf("authDisableTest ctlV3AuthDisable error (%v)", err)
 	}
 	}
+
+	// now auth fails unconditionally, note that failed RPC is Authenticate(), not Put()
+	cx.user, cx.pass = "test-user", "pass"
+	if err := ctlV3PutFailAuthDisabled(cx, "hoo", "bar"); err != nil {
+		cx.t.Fatal(err)
+	}
+
+	// now the key can be accessed
+	cx.user, cx.pass = "", ""
+	if err := ctlV3Put(cx, "hoo", "bar", ""); err != nil {
+		cx.t.Fatal(err)
+	}
+	// confirm put succeeded
+	if err := ctlV3Get(cx, []string{"hoo"}, []kv{{"hoo", "bar"}}...); err != nil {
+		cx.t.Fatal(err)
+	}
 }
 }
 
 
 func ctlV3AuthDisable(cx ctlCtx) error {
 func ctlV3AuthDisable(cx ctlCtx) error {
@@ -282,6 +317,10 @@ func ctlV3PutFailPerm(cx ctlCtx, key, val string) error {
 	return spawnWithExpect(append(cx.PrefixArgs(), "put", key, val), "permission denied")
 	return spawnWithExpect(append(cx.PrefixArgs(), "put", key, val), "permission denied")
 }
 }
 
 
+func ctlV3PutFailAuthDisabled(cx ctlCtx, key, val string) error {
+	return spawnWithExpect(append(cx.PrefixArgs(), "put", key, val), "authentication is not enabled")
+}
+
 func ctlV3GetFailPerm(cx ctlCtx, key string) error {
 func ctlV3GetFailPerm(cx ctlCtx, key string) error {
 	return spawnWithExpect(append(cx.PrefixArgs(), "get", key), "permission denied")
 	return spawnWithExpect(append(cx.PrefixArgs(), "get", key), "permission denied")
 }
 }