Tilak Sharma | d6ade0e | 2014-08-20 16:28:32 -0700 | [diff] [blame] | 1 | package security |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "reflect" |
| 6 | "testing" |
| 7 | |
| 8 | "veyron2/security" |
| 9 | ) |
| 10 | |
| 11 | func TestLoadSaveIdentity(t *testing.T) { |
| 12 | id := security.FakePrivateID("test") |
| 13 | |
| 14 | var buf bytes.Buffer |
| 15 | if err := SaveIdentity(&buf, id); err != nil { |
| 16 | t.Fatalf("Failed to save PrivateID %q: %v", id, err) |
| 17 | } |
| 18 | |
| 19 | loadedID, err := LoadIdentity(&buf) |
| 20 | if err != nil { |
| 21 | t.Fatalf("Failed to load PrivateID: %v", err) |
| 22 | } |
| 23 | if !reflect.DeepEqual(loadedID, id) { |
| 24 | t.Fatalf("Got Identity %v, but want %v", loadedID, id) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestLoadSaveACL(t *testing.T) { |
| 29 | acl := security.ACL{} |
Asim Shankar | 9f6db08 | 2014-08-27 16:44:03 -0700 | [diff] [blame] | 30 | acl.In = map[security.BlessingPattern]security.LabelSet{ |
| 31 | "veyron/...": security.LabelSet(security.ReadLabel), |
Tilak Sharma | d6ade0e | 2014-08-20 16:28:32 -0700 | [diff] [blame] | 32 | "veyron/alice": security.LabelSet(security.ReadLabel | security.WriteLabel), |
| 33 | "veyron/bob": security.LabelSet(security.AdminLabel), |
| 34 | } |
Asim Shankar | 9f6db08 | 2014-08-27 16:44:03 -0700 | [diff] [blame] | 35 | acl.NotIn = map[string]security.LabelSet{ |
Tilak Sharma | d6ade0e | 2014-08-20 16:28:32 -0700 | [diff] [blame] | 36 | "veyron/che": security.LabelSet(security.ReadLabel), |
| 37 | } |
| 38 | |
| 39 | var buf bytes.Buffer |
| 40 | if err := SaveACL(&buf, acl); err != nil { |
| 41 | t.Fatalf("Failed to save ACL %q: %v", acl, err) |
| 42 | } |
| 43 | |
| 44 | loadedACL, err := LoadACL(&buf) |
| 45 | if err != nil { |
| 46 | t.Fatalf("Failed to load ACL: %v", err) |
| 47 | } |
| 48 | if !reflect.DeepEqual(loadedACL, acl) { |
| 49 | t.Fatalf("Got ACL %v, but want %v", loadedACL, acl) |
| 50 | } |
| 51 | } |