Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions channels/log_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func (rv *RevAndVersion) UnmarshalJSON(data []byte) error {

// CV returns ver@src in big endian format 1@cbl for CBL format.
func (rv RevAndVersion) CV() string {
if rv.CurrentSource == "" || rv.CurrentVersion == "" {
return ""
}
// this should match db.Version.String()
return strconv.FormatUint(base.HexCasToUint64(rv.CurrentVersion), 16) + "@" + rv.CurrentSource
}
Expand Down
8 changes: 4 additions & 4 deletions db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,17 +984,17 @@ func (c *DatabaseCollection) processForEachDocIDResults(ctx context.Context, cal
found = results.Next(ctx, &viewRow)
if found {
docid = viewRow.Key
revid = viewRow.Value.RevID.RevTreeID
cv = viewRow.Value.RevID.CV()
revid = viewRow.Value.Rev.RevTreeID
cv = viewRow.Value.Rev.CV()
seq = viewRow.Value.Sequence
channels = viewRow.Value.Channels
}
} else {
found = results.Next(ctx, &queryRow)
if found {
docid = queryRow.Id
revid = queryRow.RevID.RevTreeID
cv = queryRow.RevID.CV()
revid = queryRow.Rev.RevTreeID
cv = queryRow.Rev.CV()
seq = queryRow.Sequence
channels = make([]string, 0)
// Query returns all channels, but we only want to return active channels
Expand Down
7 changes: 7 additions & 0 deletions db/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ func (sd *SyncData) GetRevTreeID() string {
return sd.RevAndVersion.RevTreeID
}

func (sd *SyncData) CV() string {
if sd == nil {
return ""
}
return sd.RevAndVersion.CV()
}

// determine set of current channels based on removal entries.
func (sd *SyncData) getCurrentChannels() base.Set {
ch := base.SetOf()
Expand Down
4 changes: 2 additions & 2 deletions db/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,15 @@ func (context *DatabaseContext) QueryAllRoles(ctx context.Context, startKey stri
type AllDocsViewQueryRow struct {
Key string
Value struct {
RevID channels.RevAndVersion `json:"r"`
Rev channels.RevAndVersion `json:"r"`
Sequence uint64 `json:"s"`
Channels []string `json:"c"`
}
}

type AllDocsIndexQueryRow struct {
Id string
RevID channels.RevAndVersion `json:"r"`
Rev channels.RevAndVersion `json:"r"`
Sequence uint64 `json:"s"`
Channels channels.ChannelMap `json:"c"`
}
Expand Down
7 changes: 0 additions & 7 deletions docs/api/components/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,6 @@ show_exp:
schema:
type: boolean
description: Whether to show the expiry property (`_exp`) in the response.
show_cv:
name: show_cv
in: query
required: false
schema:
type: boolean
description: Output the Current Version in the response as property `_cv`.
startkey:
name: startkey
in: query
Expand Down
1 change: 0 additions & 1 deletion docs/api/paths/admin/keyspace-_all_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ get:
- $ref: ../../components/parameters.yaml#/startkey
- $ref: ../../components/parameters.yaml#/endkey
- $ref: ../../components/parameters.yaml#/limit-result-rows
- $ref: ../../components/parameters.yaml#/show_cv
responses:
'200':
$ref: ../../components/responses.yaml#/all-docs
Expand Down
1 change: 0 additions & 1 deletion docs/api/paths/admin/keyspace-_bulk_get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ post:
description: If this header includes `gzip` then the the HTTP response will be compressed. This takes priority over `X-Accept-Part-Encoding`. Only part compression will be done if `X-Accept-Part-Encoding=gzip` and the `User-Agent` is below 1.2 due to clients not being able to handle full compression.
schema:
type: string
- $ref: ../../components/parameters.yaml#/show_cv
requestBody:
content:
application/json:
Expand Down
1 change: 0 additions & 1 deletion docs/api/paths/public/keyspace-_all_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ get:
- $ref: ../../components/parameters.yaml#/startkey
- $ref: ../../components/parameters.yaml#/endkey
- $ref: ../../components/parameters.yaml#/limit-result-rows
- $ref: ../../components/parameters.yaml#/show_cv
responses:
'200':
$ref: ../../components/responses.yaml#/all-docs
Expand Down
1 change: 0 additions & 1 deletion docs/api/paths/public/keyspace-_bulk_get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ post:
description: If this header includes `gzip` then the the HTTP response will be compressed. This takes priority over `X-Accept-Part-Encoding`. Only part compression will be done if `X-Accept-Part-Encoding=gzip` and the `User-Agent` is below 1.2 due to clients not being able to handle full compression.
schema:
type: string
- $ref: ../../components/parameters.yaml#/show_cv
requestBody:
content:
application/json:
Expand Down
35 changes: 18 additions & 17 deletions rest/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,20 @@ func TestForceAPIForbiddenErrors(t *testing.T) {
})
}
}
func TestBulkDocsChangeToAccess(t *testing.T) {

// TestBulkDocsChangeToAccess verifies that access() grants from one doc in a single bulk_docs request apply to subsequent docs in the same batch.
func TestBulkDocsChangeToAccess(t *testing.T) {
base.SetUpTestLogging(t, base.LevelInfo, base.KeyAccess)

rtConfig := RestTesterConfig{SyncFn: `function(doc) {if(doc.type == "setaccess") {channel(doc.channel); access(doc.owner, doc.channel);} else { requireAccess(doc.channel)}}`}
rtConfig := RestTesterConfig{SyncFn: `
function(doc) {
if(doc.type == "setaccess") {
channel(doc.channel);
access(doc.owner, doc.channel);
} else {
requireAccess(doc.channel);
}
}`}
rt := NewRestTesterDefaultCollection(t, &rtConfig)
defer rt.Close()

Expand All @@ -518,17 +527,18 @@ func TestBulkDocsChangeToAccess(t *testing.T) {
assert.NoError(t, a.Save(user))

input := `{"docs": [{"_id": "bulk1", "type" : "setaccess", "owner":"user1" , "channel":"chan1"}, {"_id": "bulk2" , "channel":"chan1"}]}`

response := rt.SendUserRequest("POST", "/db/_bulk_docs", input, "user1")
RequireStatus(t, response, 201)

var docs []interface{}
require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &docs))
assert.Len(t, docs, 2)
assert.Equal(t, map[string]interface{}{"rev": "1-afbcffa8a4641a0f4dd94d3fc9593e74", "id": "bulk1"}, docs[0])

assert.Equal(t, map[string]interface{}{"rev": "1-4d79588b9fe9c38faae61f0c1b9471c0", "id": "bulk2"}, docs[1])

require.Len(t, docs, 2)
assert.NotContains(t, response.BodyString(), `missing channel access`)
assert.NotContains(t, response.BodyString(), `"status":403"`)
assert.Contains(t, response.BodyString(), `"id":"bulk1"`)
assert.Contains(t, response.BodyString(), `"rev":"1-afbcffa8a4641a0f4dd94d3fc9593e74"`)
assert.Contains(t, response.BodyString(), `"id":"bulk2"`)
assert.Contains(t, response.BodyString(), `"rev":"1-4d79588b9fe9c38faae61f0c1b9471c0"`)
}

// Test _all_docs API call under different security scenarios
Expand Down Expand Up @@ -1154,15 +1164,6 @@ func TestAllDocsCV(t *testing.T) {
{
name: "no query string",
url: "/{{.keyspace}}/_all_docs",
output: fmt.Sprintf(`{
"total_rows": 1,
"update_seq": 1,
"rows": [{"key": "%s", "id": "%s", "value": {"rev": "%s"}}]
}`, docID, docID, docVersion.RevTreeID),
},
{
name: "cvs=true",
url: "/{{.keyspace}}/_all_docs?show_cv=true",
output: fmt.Sprintf(`{
"total_rows": 1,
"update_seq": 1,
Expand Down
11 changes: 9 additions & 2 deletions rest/adminapitest/admin_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2229,8 +2229,15 @@ func TestHandleGetRevTree(t *testing.T) {

resp := rt.SendAdminRequest(http.MethodPost, "/{{.keyspace}}/_bulk_docs", reqBodyJson)
rest.RequireStatus(t, resp, http.StatusCreated)
respBodyExpected := `[{"id":"foo","rev":"1-123"},{"id":"foo","rev":"1-456"},{"id":"foo","rev":"1-789"}]`
assert.Equal(t, respBodyExpected, resp.Body.String())
// Response now includes unpredictable CV values - just validate ids and revs...
// It's likely this test will be removed in 4.0, or shortly after, since we're never allowing new conflicts to be created
var bulkDocsResp []map[string]interface{}
require.NoError(t, json.Unmarshal(resp.BodyBytes(), &bulkDocsResp))
require.Len(t, bulkDocsResp, 3)
for _, d := range bulkDocsResp {
assert.Equal(t, "foo", d["id"])
assert.Truef(t, strings.HasPrefix(d["rev"].(string), "1-"), "expected rev to start with '1-', got %s", d["rev"])
}

// Get the revision tree of the user foo
resp = rt.SendAdminRequest(http.MethodGet, "/{{.keyspace}}/_revtree/foo", "")
Expand Down
Loading
Loading