@@ -25,6 +25,12 @@ import (
2525 "github.com/stretchr/testify/require"
2626)
2727
28+ type allDocsResponse struct {
29+ TotalRows int `json:"total_rows"`
30+ Offset int `json:"offset"`
31+ Rows []allDocsRow `json:"rows"`
32+ }
33+
2834func TestPublicChanGuestAccess (t * testing.T ) {
2935 rt := NewRestTester (t ,
3036 & RestTesterConfig {
@@ -70,17 +76,6 @@ func TestStarAccess(t *testing.T) {
7076
7177 base .SetUpTestLogging (t , base .LevelDebug , base .KeyChanges )
7278
73- type allDocsRow struct {
74- ID string `json:"id"`
75- Key string `json:"key"`
76- Value struct {
77- Rev string `json:"rev"`
78- Channels []string `json:"channels,omitempty"`
79- Access map [string ]base.Set `json:"access,omitempty"` // for admins only
80- } `json:"value"`
81- Doc db.Body `json:"doc,omitempty"`
82- Error string `json:"error"`
83- }
8479 var allDocsResult struct {
8580 TotalRows int `json:"total_rows"`
8681 Offset int `json:"offset"`
@@ -552,23 +547,6 @@ func TestAllDocsAccessControl(t *testing.T) {
552547 rt := NewRestTester (t , & RestTesterConfig {SyncFn : channels .DocChannelsSyncFunction })
553548 defer rt .Close ()
554549
555- type allDocsRow struct {
556- ID string `json:"id"`
557- Key string `json:"key"`
558- Value struct {
559- Rev string `json:"rev"`
560- Channels []string `json:"channels,omitempty"`
561- Access map [string ]base.Set `json:"access,omitempty"` // for admins only
562- } `json:"value"`
563- Doc db.Body `json:"doc,omitempty"`
564- Error string `json:"error"`
565- }
566- type allDocsResponse struct {
567- TotalRows int `json:"total_rows"`
568- Offset int `json:"offset"`
569- Rows []allDocsRow `json:"rows"`
570- }
571-
572550 // Create some docs:
573551 a := auth .NewAuthenticator (rt .MetadataStore (), nil , rt .GetDatabase ().AuthenticatorOptions (rt .Context ()))
574552 a .Collections = rt .GetDatabase ().CollectionNames
@@ -708,13 +686,13 @@ func TestAllDocsAccessControl(t *testing.T) {
708686 assert .Equal (t , []string {"Cinemax" }, allDocsResult .Rows [0 ].Value .Channels )
709687 assert .Equal (t , "doc1" , allDocsResult .Rows [1 ].Key )
710688 assert .Equal (t , "forbidden" , allDocsResult .Rows [1 ].Error )
711- assert .Equal (t , "" , allDocsResult .Rows [1 ].Value . Rev )
689+ assert .Nil (t , allDocsResult .Rows [1 ].Value )
712690 assert .Equal (t , "doc3" , allDocsResult .Rows [2 ].ID )
713691 assert .Equal (t , []string {"Cinemax" }, allDocsResult .Rows [2 ].Value .Channels )
714692 assert .Equal (t , "1-20912648f85f2bbabefb0993ddd37b41" , allDocsResult .Rows [2 ].Value .Rev )
715693 assert .Equal (t , "b0gus" , allDocsResult .Rows [3 ].Key )
716694 assert .Equal (t , "not_found" , allDocsResult .Rows [3 ].Error )
717- assert .Equal (t , "" , allDocsResult .Rows [3 ].Value . Rev )
695+ assert .Nil (t , allDocsResult .Rows [3 ].Value )
718696
719697 // Check GET to _all_docs with keys parameter:
720698 response = rt .SendUserRequest (http .MethodGet , "/{{.keyspace}}/_all_docs?channels=true&keys=%5B%22doc4%22%2C%22doc1%22%2C%22doc3%22%2C%22b0gus%22%5D" , "" , "alice" )
@@ -1178,3 +1156,43 @@ func TestPublicChannel(t *testing.T) {
11781156 response = rt .SendUserRequest ("GET" , "/{{.keyspace}}/privateDoc" , "" , "user1" )
11791157 RequireStatus (t , response , 403 )
11801158}
1159+
1160+ func TestAllDocsCV (t * testing.T ) {
1161+ rt := NewRestTesterPersistentConfig (t )
1162+ defer rt .Close ()
1163+
1164+ const docID = "foo"
1165+ docVersion := rt .PutDocDirectly (docID , db.Body {"foo" : "bar" })
1166+
1167+ testCases := []struct {
1168+ name string
1169+ url string
1170+ output string
1171+ }{
1172+ {
1173+ name : "no query string" ,
1174+ url : "/{{.keyspace}}/_all_docs" ,
1175+ output : fmt .Sprintf (`{
1176+ "total_rows": 1,
1177+ "update_seq": 1,
1178+ "rows": [{"key": "%s", "id": "%s", "value": {"rev": "%s"}}]
1179+ }` , docID , docID , docVersion .RevTreeID ),
1180+ },
1181+ {
1182+ name : "cvs=true" ,
1183+ url : "/{{.keyspace}}/_all_docs?show_cv=true" ,
1184+ output : fmt .Sprintf (`{
1185+ "total_rows": 1,
1186+ "update_seq": 1,
1187+ "rows": [{"key": "%s", "id": "%s", "value": {"rev": "%s", "cv": "%s"}}]
1188+ }` , docID , docID , docVersion .RevTreeID , docVersion .CV .String ()),
1189+ },
1190+ }
1191+ for _ , testCase := range testCases {
1192+ t .Run (testCase .name , func (t * testing.T ) {
1193+ response := rt .SendAdminRequest (http .MethodGet , testCase .url , "" )
1194+ RequireStatus (t , response , http .StatusOK )
1195+ require .JSONEq (t , testCase .output , response .Body .String ())
1196+ })
1197+ }
1198+ }
0 commit comments