Browse Source

integration: add a test case for non authorized RPCs

This commit add a new test case which ensures that non authorized RPCs
failed with ErrUserEmpty. The case can happen in a schedule like
below:
1. create a cluster
2. create clients
3. enable authentication of the cluster
4. the clients issue RPCs

Fix https://github.com/coreos/etcd/issues/7770
Hitoshi Mitake 8 years ago
parent
commit
6fe2249bcd
1 changed files with 22 additions and 0 deletions
  1. 22 0
      integration/v3_auth_test.go

+ 22 - 0
integration/v3_auth_test.go

@@ -270,3 +270,25 @@ func authSetupRoot(t *testing.T, auth pb.AuthClient) {
 		t.Fatal(err)
 	}
 }
+
+func TestV3AuthNonAuthorizedRPCs(t *testing.T) {
+	defer testutil.AfterTest(t)
+	clus := NewClusterV3(t, &ClusterConfig{Size: 1})
+	defer clus.Terminate(t)
+
+	nonAuthedKV := clus.Client(0).KV
+
+	key := "foo"
+	val := "bar"
+	_, err := nonAuthedKV.Put(context.TODO(), key, val)
+	if err != nil {
+		t.Fatalf("couldn't put key (%v)", err)
+	}
+
+	authSetupRoot(t, toGRPC(clus.Client(0)).Auth)
+
+	respput, err := nonAuthedKV.Put(context.TODO(), key, val)
+	if !eqErrGRPC(err, rpctypes.ErrGRPCUserEmpty) {
+		t.Fatalf("could put key (%v), it should cause an error of permission denied", respput)
+	}
+}