(t *testing.T)
| 1206 | } |
| 1207 | |
| 1208 | func TestAuditDocumentCreateUpdateEvents(t *testing.T) { |
| 1209 | rt := createAuditLoggingRestTester(t) |
| 1210 | defer rt.Close() |
| 1211 | |
| 1212 | dbConfig := rt.NewDbConfig() |
| 1213 | dbConfig.Logging = &DbLoggingConfig{ |
| 1214 | Audit: &DbAuditLoggingConfig{ |
| 1215 | Enabled: base.Ptr(true), |
| 1216 | EnabledEvents: base.Ptr([]uint{ |
| 1217 | uint(base.AuditIDDocumentCreate), |
| 1218 | uint(base.AuditIDDocumentUpdate), |
| 1219 | }), |
| 1220 | }, |
| 1221 | } |
| 1222 | if base.TestUseXattrs() { |
| 1223 | // this is not set automatically for CE |
| 1224 | dbConfig.AutoImport = base.Ptr(true) |
| 1225 | } |
| 1226 | |
| 1227 | RequireStatus(t, rt.CreateDatabase("db", dbConfig), http.StatusCreated) |
| 1228 | type testCase struct { |
| 1229 | name string |
| 1230 | setupCode func(t testing.TB, docID string) DocVersion |
| 1231 | auditableCode func(t testing.TB, docID string, docVersion DocVersion) |
| 1232 | documentCreateCount int |
| 1233 | documentUpdateCount int |
| 1234 | } |
| 1235 | testCases := []testCase{ |
| 1236 | { |
| 1237 | name: "create doc", |
| 1238 | auditableCode: func(t testing.TB, docID string, docVersion DocVersion) { |
| 1239 | RequireStatus(t, rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/"+docID, `{"foo": "bar"}`), http.StatusCreated) |
| 1240 | }, |
| 1241 | documentCreateCount: 1, |
| 1242 | }, |
| 1243 | { |
| 1244 | name: "update doc", |
| 1245 | setupCode: func(_ testing.TB, docID string) DocVersion { |
| 1246 | return rt.CreateTestDoc(docID) |
| 1247 | }, |
| 1248 | auditableCode: func(t testing.TB, docID string, docVersion DocVersion) { |
| 1249 | RequireStatus(t, rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/"+docID+"?rev="+docVersion.RevTreeID, `{"foo": "bar"}`), http.StatusCreated) |
| 1250 | }, |
| 1251 | documentUpdateCount: 1, |
| 1252 | }, |
| 1253 | } |
| 1254 | if base.TestUseXattrs() { |
| 1255 | testCases = append(testCases, []testCase{ |
| 1256 | { |
| 1257 | name: "import doc", |
| 1258 | auditableCode: func(t testing.TB, docID string, docVersion DocVersion) { |
| 1259 | importCount := rt.GetDatabase().DbStats.SharedBucketImport().ImportCount.Value() |
| 1260 | _, err := rt.GetSingleDataStore().Add(docID, 0, db.Body{"foo": "bar"}) |
| 1261 | require.NoError(t, err) |
| 1262 | base.RequireWaitForStat(t, func() int64 { |
| 1263 | return rt.GetDatabase().DbStats.SharedBucketImport().ImportCount.Value() |
| 1264 | }, importCount+1) |
| 1265 | }, |
nothing calls this directly
no test coverage detected