| package security |
| |
| import ( |
| "bytes" |
| "reflect" |
| "testing" |
| |
| "veyron2/security" |
| ) |
| |
| func TestLoadSaveIdentity(t *testing.T) { |
| id := security.FakePrivateID("test") |
| |
| var buf bytes.Buffer |
| if err := SaveIdentity(&buf, id); err != nil { |
| t.Fatalf("Failed to save PrivateID %q: %v", id, err) |
| } |
| |
| loadedID, err := LoadIdentity(&buf) |
| if err != nil { |
| t.Fatalf("Failed to load PrivateID: %v", err) |
| } |
| if !reflect.DeepEqual(loadedID, id) { |
| t.Fatalf("Got Identity %v, but want %v", loadedID, id) |
| } |
| } |
| |
| func TestLoadSaveACL(t *testing.T) { |
| acl := security.ACL{} |
| acl.In.Principals = map[security.BlessingPattern]security.LabelSet{ |
| "veyron/*": security.LabelSet(security.ReadLabel), |
| "veyron/alice": security.LabelSet(security.ReadLabel | security.WriteLabel), |
| "veyron/bob": security.LabelSet(security.AdminLabel), |
| } |
| acl.NotIn.Principals = map[security.BlessingPattern]security.LabelSet{ |
| "veyron/che": security.LabelSet(security.ReadLabel), |
| } |
| |
| var buf bytes.Buffer |
| if err := SaveACL(&buf, acl); err != nil { |
| t.Fatalf("Failed to save ACL %q: %v", acl, err) |
| } |
| |
| loadedACL, err := LoadACL(&buf) |
| if err != nil { |
| t.Fatalf("Failed to load ACL: %v", err) |
| } |
| if !reflect.DeepEqual(loadedACL, acl) { |
| t.Fatalf("Got ACL %v, but want %v", loadedACL, acl) |
| } |
| } |