From 14960b1fb46facc9bdccb63aa11228b00480fda3 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 24 Sep 2020 11:22:13 +0200 Subject: [PATCH] macaroons test: reverse macaroon time caveat check This commit fixes a go 1.15 vet check. In doing so it uncovers that the time caveat check is actually reversed. Since we should check that the caveat is added, we should only fail the check when the caveat prefix is not equal. --- macaroons/constraints_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/macaroons/constraints_test.go b/macaroons/constraints_test.go index dd97536a..569acea8 100644 --- a/macaroons/constraints_test.go +++ b/macaroons/constraints_test.go @@ -1,6 +1,7 @@ package macaroons_test import ( + "fmt" "strings" "testing" "time" @@ -14,7 +15,7 @@ var ( testID = []byte("dummyId") testLocation = "lnd" testVersion = macaroon.LatestVersion - expectedTimeCaveatSubstring = "time-before " + string(time.Now().Year()) + expectedTimeCaveatSubstring = fmt.Sprintf("time-before %d", time.Now().Year()) ) func createDummyMacaroon(t *testing.T) *macaroon.Macaroon { @@ -67,8 +68,8 @@ func TestTimeoutConstraint(t *testing.T) { } // Finally, check that the created caveat has an - // acceptable value - if strings.HasPrefix(string(testMacaroon.Caveats()[0].Id), + // acceptable value. + if !strings.HasPrefix(string(testMacaroon.Caveats()[0].Id), expectedTimeCaveatSubstring) { t.Fatalf("Added caveat '%s' does not meet the expectations!", testMacaroon.Caveats()[0].Id) @@ -90,7 +91,7 @@ func TestIpLockConstraint(t *testing.T) { } // Finally, check that the created caveat has an - // acceptable value + // acceptable value. if string(testMacaroon.Caveats()[0].Id) != "ipaddr 127.0.0.1" { t.Fatalf("Added caveat '%s' does not meet the expectations!", testMacaroon.Caveats()[0].Id)