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

Function TestRedactConfigAsStr

rest/audit_test.go:708–781  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

706}
707
708func TestRedactConfigAsStr(t *testing.T) {
709 testCases := []struct {
710 name string
711 input string
712 expected string
713 hasError bool
714 }{
715 {
716 name: "empty",
717 input: "",
718 expected: "",
719 hasError: true,
720 },
721 {
722 name: "simple",
723 input: `{"key":"value"}`,
724 expected: `{"key":"value"}`,
725 },
726 {
727 name: "dbConfig",
728 input: string(base.MustJSONMarshal(t, DbConfig{})),
729 expected: `{}`,
730 },
731 {
732 name: "dbConfig with password",
733 input: string(base.MustJSONMarshal(t, DbConfig{
734 BucketConfig: BucketConfig{
735 Password: "password",
736 },
737 })),
738 expected: `{"password":"xxxxx"}`,
739 },
740 {
741 name: "dbConfig with password and username",
742 input: string(base.MustJSONMarshal(t, DbConfig{
743 Users: map[string]*auth.PrincipalConfig{
744 "alice": {
745 Password: base.Ptr("password1"),
746 },
747 "bob": {
748 Password: base.Ptr("password2"),
749 },
750 },
751 })),
752 expected: `{"users":{"alice":{"password":"xxxxx"},"bob":{"password":"xxxxx"}}}`,
753 },
754 {
755 name: "dbConfig with replication username and password",
756 input: string(base.MustJSONMarshal(t, DbConfig{
757 Replications: map[string]*db.ReplicationConfig{
758 "replication1": &db.ReplicationConfig{
759 Username: "alice1",
760 Password: "password1",
761 RemotePassword: "hunter2",
762 },
763 },
764 })),
765 expected: `{"replications":{"replication1":{"replication_id":"","remote":"","username":"alice1","password":"xxxxx","remote_password":"xxxxx","direction":"","continuous":false}}}`,

Callers

nothing calls this directly

Calls 6

MustJSONMarshalFunction · 0.92
PtrFunction · 0.92
TestCtxFunction · 0.92
redactConfigAsStrFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected