MCPcopy Create free account
hub / github.com/couchbase/cbft / TestPreparePerms

Function TestPreparePerms

rest_auth_test.go:362–588  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

360}
361
362func TestPreparePerms(t *testing.T) {
363 rest.RequestProxyStubFunc = func() bool {
364 return false
365 }
366 emptyDir, _ := ioutil.TempDir("./tmp", "test")
367 defer func() {
368 os.RemoveAll(emptyDir)
369 rest.RequestProxyStubFunc = nil
370 }()
371
372 cfg := cbgt.NewCfgMem()
373 meh := &TestMEH{}
374 mgr := cbgt.NewManager(cbgt.VERSION, cfg, cbgt.NewUUID(),
375 nil, "", 1, "", ":1000", emptyDir, "some-datasource", meh)
376 mgr.Start("wanted")
377 mgr.Kick("test-start-kick")
378
379 mr, _ := cbgt.NewMsgRing(os.Stderr, 1000)
380
381 router, _, err := NewRESTRouter("v0", mgr, "static", "", mr, nil)
382 if err != nil || router == nil {
383 t.Errorf("no mux router")
384 }
385 router.KeepContext = true // so we can see the mux vars
386
387 s := &stubDefinitionLookuper{
388 pindexes: testPIndexesByName,
389 defs: &cbgt.IndexDefs{
390 IndexDefs: testIndexDefsByName,
391 },
392 }
393
394 tests := []struct {
395 method string
396 uri string
397 body []byte
398 path string
399 vars map[string]string
400 perms []string
401 err error
402 }{
403 // case with valid perm not containing source
404 {
405 method: http.MethodGet,
406 uri: "/api/index",
407 path: "/api/index",
408 perms: nil,
409 },
410 // case with valid index name
411 {
412 method: http.MethodGet,
413 uri: "/api/index/i1",
414 path: "/api/index/{indexName}",
415 vars: map[string]string{"indexName": "i1"},
416 perms: []string{"cluster.bucket[s1].fts!read"},
417 },
418 // case with valid index name on collection
419 {

Callers

nothing calls this directly

Calls 3

NewRESTRouterFunction · 0.85
preparePermsFunction · 0.85
ServeHTTPMethod · 0.45

Tested by

no test coverage detected