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()
21 client.Timeout = 0 // disable auto-retry
22 pc := newPermChecker(*client).(*cachingPermChecker)
23 setToken := func(label, token string) {
24 c.Logf("...%s token %q", label, token)
27 wantError := func(uuid string) {
29 ok, err := pc.Check(context.Background(), uuid)
30 c.Check(ok, check.Equals, false)
31 c.Check(err, check.NotNil)
33 wantYes := func(uuid string) {
35 ok, err := pc.Check(context.Background(), uuid)
36 c.Check(ok, check.Equals, true)
37 c.Check(err, check.IsNil)
39 wantNo := func(uuid string) {
41 ok, err := pc.Check(context.Background(), uuid)
42 c.Check(ok, check.Equals, false)
43 c.Check(err, check.IsNil)
47 wantNo(arvadostest.UserAgreementCollection)
48 wantNo(arvadostest.UserAgreementPDH)
49 wantNo(arvadostest.FooBarDirCollection)
51 setToken("anonymous", arvadostest.AnonymousToken)
52 wantYes(arvadostest.UserAgreementCollection)
53 wantYes(arvadostest.UserAgreementPDH)
54 wantNo(arvadostest.FooBarDirCollection)
55 wantNo(arvadostest.FooCollection)
57 setToken("active", arvadostest.ActiveToken)
58 wantYes(arvadostest.UserAgreementCollection)
59 wantYes(arvadostest.UserAgreementPDH)
60 wantYes(arvadostest.FooBarDirCollection)
61 wantYes(arvadostest.FooCollection)
63 setToken("admin", arvadostest.AdminToken)
64 wantYes(arvadostest.UserAgreementCollection)
65 wantYes(arvadostest.UserAgreementPDH)
66 wantYes(arvadostest.FooBarDirCollection)
67 wantYes(arvadostest.FooCollection)
69 // hack to empty the cache
71 pc.SetToken(arvadostest.ActiveToken)
73 c.Log("...network error")
74 pc.Client.APIHost = "127.0.0.1:9"
75 wantError(arvadostest.UserAgreementCollection)
76 wantError(arvadostest.FooBarDirCollection)
78 c.Logf("%d checks, %d misses, %d invalid, %d cached", pc.nChecks, pc.nMisses, pc.nInvalid, len(pc.cache))