mirror of
https://github.com/lightninglabs/aperture.git
synced 2026-01-24 11:44:24 +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`
88 lines
1.7 KiB
Go
88 lines
1.7 KiB
Go
package l402
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestTimeoutSatisfier tests that the Timeout Satisfier implementation behaves
|
|
// as expected and correctly accepts or rejects calls based on if the
|
|
// timeout has been reached or not.
|
|
func TestTimeoutSatisfier(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
now := int64(0)
|
|
|
|
var tests = []struct {
|
|
name string
|
|
timeouts []int64
|
|
expectFinalErr bool
|
|
expectPrevErr bool
|
|
}{
|
|
{
|
|
name: "current time is before expiration",
|
|
timeouts: []int64{now + 1000},
|
|
},
|
|
{
|
|
name: "time passed is greater than " +
|
|
"expiration",
|
|
timeouts: []int64{now - 1000},
|
|
expectFinalErr: true,
|
|
},
|
|
{
|
|
name: "successive caveats are increasingly " +
|
|
"restrictive and not yet expired",
|
|
timeouts: []int64{now + 1000, now + 500},
|
|
},
|
|
{
|
|
name: "latter caveat is less restrictive " +
|
|
"then previous",
|
|
timeouts: []int64{now + 500, now + 1000},
|
|
expectPrevErr: true,
|
|
},
|
|
}
|
|
|
|
var (
|
|
service = "restricted"
|
|
condition = service + CondTimeoutSuffix
|
|
satisfier = NewTimeoutSatisfier(service, func() time.Time {
|
|
return time.Unix(now, 0)
|
|
})
|
|
)
|
|
|
|
for _, test := range tests {
|
|
test := test
|
|
t.Run(test.name, func(t *testing.T) {
|
|
var prev *Caveat
|
|
for _, timeout := range test.timeouts {
|
|
caveat := NewCaveat(
|
|
condition, fmt.Sprintf("%d", timeout),
|
|
)
|
|
|
|
if prev != nil {
|
|
err := satisfier.SatisfyPrevious(
|
|
*prev, caveat,
|
|
)
|
|
if test.expectPrevErr {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
}
|
|
|
|
err := satisfier.SatisfyFinal(caveat)
|
|
if test.expectFinalErr {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
prev = &caveat
|
|
}
|
|
})
|
|
}
|
|
}
|