1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
8 "git.curoverse.com/arvados.git/sdk/go/arvados"
9 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
10 check "gopkg.in/check.v1"
13 var _ = check.Suite(&permSuite{})
15 type permSuite struct{}
17 func (s *permSuite) TestCheck(c *check.C) {
18 pc := newPermChecker(*(arvados.NewClientFromEnv())).(*cachingPermChecker)
19 setToken := func(label, token string) {
20 c.Logf("...%s token %q", label, token)
23 wantError := func(uuid string) {
25 ok, err := pc.Check(uuid)
26 c.Check(ok, check.Equals, false)
27 c.Check(err, check.NotNil)
29 wantYes := func(uuid string) {
31 ok, err := pc.Check(uuid)
32 c.Check(ok, check.Equals, true)
33 c.Check(err, check.IsNil)
35 wantNo := func(uuid string) {
37 ok, err := pc.Check(uuid)
38 c.Check(ok, check.Equals, false)
39 c.Check(err, check.IsNil)
43 wantNo(arvadostest.UserAgreementCollection)
44 wantNo(arvadostest.UserAgreementPDH)
45 wantNo(arvadostest.FooBarDirCollection)
47 setToken("anonymous", arvadostest.AnonymousToken)
48 wantYes(arvadostest.UserAgreementCollection)
49 wantYes(arvadostest.UserAgreementPDH)
50 wantNo(arvadostest.FooBarDirCollection)
51 wantNo(arvadostest.FooCollection)
53 setToken("active", arvadostest.ActiveToken)
54 wantYes(arvadostest.UserAgreementCollection)
55 wantYes(arvadostest.UserAgreementPDH)
56 wantYes(arvadostest.FooBarDirCollection)
57 wantYes(arvadostest.FooCollection)
59 setToken("admin", arvadostest.AdminToken)
60 wantYes(arvadostest.UserAgreementCollection)
61 wantYes(arvadostest.UserAgreementPDH)
62 wantYes(arvadostest.FooBarDirCollection)
63 wantYes(arvadostest.FooCollection)
65 // hack to empty the cache
67 pc.SetToken(arvadostest.ActiveToken)
69 c.Log("...network error")
70 pc.Client.APIHost = "127.0.0.1:discard"
71 wantError(arvadostest.UserAgreementCollection)
72 wantError(arvadostest.FooBarDirCollection)
74 c.Logf("%d checks, %d misses, %d invalid, %d cached", pc.nChecks, pc.nMisses, pc.nInvalid, len(pc.cache))