Просмотр исходного кода

Merge pull request #7263 from Rushit/test_isadminpermited

auth: test for AuthStore.IsAdminPermitted
Xiang Li 9 лет назад
Родитель
Сommit
f74142187d
1 измененных файлов с 29 добавлено и 0 удалено
  1. 29 0
      auth/store_test.go

+ 29 - 0
auth/store_test.go

@@ -467,6 +467,35 @@ func TestAuthDisable(t *testing.T) {
 	}
 	}
 }
 }
 
 
+func TestIsAdminPermitted(t *testing.T) {
+	as, tearDown := setupAuthStore(t)
+	defer tearDown(t)
+
+	err := as.IsAdminPermitted(&AuthInfo{Username: "root", Revision: 1})
+	if err != nil {
+		t.Errorf("expected nil, got %v", err)
+	}
+
+	// invalid user
+	err = as.IsAdminPermitted(&AuthInfo{Username: "rooti", Revision: 1})
+	if err != ErrUserNotFound {
+		t.Errorf("expected %v, got %v", ErrUserNotFound, err)
+	}
+
+	// non-admin user
+	err = as.IsAdminPermitted(&AuthInfo{Username: "foo", Revision: 1})
+	if err != ErrPermissionDenied {
+		t.Errorf("expected %v, got %v", ErrPermissionDenied, err)
+	}
+
+	// disabled auth should return nil
+	as.AuthDisable()
+	err = as.IsAdminPermitted(&AuthInfo{Username: "root", Revision: 1})
+	if err != nil {
+		t.Errorf("expected nil, got %v", err)
+	}
+}
+
 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 {