(t *testing.T)
| 781 | } |
| 782 | |
| 783 | func 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 | |
| 829 | func TestAuditDocumentRead(t *testing.T) { |
| 830 | rt := createAuditLoggingRestTester(t) |
nothing calls this directly
no test coverage detected