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