Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 1 | package impl_test |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "fmt" |
| 6 | "io" |
| 7 | "os" |
| 8 | "reflect" |
| 9 | "syscall" |
| 10 | "testing" |
| 11 | |
| 12 | "v.io/core/veyron2" |
| 13 | "v.io/core/veyron2/context" |
| 14 | "v.io/core/veyron2/naming" |
| 15 | "v.io/core/veyron2/rt" |
| 16 | "v.io/core/veyron2/security" |
| 17 | "v.io/core/veyron2/services/mgmt/application" |
| 18 | "v.io/core/veyron2/services/security/access" |
| 19 | "v.io/core/veyron2/vdl/vdlutil" |
| 20 | "v.io/core/veyron2/verror" |
| 21 | "v.io/core/veyron2/vlog" |
| 22 | |
| 23 | "v.io/core/veyron/lib/modules" |
| 24 | "v.io/core/veyron/lib/signals" |
| 25 | "v.io/core/veyron/lib/testutil" |
| 26 | tsecurity "v.io/core/veyron/lib/testutil/security" |
| 27 | "v.io/core/veyron/services/mgmt/application/impl" |
| 28 | mgmttest "v.io/core/veyron/services/mgmt/lib/testutil" |
| 29 | "v.io/core/veyron/services/mgmt/repository" |
| 30 | ) |
| 31 | |
| 32 | const ( |
| 33 | repoCmd = "repository" |
| 34 | ) |
| 35 | |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 36 | var globalCtx *context.T |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame^] | 37 | var globalCancel context.CancelFunc |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 38 | |
| 39 | // This is also a modules world. |
| 40 | // Insert necessary code here to be a modules test. |
| 41 | func init() { |
| 42 | // TODO(rjkroege): Remove when vom2 is ready. |
| 43 | vdlutil.Register(&naming.VDLMountedServer{}) |
| 44 | |
| 45 | modules.RegisterChild(repoCmd, "", appRepository) |
| 46 | testutil.Init() |
| 47 | |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame^] | 48 | globalRT, err := rt.New() |
| 49 | if err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 50 | panic(err) |
| 51 | } |
| 52 | globalCtx = globalRT.NewContext() |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame^] | 53 | globalCancel = globalRT.Cleanup |
Matt Rosencrantz | d599e38 | 2015-01-12 11:13:32 -0800 | [diff] [blame] | 54 | veyron2.GetNamespace(globalCtx).CacheCtl(naming.DisableCache(true)) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | // TestHelperProcess is the entrypoint for the modules commands in a |
| 58 | // a test subprocess. |
| 59 | func TestHelperProcess(t *testing.T) { |
| 60 | modules.DispatchInTest() |
| 61 | } |
| 62 | |
| 63 | func appRepository(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error { |
| 64 | args = args[1:] |
| 65 | if len(args) < 2 { |
| 66 | vlog.Fatalf("repository expected at least name and store arguments and optionally ACL flags per TaggedACLMapFromFlag") |
| 67 | } |
| 68 | publishName := args[0] |
| 69 | storedir := args[1] |
| 70 | |
| 71 | defer fmt.Fprintf(stdout, "%v terminating\n", publishName) |
| 72 | defer vlog.VI(1).Infof("%v terminating", publishName) |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame^] | 73 | defer globalCancel() |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 74 | server, endpoint := mgmttest.NewServer(globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 75 | defer server.Stop() |
| 76 | |
| 77 | name := naming.JoinAddressName(endpoint, "") |
| 78 | vlog.VI(1).Infof("applicationd name: %v", name) |
| 79 | |
| 80 | dispatcher, err := impl.NewDispatcher(storedir) |
| 81 | if err != nil { |
| 82 | vlog.Fatalf("Failed to create repository dispatcher: %v", err) |
| 83 | } |
| 84 | if err := server.ServeDispatcher(publishName, dispatcher); err != nil { |
| 85 | vlog.Fatalf("Serve(%v) failed: %v", publishName, err) |
| 86 | } |
| 87 | |
| 88 | fmt.Fprintf(stdout, "ready:%d\n", os.Getpid()) |
| 89 | <-signals.ShutdownOnSignals(globalCtx) |
| 90 | |
| 91 | return nil |
| 92 | } |
| 93 | |
| 94 | func TestApplicationUpdateACL(t *testing.T) { |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 95 | sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 96 | defer deferFn() |
| 97 | |
| 98 | // setup mock up directory to put state in |
| 99 | storedir, cleanup := mgmttest.SetupRootDir(t, "application") |
| 100 | defer cleanup() |
| 101 | |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame^] | 102 | otherCtx, otherCancel := mgmttest.NewRuntime(t, globalCtx) |
| 103 | defer otherCancel() |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 104 | |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 105 | idp := tsecurity.NewIDProvider("root") |
| 106 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 107 | // By default, globalRT and otherRT will have blessings generated based on the |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 108 | // username/machine name running this process. Since these blessings will appear |
| 109 | // in ACLs, give them recognizable names. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 110 | if err := idp.Bless(veyron2.GetPrincipal(globalCtx), "self"); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 111 | t.Fatal(err) |
| 112 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 113 | if err := idp.Bless(veyron2.GetPrincipal(otherCtx), "other"); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 114 | t.Fatal(err) |
| 115 | } |
| 116 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 117 | crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "repo") |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 118 | defer os.RemoveAll(crDir) |
| 119 | |
| 120 | // Make server credentials derived from the test harness. |
| 121 | _, nms := mgmttest.RunShellCommand(t, sh, crEnv, repoCmd, "repo", storedir) |
| 122 | pid := mgmttest.ReadPID(t, nms) |
| 123 | defer syscall.Kill(pid, syscall.SIGINT) |
| 124 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 125 | v1stub := repository.ApplicationClient("repo/search/v1") |
| 126 | repostub := repository.ApplicationClient("repo") |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 127 | |
| 128 | // Create example envelopes. |
| 129 | envelopeV1 := application.Envelope{ |
| 130 | Args: []string{"--help"}, |
| 131 | Env: []string{"DEBUG=1"}, |
| 132 | Binary: "/veyron/name/of/binary", |
| 133 | } |
| 134 | |
| 135 | // Envelope putting as other should fail. |
| 136 | // TODO(rjkroege): Validate that it is failed with permission denied. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 137 | if err := v1stub.Put(otherCtx, []string{"base"}, envelopeV1); err == nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 138 | t.Fatalf("Put() wrongly didn't fail") |
| 139 | } |
| 140 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 141 | // Envelope putting as global should succeed. |
| 142 | if err := v1stub.Put(globalCtx, []string{"base"}, envelopeV1); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 143 | t.Fatalf("Put() failed: %v", err) |
| 144 | } |
| 145 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 146 | acl, etag, err := repostub.GetACL(globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 147 | if !verror.Is(err, impl.ErrNotFound.ID) { |
| 148 | t.Fatalf("GetACL should have failed with ErrNotFound but was: %v", err) |
| 149 | } |
| 150 | if etag != "default" { |
| 151 | t.Fatalf("getACL expected:default, got:%v(%v)", etag, acl) |
| 152 | } |
| 153 | if acl != nil { |
| 154 | t.Fatalf("GetACL got %v, expected %v", acl, nil) |
| 155 | } |
| 156 | |
| 157 | vlog.VI(2).Infof("self attempting to give other permission to update application") |
| 158 | newACL := make(access.TaggedACLMap) |
| 159 | for _, tag := range access.AllTypicalTags() { |
| 160 | newACL.Add("root/self", string(tag)) |
| 161 | newACL.Add("root/other", string(tag)) |
| 162 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 163 | if err := repostub.SetACL(globalCtx, newACL, ""); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 164 | t.Fatalf("SetACL failed: %v", err) |
| 165 | } |
| 166 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 167 | acl, etag, err = repostub.GetACL(globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 168 | if err != nil { |
| 169 | t.Fatalf("GetACL should not have failed: %v", err) |
| 170 | } |
| 171 | expected := newACL |
| 172 | if got := acl; !reflect.DeepEqual(expected.Normalize(), got.Normalize()) { |
| 173 | t.Errorf("got %#v, exected %#v ", got, expected) |
| 174 | } |
| 175 | |
| 176 | // Envelope putting as other should now succeed. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 177 | if err := v1stub.Put(otherCtx, []string{"base"}, envelopeV1); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 178 | t.Fatalf("Put() wrongly failed: %v", err) |
| 179 | } |
| 180 | |
| 181 | // Other takes control. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 182 | acl, etag, err = repostub.GetACL(otherCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 183 | if err != nil { |
| 184 | t.Fatalf("GetACL 2 should not have failed: %v", err) |
| 185 | } |
| 186 | acl["Admin"] = access.ACL{ |
| 187 | In: []security.BlessingPattern{"root/other"}, |
| 188 | NotIn: []string{}} |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 189 | if err = repostub.SetACL(otherCtx, acl, etag); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 190 | t.Fatalf("SetACL failed: %v", err) |
| 191 | } |
| 192 | |
| 193 | // Self is now locked out but other isn't. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 194 | if _, _, err = repostub.GetACL(globalCtx); err == nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 195 | t.Fatalf("GetACL should not have succeeded") |
| 196 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 197 | acl, _, err = repostub.GetACL(otherCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 198 | if err != nil { |
| 199 | t.Fatalf("GetACL should not have failed: %v", err) |
| 200 | } |
| 201 | expected = access.TaggedACLMap{ |
| 202 | "Admin": access.ACL{ |
| 203 | In: []security.BlessingPattern{"root/other"}, |
| 204 | NotIn: []string{}}, |
| 205 | "Read": access.ACL{In: []security.BlessingPattern{"root/other", |
| 206 | "root/self"}, |
| 207 | NotIn: []string{}}, |
| 208 | "Write": access.ACL{In: []security.BlessingPattern{"root/other", |
| 209 | "root/self"}, |
| 210 | NotIn: []string{}}, |
| 211 | "Debug": access.ACL{In: []security.BlessingPattern{"root/other", |
| 212 | "root/self"}, |
| 213 | NotIn: []string{}}, |
| 214 | "Resolve": access.ACL{In: []security.BlessingPattern{"root/other", |
| 215 | "root/self"}, |
| 216 | NotIn: []string{}}} |
| 217 | |
| 218 | if got := acl; !reflect.DeepEqual(expected.Normalize(), got.Normalize()) { |
| 219 | t.Errorf("got %#v, exected %#v ", got, expected) |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | func TestPerAppACL(t *testing.T) { |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 224 | sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 225 | defer deferFn() |
| 226 | |
| 227 | // setup mock up directory to put state in |
| 228 | storedir, cleanup := mgmttest.SetupRootDir(t, "application") |
| 229 | defer cleanup() |
| 230 | |
Matt Rosencrantz | f1c3b44 | 2015-01-12 17:53:08 -0800 | [diff] [blame^] | 231 | otherCtx, otherCancel := mgmttest.NewRuntime(t, globalCtx) |
| 232 | defer otherCancel() |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 233 | idp := tsecurity.NewIDProvider("root") |
| 234 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 235 | // By default, globalRT and otherRT will have blessings generated based on the |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 236 | // username/machine name running this process. Since these blessings will appear |
| 237 | // in ACLs, give them recognizable names. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 238 | if err := idp.Bless(veyron2.GetPrincipal(globalCtx), "self"); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 239 | t.Fatal(err) |
| 240 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 241 | if err := idp.Bless(veyron2.GetPrincipal(otherCtx), "other"); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 242 | t.Fatal(err) |
| 243 | } |
| 244 | |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 245 | crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "repo") |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 246 | defer os.RemoveAll(crDir) |
| 247 | |
| 248 | // Make a server with the same credential as test harness. |
| 249 | _, nms := mgmttest.RunShellCommand(t, sh, crEnv, repoCmd, "repo", storedir) |
| 250 | pid := mgmttest.ReadPID(t, nms) |
| 251 | defer syscall.Kill(pid, syscall.SIGINT) |
| 252 | |
| 253 | // Create example envelope. |
| 254 | envelopeV1 := application.Envelope{ |
| 255 | Args: []string{"--help"}, |
| 256 | Env: []string{"DEBUG=1"}, |
| 257 | Binary: "/veyron/name/of/binary", |
| 258 | } |
| 259 | |
| 260 | // Upload the envelope at two different names. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 261 | v1stub := repository.ApplicationClient("repo/search/v1") |
| 262 | if err := v1stub.Put(globalCtx, []string{"base"}, envelopeV1); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 263 | t.Fatalf("Put() failed: %v", err) |
| 264 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 265 | v2stub := repository.ApplicationClient("repo/search/v2") |
| 266 | if err := v2stub.Put(globalCtx, []string{"base"}, envelopeV1); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 267 | t.Fatalf("Put() failed: %v", err) |
| 268 | } |
| 269 | |
| 270 | // Self can access ACLs but other can't. |
| 271 | for _, path := range []string{"repo/search", "repo/search/v1", "repo/search/v2"} { |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 272 | stub := repository.ApplicationClient(path) |
| 273 | acl, etag, err := stub.GetACL(globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 274 | if !verror.Is(err, impl.ErrNotFound.ID) { |
| 275 | t.Fatalf("GetACL should have failed with ErrNotFound but was: %v", err) |
| 276 | } |
| 277 | if etag != "default" { |
| 278 | t.Fatalf("GetACL expected:default, got:%v(%v)", etag, acl) |
| 279 | } |
| 280 | if acl != nil { |
| 281 | t.Fatalf("GetACL got %v, expected %v", acl, nil) |
| 282 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 283 | if _, _, err := stub.GetACL(otherCtx); err == nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 284 | t.Fatalf("GetACL didn't fail for other when it should have.") |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // Self gives other full access only to repo/search/v1. |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 289 | newACL := make(access.TaggedACLMap) |
| 290 | for _, tag := range access.AllTypicalTags() { |
| 291 | newACL.Add("root/self", string(tag)) |
| 292 | newACL.Add("root/other", string(tag)) |
| 293 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 294 | if err := v1stub.SetACL(globalCtx, newACL, ""); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 295 | t.Fatalf("SetACL failed: %v", err) |
| 296 | } |
| 297 | |
| 298 | // Other can now access this location. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 299 | acl, _, err := v1stub.GetACL(otherCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 300 | if err != nil { |
| 301 | t.Fatalf("GetACL should not have failed: %v", err) |
| 302 | } |
| 303 | expected := access.TaggedACLMap{ |
| 304 | "Admin": access.ACL{ |
| 305 | In: []security.BlessingPattern{"root/other", |
| 306 | "root/self"}, |
| 307 | NotIn: []string{}}, |
| 308 | "Read": access.ACL{In: []security.BlessingPattern{"root/other", |
| 309 | "root/self"}, |
| 310 | NotIn: []string{}}, |
| 311 | "Write": access.ACL{In: []security.BlessingPattern{"root/other", |
| 312 | "root/self"}, |
| 313 | NotIn: []string{}}, |
| 314 | "Debug": access.ACL{In: []security.BlessingPattern{"root/other", |
| 315 | "root/self"}, |
| 316 | NotIn: []string{}}, |
| 317 | "Resolve": access.ACL{In: []security.BlessingPattern{"root/other", |
| 318 | "root/self"}, |
| 319 | NotIn: []string{}}} |
| 320 | if got := acl; !reflect.DeepEqual(expected.Normalize(), got.Normalize()) { |
| 321 | t.Errorf("got %#v, exected %#v ", got, expected) |
| 322 | } |
| 323 | |
| 324 | // But other locations should be unaffected and other cannot access. |
| 325 | for _, path := range []string{"repo/search", "repo/search/v2"} { |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 326 | stub := repository.ApplicationClient(path) |
| 327 | if _, _, err := stub.GetACL(otherCtx); err == nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 328 | t.Fatalf("GetACL didn't fail for other when it should have.") |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // Self gives other write perms on base. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 333 | repostub := repository.ApplicationClient("repo/") |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 334 | newACL = make(access.TaggedACLMap) |
| 335 | for _, tag := range access.AllTypicalTags() { |
| 336 | newACL.Add("root/self", string(tag)) |
| 337 | } |
| 338 | newACL["Write"] = access.ACL{In: []security.BlessingPattern{"root/other", "root/self"}} |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 339 | if err := repostub.SetACL(globalCtx, newACL, ""); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 340 | t.Fatalf("SetACL failed: %v", err) |
| 341 | } |
| 342 | |
| 343 | // Other can now upload an envelope at both locations. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 344 | for _, stub := range []repository.ApplicationClientStub{v1stub, v2stub} { |
| 345 | if err := stub.Put(otherCtx, []string{"base"}, envelopeV1); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 346 | t.Fatalf("Put() failed: %v", err) |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // But self didn't give other ACL modification permissions. |
| 351 | for _, path := range []string{"repo/search", "repo/search/v2"} { |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 352 | stub := repository.ApplicationClient(path) |
| 353 | if _, _, err := stub.GetACL(otherCtx); err == nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 354 | t.Fatalf("GetACL didn't fail for other when it should have.") |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | func TestInitialACLSet(t *testing.T) { |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 360 | sh, deferFn := mgmttest.CreateShellAndMountTable(t, globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 361 | defer deferFn() |
| 362 | |
| 363 | // Setup mock up directory to put state in. |
| 364 | storedir, cleanup := mgmttest.SetupRootDir(t, "application") |
| 365 | defer cleanup() |
| 366 | |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 367 | idp := tsecurity.NewIDProvider("root") |
| 368 | |
| 369 | // Make a recognizable principal name. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 370 | if err := idp.Bless(veyron2.GetPrincipal(globalCtx), "self"); err != nil { |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 371 | t.Fatal(err) |
| 372 | } |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 373 | crDir, crEnv := mgmttest.CredentialsForChild(globalCtx, "repo") |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 374 | defer os.RemoveAll(crDir) |
| 375 | |
| 376 | // Make an TAM for use on the command line. |
| 377 | expected := access.TaggedACLMap{ |
| 378 | "Admin": access.ACL{ |
| 379 | In: []security.BlessingPattern{"root/rubberchicken", |
| 380 | "root/self"}, |
| 381 | NotIn: []string{}, |
| 382 | }, |
| 383 | } |
| 384 | |
| 385 | b := new(bytes.Buffer) |
| 386 | if err := expected.WriteTo(b); err != nil { |
| 387 | t.Fatal(err) |
| 388 | } |
| 389 | |
| 390 | // Start a server with the same credential as test harness. |
| 391 | _, nms := mgmttest.RunShellCommand(t, sh, crEnv, repoCmd, "--veyron.acl.literal", b.String(), "repo", storedir) |
| 392 | pid := mgmttest.ReadPID(t, nms) |
| 393 | defer syscall.Kill(pid, syscall.SIGINT) |
| 394 | |
| 395 | // It should have the correct starting ACLs from the command line. |
Matt Rosencrantz | 6edab56 | 2015-01-12 11:07:55 -0800 | [diff] [blame] | 396 | stub := repository.ApplicationClient("repo") |
| 397 | acl, _, err := stub.GetACL(globalCtx) |
Robert Kroeger | d6e1d1a | 2014-12-10 15:08:45 -0800 | [diff] [blame] | 398 | if err != nil { |
| 399 | t.Fatalf("GetACL should not have failed: %v", err) |
| 400 | } |
| 401 | if got := acl; !reflect.DeepEqual(expected.Normalize(), got.Normalize()) { |
| 402 | t.Errorf("got %#v, exected %#v ", got, expected) |
| 403 | } |
| 404 | } |