Files
lnd/macaroons/fuzz_test.go
Boris Nagaev dee8ad3754 multi: context.Background() -> t.Context()
Use the new feature of Go 1.24, fix linter warnings.

This change was produced by:
 - running golangci-lint run --fix
 - sed 's/context.Background/t.Context/' -i `git grep -l context.Background | grep test.go`
 - manually fixing broken tests
 - itest, lntest: use ht.Context() where ht or hn is available
 - in HarnessNode.Stop() we keep using context.Background(), because it is
   called from a cleanup handler in which t.Context() is canceled already.
2025-08-30 14:13:44 -03:00

51 lines
912 B
Go

package macaroons
import (
"testing"
"gopkg.in/macaroon-bakery.v2/bakery"
"gopkg.in/macaroon.v2"
)
func FuzzUnmarshalMacaroon(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
mac := &macaroon.Macaroon{}
_ = mac.UnmarshalBinary(data)
})
}
func FuzzAuthChecker(f *testing.F) {
rootKeyStore := bakery.NewMemRootKeyStore()
ctx := f.Context()
f.Fuzz(func(t *testing.T, location, entity, action, method string,
rootKey, id []byte) {
macService, err := NewService(
rootKeyStore, location, true, IPLockChecker,
)
if err != nil {
return
}
requiredPermissions := []bakery.Op{{
Entity: entity,
Action: action,
}}
mac, err := macaroon.New(rootKey, id, location, macaroon.V2)
if err != nil {
return
}
macBytes, err := mac.MarshalBinary()
if err != nil {
return
}
_ = macService.CheckMacAuth(
ctx, macBytes, requiredPermissions, method,
)
})
}