// SameClientIPAddrCaveat returns a caveat that will check that // the remote IP address is the same as that in the given HTTP request. func SameClientIPAddrCaveat(req *http.Request) checkers.Caveat { if req.RemoteAddr == "" { return checkers.ErrorCaveatf("client has no remote IP address") } ip, err := requestIPAddr(req) if err != nil { return checkers.ErrorCaveatf("%v", err) } return checkers.ClientIPAddrCaveat(ip) }
expectError: `caveat "declared a aval" not satisfied: got a="aval", expected " aval"`, }, { caveat: checkers.DeclaredCaveat("spc", "a b").Condition, expectError: `caveat "declared spc a b" not satisfied: got spc=" a b", expected "a b"`, }, { caveat: checkers.DeclaredCaveat("", "a b").Condition, expectError: `caveat "error invalid caveat 'declared' key \\"\\"" not satisfied: bad caveat`, }, { caveat: checkers.DeclaredCaveat("a b", "a b").Condition, expectError: `caveat "error invalid caveat 'declared' key \\"a b\\"" not satisfied: bad caveat`, }}, }, { about: "error caveat", checker: checkers.New(), checks: []checkTest{{ caveat: checkers.ErrorCaveatf("").Condition, expectError: `caveat "error " not satisfied: bad caveat`, }, { caveat: checkers.ErrorCaveatf("something %d", 134).Condition, expectError: `caveat "error something 134" not satisfied: bad caveat`, }}, }, { about: "error caveat overrides other", checker: checkers.New(argChecker("error", "something")), checks: []checkTest{{ caveat: checkers.ErrorCaveatf("something").Condition, expectError: `caveat "error something" not satisfied: bad caveat`, }}, }} var errWrongArg = errgo.New("wrong arg")