mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-17 00:54:20 +01:00
auth: LsatAuthenticator -> L402Authenticator sed -i 's/LsatAuthenticator/L402Authenticator/g' aperture.go auth/authenticator.go auth/authenticator_test.go rename package lsat to l402 git mv lsat/ l402 sed 's@aperture/lsat@aperture/l402@g' -i `git grep -l aperture/lsat` sed -i 's@package lsat@package l402@' `git grep -l 'package lsat'` sed -i 's@lsat\.@l402.@g' -i `git grep -l 'lsat\.'` sed 's@l402.Id@lsat.Id@' -i mint/mint_test.go replace lsat with l402 in the code sed 's@lsat@l402@' -i mint/mint_test.go sed 's@Lsat@L402@' -i l402/client_interceptor.go sed 's@lsatstore@l402store@' -i l402/store_test.go replace LSAT to L402 in comments sed '/\/\//s@LSAT@L402@g' -i `git grep -l '//.*LSAT'` replace LSAT -> L402 in the code, skip when a string starts with it sed 's@\([^"/]\)LSAT@\1L402@g' -i `git grep -l LSAT`
84 lines
1.5 KiB
Go
84 lines
1.5 KiB
Go
package l402
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// TestServicesCaveatSerialization ensures that we can properly encode/decode
|
|
// valid services from a caveat and cannot do so for invalid ones.
|
|
func TestServicesCaveatSerialization(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
value string
|
|
err error
|
|
}{
|
|
{
|
|
name: "single service",
|
|
value: "a:0",
|
|
err: nil,
|
|
},
|
|
{
|
|
name: "multiple services",
|
|
value: "a:0,b:1,c:0",
|
|
err: nil,
|
|
},
|
|
{
|
|
name: "no services",
|
|
value: "",
|
|
err: ErrNoServices,
|
|
},
|
|
{
|
|
name: "service missing name",
|
|
value: ":0",
|
|
err: ErrInvalidService,
|
|
},
|
|
{
|
|
name: "service missing tier",
|
|
value: "a",
|
|
err: ErrInvalidService,
|
|
},
|
|
{
|
|
name: "service empty tier",
|
|
value: "a:",
|
|
err: ErrInvalidService,
|
|
},
|
|
{
|
|
name: "service non-numeric tier",
|
|
value: "a:b",
|
|
err: ErrInvalidService,
|
|
},
|
|
{
|
|
name: "empty services",
|
|
value: ",,",
|
|
err: ErrInvalidService,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
test := test
|
|
success := t.Run(test.name, func(t *testing.T) {
|
|
services, err := decodeServicesCaveatValue(test.value)
|
|
if !errors.Is(err, test.err) {
|
|
t.Fatalf("expected err \"%v\", got \"%v\"",
|
|
test.err, err)
|
|
}
|
|
|
|
if test.err != nil {
|
|
return
|
|
}
|
|
|
|
value, _ := encodeServicesCaveatValue(services...)
|
|
if value != test.value {
|
|
t.Fatalf("expected encoded services \"%v\", "+
|
|
"got \"%v\"", test.value, value)
|
|
}
|
|
})
|
|
if !success {
|
|
return
|
|
}
|
|
}
|
|
}
|