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

Function TestAdminAuthWithX509

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

Source from the content-addressed store, hash-verified

436}
437
438func TestAdminAuthWithX509(t *testing.T) {
439 serverURL := base.UnitTestUrl()
440 if !base.ServerIsTLS(serverURL) {
441 t.Skipf("URI %s needs to start with couchbases://", serverURL)
442 }
443 ctx := base.TestCtx(t)
444 tb, caCertPath, certPath, keyPath := setupX509Tests(t, true)
445 defer tb.Close(ctx)
446
447 svrctx := NewServerContext(ctx, &StartupConfig{
448 Bootstrap: BootstrapConfig{
449 Server: serverURL,
450 X509CertPath: certPath,
451 X509KeyPath: keyPath,
452 CACertPath: caCertPath,
453 },
454 }, false)
455 defer svrctx.Close(ctx)
456
457 goCBAgent, err := svrctx.initializeGoCBAgent(ctx)
458 require.NoError(t, err)
459 svrctx.GoCBAgent = goCBAgent
460
461 noX509HttpClient, err := svrctx.initializeNoX509HttpClient(ctx)
462 require.NoError(t, err)
463 svrctx.NoX509HTTPClient = noX509HttpClient
464
465 managementEndpoints, httpClient, err := svrctx.ObtainManagementEndpointsAndHTTPClient()
466 require.NoError(t, err)
467
468 var statusCode int
469 _, statusCode, err = checkAdminAuth(ctx, "", base.TestClusterUsername(), base.TestClusterPassword(), "", httpClient, managementEndpoints, true, []Permission{{"!admin", false}}, nil)
470 assert.NoError(t, err)
471 assert.Equal(t, http.StatusOK, statusCode)
472
473 _, statusCode, err = checkAdminAuth(ctx, "", "invalidUser", "invalidPassword", "", httpClient, managementEndpoints, true, []Permission{{"!admin", false}}, nil)
474 assert.NoError(t, err)
475 assert.Equal(t, http.StatusUnauthorized, statusCode)
476 require.Contains(t, err.Error(), ErrInvalidLogin.Message)
477}
478
479func TestAdminAPIAuth(t *testing.T) {
480 base.LongRunningTest(t)

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
initializeGoCBAgentMethod · 0.95
UnitTestUrlFunction · 0.92
ServerIsTLSFunction · 0.92
TestCtxFunction · 0.92
TestClusterUsernameFunction · 0.92
TestClusterPasswordFunction · 0.92
setupX509TestsFunction · 0.85
NewServerContextFunction · 0.85
checkAdminAuthFunction · 0.85

Tested by

no test coverage detected