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.
This commit is contained in:
Johan T. Halseth 2020-09-24 11:22:13 +02:00
parent 8ca5342b37
commit 14960b1fb4
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -1,6 +1,7 @@
package macaroons_test package macaroons_test
import ( import (
"fmt"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -14,7 +15,7 @@ var (
testID = []byte("dummyId") testID = []byte("dummyId")
testLocation = "lnd" testLocation = "lnd"
testVersion = macaroon.LatestVersion 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 { func createDummyMacaroon(t *testing.T) *macaroon.Macaroon {
@ -67,8 +68,8 @@ func TestTimeoutConstraint(t *testing.T) {
} }
// Finally, check that the created caveat has an // Finally, check that the created caveat has an
// acceptable value // acceptable value.
if strings.HasPrefix(string(testMacaroon.Caveats()[0].Id), if !strings.HasPrefix(string(testMacaroon.Caveats()[0].Id),
expectedTimeCaveatSubstring) { expectedTimeCaveatSubstring) {
t.Fatalf("Added caveat '%s' does not meet the expectations!", t.Fatalf("Added caveat '%s' does not meet the expectations!",
testMacaroon.Caveats()[0].Id) testMacaroon.Caveats()[0].Id)
@ -90,7 +91,7 @@ func TestIpLockConstraint(t *testing.T) {
} }
// Finally, check that the created caveat has an // Finally, check that the created caveat has an
// acceptable value // acceptable value.
if string(testMacaroon.Caveats()[0].Id) != "ipaddr 127.0.0.1" { if string(testMacaroon.Caveats()[0].Id) != "ipaddr 127.0.0.1" {
t.Fatalf("Added caveat '%s' does not meet the expectations!", t.Fatalf("Added caveat '%s' does not meet the expectations!",
testMacaroon.Caveats()[0].Id) testMacaroon.Caveats()[0].Id)