Ensure internal properties aren't being incorrectly stored in revision cache
(t *testing.T)
| 580 | |
| 581 | // Ensure internal properties aren't being incorrectly stored in revision cache |
| 582 | func TestRevisionCacheInternalProperties(t *testing.T) { |
| 583 | |
| 584 | db, ctx := setupTestDB(t) |
| 585 | defer db.Close(ctx) |
| 586 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 587 | |
| 588 | // Invalid _revisions property will be stripped. Should also not be present in the rev cache. |
| 589 | rev1body := Body{ |
| 590 | "value": 1234, |
| 591 | BodyRevisions: "unexpected data", |
| 592 | } |
| 593 | rev1id, _, err := collection.Put(ctx, "doc1", rev1body) |
| 594 | assert.NoError(t, err, "Put") |
| 595 | |
| 596 | // Get the raw document directly from the bucket, validate _revisions property isn't found |
| 597 | var bucketBody Body |
| 598 | _, err = collection.dataStore.Get("doc1", &bucketBody) |
| 599 | require.NoError(t, err) |
| 600 | _, ok := bucketBody[BodyRevisions] |
| 601 | if ok { |
| 602 | t.Error("_revisions property still present in document retrieved directly from bucket.") |
| 603 | } |
| 604 | |
| 605 | // Get the doc while still resident in the rev cache w/ history=false, validate _revisions property isn't found |
| 606 | body, err := collection.Get1xRevBody(ctx, "doc1", rev1id, false, nil) |
| 607 | assert.NoError(t, err, "Get1xRevBody") |
| 608 | badRevisions, ok := body[BodyRevisions] |
| 609 | if ok { |
| 610 | t.Errorf("_revisions property still present in document retrieved from rev cache: %s", badRevisions) |
| 611 | } |
| 612 | |
| 613 | // Get the doc while still resident in the rev cache w/ history=true, validate _revisions property is returned with expected |
| 614 | // properties ("start", "ids") |
| 615 | bodyWithHistory, err := collection.Get1xRevBody(ctx, "doc1", rev1id, true, nil) |
| 616 | assert.NoError(t, err, "Get1xRevBody") |
| 617 | validRevisions, ok := bodyWithHistory[BodyRevisions] |
| 618 | if !ok { |
| 619 | t.Errorf("Expected _revisions property not found in document retrieved from rev cache: %s", validRevisions) |
| 620 | } |
| 621 | |
| 622 | validRevisionsMap, ok := validRevisions.(Revisions) |
| 623 | require.True(t, ok) |
| 624 | _, startOk := validRevisionsMap[RevisionsStart] |
| 625 | assert.True(t, startOk) |
| 626 | _, idsOk := validRevisionsMap[RevisionsIds] |
| 627 | assert.True(t, idsOk) |
| 628 | } |
| 629 | |
| 630 | func TestBypassRevisionCache(t *testing.T) { |
| 631 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD) |
nothing calls this directly
no test coverage detected