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

Function TestBucketCredentialsValidation

rest/config_test.go:2554–2668  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2552}
2553
2554func TestBucketCredentialsValidation(t *testing.T) {
2555 bucketCredsError := "bucket_credentials cannot use both x509 and basic auth"
2556 bucketNoCredsServerless := "at least 1 bucket must be defined in bucket_credentials when running in serverless mode"
2557 testCases := []struct {
2558 name string
2559 startupConfig StartupConfig
2560 expectedError *string
2561 }{
2562 {
2563 name: "No credentials provided",
2564 startupConfig: StartupConfig{},
2565 },
2566 {
2567 name: "Valid bucket using x509",
2568 startupConfig: StartupConfig{
2569 BucketCredentials: base.PerBucketCredentialsConfig{"bucket": &base.CredentialsConfig{CredentialsConfigX509: base.CredentialsConfigX509{X509CertPath: "cert", X509KeyPath: "key"}}},
2570 },
2571 },
2572 {
2573 name: "Valid bucket using basic auth",
2574 startupConfig: StartupConfig{
2575 BucketCredentials: base.PerBucketCredentialsConfig{"bucket": &base.CredentialsConfig{Username: "uname", Password: "pass"}}},
2576 },
2577 {
2578 name: "Valid database using basic auth",
2579 startupConfig: StartupConfig{
2580 DatabaseCredentials: PerDatabaseCredentialsConfig{"db": &base.CredentialsConfig{Username: "uname", Password: "pword"}},
2581 },
2582 },
2583 {
2584 name: "Blank database and filled bucket creds provided",
2585 startupConfig: StartupConfig{
2586 DatabaseCredentials: PerDatabaseCredentialsConfig{},
2587 BucketCredentials: base.PerBucketCredentialsConfig{"bucket": &base.CredentialsConfig{CredentialsConfigX509: base.CredentialsConfigX509{X509CertPath: "cert", X509KeyPath: "key"}}},
2588 },
2589 },
2590 {
2591 name: "Filled database and blank bucket creds provided",
2592 startupConfig: StartupConfig{
2593 BucketCredentials: base.PerBucketCredentialsConfig{},
2594 DatabaseCredentials: PerDatabaseCredentialsConfig{"bucket": &base.CredentialsConfig{CredentialsConfigX509: base.CredentialsConfigX509{X509CertPath: "cert", X509KeyPath: "key"}}},
2595 },
2596 },
2597 {
2598 name: "Database and bucket creds provided",
2599 startupConfig: StartupConfig{
2600 DatabaseCredentials: PerDatabaseCredentialsConfig{"bucket": &base.CredentialsConfig{CredentialsConfigX509: base.CredentialsConfigX509{X509CertPath: "cert", X509KeyPath: "key"}}},
2601 BucketCredentials: base.PerBucketCredentialsConfig{"bucket": &base.CredentialsConfig{CredentialsConfigX509: base.CredentialsConfigX509{X509CertPath: "cert", X509KeyPath: "key"}}},
2602 },
2603 },
2604 {
2605 name: "Bucket creds for x509 and basic auth",
2606 startupConfig: StartupConfig{
2607 BucketCredentials: base.PerBucketCredentialsConfig{"bucket": &base.CredentialsConfig{CredentialsConfigX509: base.CredentialsConfigX509{X509CertPath: "cert", X509KeyPath: "key"}, Username: "uname", Password: "pword"}},
2608 },
2609 expectedError: &bucketCredsError,
2610 },
2611 {

Callers

nothing calls this directly

Calls 7

PtrFunction · 0.92
TestCtxFunction · 0.92
IsEnterpriseEditionFunction · 0.92
RunMethod · 0.65
ContainsMethod · 0.65
ValidateMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected