mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
add tests to test tx delete consistency.
Signed-off-by: Siyuan Zhang <sizhang@google.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/etcd/clientv3"
|
||||
"go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
|
||||
"go.etcd.io/etcd/integration"
|
||||
@@ -55,6 +56,56 @@ func TestUserError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddUserAfterDelete(t *testing.T) {
|
||||
defer testutil.AfterTest(t)
|
||||
|
||||
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
|
||||
defer clus.Terminate(t)
|
||||
|
||||
authapi := clus.RandClient()
|
||||
authSetupRoot(t, authapi.Auth)
|
||||
cfg := clientv3.Config{
|
||||
Endpoints: authapi.Endpoints(),
|
||||
DialTimeout: 5 * time.Second,
|
||||
DialOptions: []grpc.DialOption{grpc.WithBlock()},
|
||||
}
|
||||
cfg.Username, cfg.Password = "root", "123"
|
||||
authed, err := clientv3.New(cfg)
|
||||
require.NoError(t, err)
|
||||
defer authed.Close()
|
||||
|
||||
// add user
|
||||
_, err = authed.UserAdd(context.TODO(), "foo", "bar")
|
||||
require.NoError(t, err)
|
||||
_, err = authapi.Authenticate(context.TODO(), "foo", "bar")
|
||||
require.NoError(t, err)
|
||||
// delete user
|
||||
_, err = authed.UserDelete(context.TODO(), "foo")
|
||||
require.NoError(t, err)
|
||||
if _, err = authed.Authenticate(context.TODO(), "foo", "bar"); err == nil {
|
||||
t.Errorf("expect Authenticate error for old password")
|
||||
}
|
||||
// add user back
|
||||
_, err = authed.UserAdd(context.TODO(), "foo", "bar")
|
||||
require.NoError(t, err)
|
||||
_, err = authed.Authenticate(context.TODO(), "foo", "bar")
|
||||
require.NoError(t, err)
|
||||
// change password
|
||||
_, err = authed.UserChangePassword(context.TODO(), "foo", "bar2")
|
||||
require.NoError(t, err)
|
||||
_, err = authed.UserChangePassword(context.TODO(), "foo", "bar1")
|
||||
require.NoError(t, err)
|
||||
|
||||
if _, err = authed.Authenticate(context.TODO(), "foo", "bar"); err == nil {
|
||||
t.Errorf("expect Authenticate error for old password")
|
||||
}
|
||||
if _, err = authed.Authenticate(context.TODO(), "foo", "bar2"); err == nil {
|
||||
t.Errorf("expect Authenticate error for old password")
|
||||
}
|
||||
_, err = authed.Authenticate(context.TODO(), "foo", "bar1")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestUserErrorAuth(t *testing.T) {
|
||||
defer testutil.AfterTest(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user