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

Function TestEffectiveUserID

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

Source from the content-addressed store, hash-verified

781}
782
783func TestEffectiveUserID(t *testing.T) {
784 tempdir := t.TempDir()
785 base.ResetGlobalTestLogging(t)
786 base.InitializeMemoryLoggers()
787 const (
788 headerUser = "user"
789 headerDomain = "domain"
790 cnfDomain = "myDomain"
791 cnfUser = "bob"
792 realUser = "alice"
793 realDomain = "sgw"
794 )
795 reqHeaders := map[string]string{
796 "user_header": fmt.Sprintf(`{"%s": "%s", "%s":"%s"}`, headerDomain, cnfDomain, headerUser, cnfUser),
797 "Authorization": GetBasicAuthHeader(t, realUser, RestTesterDefaultUserPassword),
798 }
799
800 rt := NewRestTester(t, &RestTesterConfig{
801 GuestEnabled: true,
802 PersistentConfig: true,
803 MutateStartupConfig: func(config *StartupConfig) {
804 config.Unsupported.EffectiveUserHeaderName = base.Ptr("user_header")
805 config.Logging = getAuditLoggingTestConfig(tempdir)
806 require.NoError(t, config.SetupAndValidateLogging(base.TestCtx(t)))
807 },
808 })
809 defer rt.Close()
810 RequireStatus(t, rt.CreateDatabase("db", rt.NewDbConfig()), http.StatusCreated)
811 rt.CreateUser(realUser, nil)
812
813 action := func(t testing.TB) {
814 RequireStatus(t, rt.SendRequestWithHeaders(http.MethodGet, "/{{.db}}/", "", reqHeaders), http.StatusOK)
815 }
816 output := base.AuditLogContents(t, action)
817 events := jsonLines(t, output)
818
819 for _, event := range events {
820 effective := event[base.AuditEffectiveUserID].(map[string]any)
821 assert.Equal(t, cnfDomain, effective[base.AuditFieldEffectiveUserIDDomain])
822 assert.Equal(t, cnfUser, effective[base.AuditFieldEffectiveUserIDUser])
823 realUserEvent := event[base.AuditFieldRealUserID].(map[string]any)
824 assert.Equal(t, realDomain, realUserEvent[base.AuditFieldRealUserIDDomain])
825 assert.Equal(t, realUser, realUserEvent[base.AuditFieldRealUserIDUser])
826 }
827}
828
829func TestAuditDocumentRead(t *testing.T) {
830 rt := createAuditLoggingRestTester(t)

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
CreateDatabaseMethod · 0.95
NewDbConfigMethod · 0.95
CreateUserMethod · 0.95
ResetGlobalTestLoggingFunction · 0.92
InitializeMemoryLoggersFunction · 0.92
PtrFunction · 0.92
TestCtxFunction · 0.92
AuditLogContentsFunction · 0.92
GetBasicAuthHeaderFunction · 0.85
NewRestTesterFunction · 0.85

Tested by

no test coverage detected