MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestAdminAuth

Function TestAdminAuth

rest/admin_api_auth_test.go:292–436  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

290}
291
292func TestAdminAuth(t *testing.T) {
293 if base.UnitTestUrlIsWalrus() {
294 t.Skip("Test requires Couchbase Server")
295 }
296
297 rt := NewRestTester(t, nil)
298 defer rt.Close()
299
300 BucketFullAccessRoleTest := fmt.Sprintf("bucket_full_access[%s]", rt.Bucket().GetName())
301 clusterAdminPermission := Permission{"!admin", false}
302 bucketWritePermission := Permission{"!write", true}
303
304 testCases := []struct {
305 Name string
306 Username string
307 Password string
308 Operation string
309 CheckPermissions []Permission
310 ResponsePermissions []Permission
311 ExpectedStatusCode int
312 ExpectedPermResults map[string]bool
313 CreateUser string
314 CreatePassword string
315 CreateRoles []string
316 BucketName string
317 }{
318 {
319 Name: "ClusterAdmin",
320 Username: base.TestClusterUsername(),
321 Password: base.TestClusterPassword(),
322 CheckPermissions: []Permission{clusterAdminPermission},
323 ExpectedStatusCode: http.StatusOK,
324 BucketName: "",
325 },
326 {
327 Name: "ClusterAdminWrongPassword",
328 Username: "ClusterAdminWrongPassword",
329 Password: "wrongpassword",
330 CheckPermissions: []Permission{clusterAdminPermission},
331 ExpectedStatusCode: http.StatusUnauthorized,
332 CreateUser: "ClusterAdminWrongPassword",
333 CreatePassword: "password",
334 CreateRoles: []string{"admin"},
335 BucketName: "",
336 },
337 {
338 Name: "NoUser",
339 Username: "IDontExist",
340 Password: "password",
341 CheckPermissions: []Permission{clusterAdminPermission},
342 ExpectedStatusCode: http.StatusUnauthorized,
343 BucketName: "",
344 },
345 {
346 Name: "MissingPermissionAndRole",
347 Username: "MissingPermissionAndRole",
348 Password: "password",
349 CheckPermissions: []Permission{clusterAdminPermission},

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
BucketMethod · 0.95
ContextMethod · 0.95
GetDatabaseMethod · 0.95
ServerContextMethod · 0.95
RunMethod · 0.95
UnitTestUrlIsWalrusFunction · 0.92
TestClusterUsernameFunction · 0.92
TestClusterPasswordFunction · 0.92
TestCtxFunction · 0.92
NewRestTesterFunction · 0.85
MakeUserFunction · 0.85

Tested by

no test coverage detected