veyron/security/audit: Bug fixes and tests for those fixes.
Specifically:
(1) PublicKey and PublicID had an infinite recursion problem
(2) Operations on a Derived identity were not being audited
Change-Id: I6ab875c42492a762486c413e8060a5433c8cdf03
diff --git a/security/audit/auditor_test.go b/security/audit/auditor_test.go
new file mode 100644
index 0000000..5e4e1bb
--- /dev/null
+++ b/security/audit/auditor_test.go
@@ -0,0 +1,45 @@
+package audit_test
+
+import (
+ "testing"
+ "time"
+
+ "veyron/security/audit"
+)
+
+func TestEntryString(t *testing.T) {
+ timestamp, err := time.Parse(time.RFC3339, "2014-08-08T14:39:25-07:00") // "2014-08-08 12:56:40.698493437 -0700 PDT")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var (
+ onearg = []interface{}{"Arg"}
+ manyargs = []interface{}{"Arg1", "Arg2"}
+ oneresult = []interface{}{"Result"}
+ manyresults = []interface{}{"Res1", "Res2"}
+ tests = []struct {
+ Entry audit.Entry
+ String string
+ }{
+ // No results, 0, 1 or multiple arguments
+ {audit.Entry{Method: "M"}, "2014-08-08T14:39:25-07:00: M()"},
+ {audit.Entry{Method: "M", Arguments: onearg}, "2014-08-08T14:39:25-07:00: M(Arg)"},
+ {audit.Entry{Method: "M", Arguments: manyargs}, "2014-08-08T14:39:25-07:00: M(Arg1, Arg2)"},
+ // 1 result, 0, 1 or multiple arguments
+ {audit.Entry{Method: "M", Results: oneresult}, "2014-08-08T14:39:25-07:00: M() = (Result)"},
+ {audit.Entry{Method: "M", Arguments: onearg, Results: oneresult}, "2014-08-08T14:39:25-07:00: M(Arg) = (Result)"},
+ {audit.Entry{Method: "M", Arguments: manyargs, Results: oneresult}, "2014-08-08T14:39:25-07:00: M(Arg1, Arg2) = (Result)"},
+ // Multiple results, 0, 1 or multiple arguments
+ {audit.Entry{Method: "M", Results: manyresults}, "2014-08-08T14:39:25-07:00: M() = (Res1, Res2)"},
+ {audit.Entry{Method: "M", Arguments: onearg, Results: manyresults}, "2014-08-08T14:39:25-07:00: M(Arg) = (Res1, Res2)"},
+ {audit.Entry{Method: "M", Arguments: manyargs, Results: manyresults}, "2014-08-08T14:39:25-07:00: M(Arg1, Arg2) = (Res1, Res2)"},
+ }
+ )
+
+ for _, test := range tests {
+ test.Entry.Timestamp = timestamp
+ if got, want := test.Entry.String(), test.String; got != want {
+ t.Errorf("Got %q want %q for [%#v]", got, want, test.Entry)
+ }
+ }
+}