-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-4617: Add DisablePublicAllDocs db config option #7540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+158
−69
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cf93418
Add DisablePublicAllDocs db config option
bbrks 992d3ee
Add deprecation warning
bbrks 15a49d8
Add OpenAPI entry for disable_public_all_docs db config
bbrks d0a9a56
Add test
bbrks 2fe2d7e
Share allDocsResponse structs for tests
bbrks 6999a77
Reword guidance for _all_docs and the disable config option
bbrks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2025-Present Couchbase, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included | ||
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified | ||
// in that file, in accordance with the Business Source License, use of this | ||
// software will be governed by the Apache License, Version 2.0, included in | ||
// the file licenses/APL2.txt. | ||
|
||
package rest | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/couchbase/sync_gateway/base" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDisablePublicAllDocs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
disablePublicAllDocs *bool | ||
expectedPublicStatus int | ||
expectedPublicError string | ||
}{ | ||
{ | ||
name: "default", | ||
disablePublicAllDocs: nil, | ||
expectedPublicStatus: http.StatusOK, | ||
}, | ||
{ | ||
name: "disabled", | ||
disablePublicAllDocs: base.Ptr(true), | ||
expectedPublicStatus: http.StatusForbidden, | ||
expectedPublicError: "public access to _all_docs is disabled for this database", | ||
}, | ||
{ | ||
name: "enabled", | ||
disablePublicAllDocs: base.Ptr(false), | ||
expectedPublicStatus: http.StatusOK, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
rtConfig := RestTesterConfig{ | ||
DatabaseConfig: &DatabaseConfig{ | ||
DbConfig: DbConfig{ | ||
DisablePublicAllDocs: test.disablePublicAllDocs, | ||
}, | ||
}, | ||
} | ||
rt := NewRestTester(t, &rtConfig) | ||
defer rt.Close() | ||
|
||
rt.CreateUser("user1", nil) | ||
rt.CreateTestDoc("doc1") | ||
rt.CreateTestDoc("doc2") | ||
|
||
t.Run("public", func(t *testing.T) { | ||
response := rt.SendUserRequest("GET", "/{{.keyspace}}/_all_docs", "", "user1") | ||
RequireStatus(t, response, test.expectedPublicStatus) | ||
if test.expectedPublicError != "" { | ||
require.Contains(t, response.Body.String(), test.expectedPublicError) | ||
} | ||
}) | ||
|
||
t.Run("admin", func(t *testing.T) { | ||
response := rt.SendAdminRequest("GET", "/{{.keyspace}}/_all_docs", "") | ||
RequireStatus(t, response, http.StatusOK) | ||
var result allDocsResponse | ||
require.NoError(t, json.Unmarshal(response.Body.Bytes(), &result)) | ||
assert.Equal(t, 2, len(result.Rows)) | ||
assert.Equal(t, "doc1", result.Rows[0].ID) | ||
assert.Equal(t, "doc2", result.Rows[1].ID) | ||
}) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.