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

Function TestForceAPIForbiddenErrors

rest/access_test.go:300–498  ·  view source on GitHub ↗

CBG-2143: Make sure the REST API is returning forbidden errors if when unsupported config option is set

(t *testing.T)

Source from the content-addressed store, hash-verified

298
299// CBG-2143: Make sure the REST API is returning forbidden errors if when unsupported config option is set
300func TestForceAPIForbiddenErrors(t *testing.T) {
301 base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD, base.KeyHTTP)
302 testCases := []struct {
303 forceForbiddenErrors bool
304 }{
305 {
306 forceForbiddenErrors: true,
307 },
308 {
309 forceForbiddenErrors: false,
310 },
311 }
312 for _, test := range testCases {
313 t.Run(fmt.Sprintf("Forbidden errors %v", test.forceForbiddenErrors), func(t *testing.T) {
314 // assertRespStatus changes behaviour depending on if forcing forbidden errors
315 assertRespStatus := func(resp *TestResponse, statusIfForbiddenErrorsFalse int) {
316 if test.forceForbiddenErrors {
317 AssertHTTPErrorReason(t, resp, http.StatusForbidden, "forbidden")
318 return
319 }
320 AssertStatus(t, resp, statusIfForbiddenErrorsFalse)
321 }
322
323 rt := NewRestTester(t,
324 &RestTesterConfig{
325 SyncFn: `
326 function(doc, oldDoc) {
327 if (!doc.doNotSync) {
328 access("NoPerms", "chan2");
329 access("Perms", "chan2");
330 requireAccess("chan");
331 channel(doc.channels);
332 }
333 }`,
334 DatabaseConfig: &DatabaseConfig{DbConfig: DbConfig{
335 Unsupported: &db.UnsupportedOptions{
336 ForceAPIForbiddenErrors: test.forceForbiddenErrors,
337 },
338 Guest: &auth.PrincipalConfig{
339 Disabled: base.Ptr(false),
340 },
341 Users: map[string]*auth.PrincipalConfig{
342 "NoPerms": {
343 Password: base.Ptr("password"),
344 },
345 "Perms": {
346 Password: base.Ptr("password"),
347 },
348 },
349 }},
350 })
351 defer rt.Close()
352 dataStore := rt.GetSingleDataStore()
353 c := dataStore.CollectionName()
354 s := dataStore.ScopeName()
355
356 // update the user to add chan
357 resp := rt.SendAdminRequest(http.MethodPut, "/{{.db}}/_user/Perms", GetUserPayload(t, "Perms", "password", "", dataStore, []string{"chan"}, nil))

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetSingleDataStoreMethod · 0.95
SendAdminRequestMethod · 0.95
PutDocMethod · 0.95
GetChannelsMethod · 0.95
SetUpTestLoggingFunction · 0.92
PtrFunction · 0.92
AssertHTTPErrorReasonFunction · 0.85
AssertStatusFunction · 0.85
NewRestTesterFunction · 0.85
GetUserPayloadFunction · 0.85

Tested by

no test coverage detected