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

Function TestDbConfigCredentials

rest/adminapitest/admin_api_test.go:2839–2869  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2837}
2838
2839func TestDbConfigCredentials(t *testing.T) {
2840 if base.UnitTestUrlIsWalrus() {
2841 t.Skip("This test only works against Couchbase Server")
2842 }
2843
2844 rt := rest.NewRestTesterPersistentConfig(t)
2845 defer rt.Close()
2846
2847 var dbConfig rest.DatabaseConfig
2848 resp := rt.SendAdminRequest(http.MethodGet, "/db/_config", "")
2849 rest.RequireStatus(t, resp, http.StatusOK)
2850 require.NoError(t, base.JSONUnmarshal(resp.Body.Bytes(), &dbConfig))
2851
2852 // non-runtime config, we don't expect to see any credentials present
2853 assert.Equal(t, "", dbConfig.Username)
2854 assert.Equal(t, "", dbConfig.Password)
2855 assert.Equal(t, "", dbConfig.CACertPath)
2856 assert.Equal(t, "", dbConfig.CertPath)
2857 assert.Equal(t, "", dbConfig.KeyPath)
2858
2859 resp = rt.SendAdminRequest(http.MethodGet, "/db/_config?include_runtime=true", "")
2860 rest.RequireStatus(t, resp, http.StatusOK)
2861 require.NoError(t, base.JSONUnmarshal(resp.Body.Bytes(), &dbConfig))
2862
2863 // runtime config, we expect to see the credentials used by the database (either bootstrap or per-db - but in this case, bootstrap)
2864 assert.Equal(t, base.TestClusterUsername(), dbConfig.Username)
2865 assert.Equal(t, base.RedactedStr, dbConfig.Password)
2866 assert.Equal(t, "", dbConfig.CACertPath)
2867 assert.Equal(t, "", dbConfig.CertPath)
2868 assert.Equal(t, "", dbConfig.KeyPath)
2869}
2870
2871func TestInvalidDBConfig(t *testing.T) {
2872 rt := rest.NewRestTesterPersistentConfig(t)

Callers

nothing calls this directly

Calls 8

UnitTestUrlIsWalrusFunction · 0.92
RequireStatusFunction · 0.92
JSONUnmarshalFunction · 0.92
TestClusterUsernameFunction · 0.92
SendAdminRequestMethod · 0.80
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected