MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestGuestReadOnly

Function TestGuestReadOnly

rest/doc_api_test.go:140–178  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func TestGuestReadOnly(t *testing.T) {
141 rt := NewRestTester(t, &RestTesterConfig{
142 GuestEnabled: true,
143 DatabaseConfig: &DatabaseConfig{DbConfig: DbConfig{
144 Unsupported: &db.UnsupportedOptions{
145 GuestReadOnly: true,
146 },
147 },
148 }},
149 )
150 defer rt.Close()
151
152 const docID = "doc"
153
154 // Write a document as admin
155 response := rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/"+docID, `{"val": "test"}`)
156 RequireStatus(t, response, http.StatusCreated)
157
158 // Attempt to read as guest
159 body := rt.GetDocBody(docID)
160 assert.Equal(t, "test", body["val"].(string))
161 rev := body["_rev"].(string)
162
163 // Attempt to write as guest
164 response = rt.SendRequest(http.MethodPut, "/{{.keyspace}}/doc?rev="+rev, `{"val": "newval"}`)
165 RequireStatus(t, response, http.StatusForbidden)
166
167 // Attempt to access _blipsync as guest - blip sync handling for read-only GUEST is applied at replication level (to allow pull-only replications).
168 // Should succeed permission check, and only fail on websocket upgrade
169 response = rt.SendRequest(http.MethodGet, "/{{.db}}/_blipsync", "")
170 RequireStatus(t, response, http.StatusUpgradeRequired)
171
172 // Verify matching on _blipsync path doesn't incorrectly match docs, attachments
173 response = rt.SendRequest(http.MethodPut, "/{{.keyspace}}/doc_named_blipsync", "")
174 RequireStatus(t, response, http.StatusForbidden)
175 response = rt.SendRequest(http.MethodPut, "/{{.keyspace}}/doc/_blipsync", "")
176 RequireStatus(t, response, http.StatusForbidden)
177
178}
179
180func TestGetDocWithCV(t *testing.T) {
181 rt := NewRestTesterPersistentConfig(t)

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.95
SendAdminRequestMethod · 0.95
GetDocBodyMethod · 0.95
SendRequestMethod · 0.95
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected