mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
auth: add a test case for recoverying from snapshot
This commit is contained in:
parent
6fb99a8585
commit
280b65fe4d
@ -496,6 +496,41 @@ func TestIsAdminPermitted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRecoverFromSnapshot(t *testing.T) {
|
||||||
|
as, _ := setupAuthStore(t)
|
||||||
|
|
||||||
|
ua := &pb.AuthUserAddRequest{Name: "foo"}
|
||||||
|
_, err := as.UserAdd(ua) // add an existing user
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err)
|
||||||
|
}
|
||||||
|
if err != ErrUserAlreadyExist {
|
||||||
|
t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ua = &pb.AuthUserAddRequest{Name: ""}
|
||||||
|
_, err = as.UserAdd(ua) // add a user with empty name
|
||||||
|
if err != ErrUserEmpty {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
as.Close()
|
||||||
|
|
||||||
|
as2 := NewAuthStore(as.be, dummyIndexWaiter)
|
||||||
|
|
||||||
|
if !as2.isAuthEnabled() {
|
||||||
|
t.Fatal("recovering authStore from existing backend failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
ul, err := as.UserList(&pb.AuthUserListRequest{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !contains(ul.Users, "root") {
|
||||||
|
t.Errorf("expected %v in %v", "root", ul.Users)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func contains(array []string, str string) bool {
|
func contains(array []string, str string) bool {
|
||||||
for _, s := range array {
|
for _, s := range array {
|
||||||
if s == str {
|
if s == str {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user