c.Assert(checkers.InferDeclared(ms), jc.DeepEquals, test.expect) } } var operationCheckerTests = []struct { about string caveat checkers.Caveat oc checkers.OperationChecker expectError string }{{ about: "allowed operation", caveat: checkers.AllowCaveat("op1", "op2", "op3"), oc: checkers.OperationChecker("op1"), }, { about: "not denied oc", caveat: checkers.DenyCaveat("op1", "op2", "op3"), oc: checkers.OperationChecker("op4"), }, { about: "not allowed oc", caveat: checkers.AllowCaveat("op1", "op2", "op3"), oc: checkers.OperationChecker("op4"), expectError: "op4 not allowed", }, { about: "denied oc", caveat: checkers.DenyCaveat("op1", "op2", "op3"), oc: checkers.OperationChecker("op1"), expectError: "op1 not allowed", }, { about: "unrecognised caveat", caveat: checkers.ErrorCaveatf("unrecognized"), oc: checkers.OperationChecker("op1"),
about: "empty caveats", caveats: []macaroon.Caveat{}, }, { about: "single time-before caveat", caveats: []macaroon.Caveat{ macaroon.Caveat{ Id: checkers.TimeBeforeCaveat(t1).Condition, }, }, expectTime: t1, expectExpires: true, }, { about: "single deny caveat", caveats: []macaroon.Caveat{ macaroon.Caveat{ Id: checkers.DenyCaveat("abc").Condition, }, }, }, { about: "multiple time-before caveat", caveats: []macaroon.Caveat{ macaroon.Caveat{ Id: checkers.TimeBeforeCaveat(t2).Condition, }, macaroon.Caveat{ Id: checkers.TimeBeforeCaveat(t1).Condition, }, }, expectTime: t1, expectExpires: true, }, {