Skip to content

Commit e886fa2

Browse files
committed
auth: export mock mint so we can use it elsewhere
1 parent e3d746b commit e886fa2

File tree

3 files changed

+68
-66
lines changed

3 files changed

+68
-66
lines changed

auth/authenticator_test.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,15 @@ import (
99

1010
"github.com/lightninglabs/aperture/auth"
1111
"github.com/lightninglabs/aperture/lsat"
12-
"gopkg.in/macaroon.v2"
1312
)
1413

15-
// createDummyMacHex creates a valid macaroon with dummy content for our tests.
16-
func createDummyMacHex(preimage string) string {
17-
dummyMac, err := macaroon.New(
18-
[]byte("aabbccddeeff00112233445566778899"), []byte("AA=="),
19-
"aperture", macaroon.LatestVersion,
20-
)
21-
if err != nil {
22-
panic(err)
23-
}
24-
preimageCaveat := lsat.Caveat{Condition: lsat.PreimageKey, Value: preimage}
25-
err = lsat.AddFirstPartyCaveats(dummyMac, preimageCaveat)
26-
if err != nil {
27-
panic(err)
28-
}
29-
macBytes, err := dummyMac.MarshalBinary()
30-
if err != nil {
31-
panic(err)
32-
}
33-
return hex.EncodeToString(macBytes)
34-
}
35-
3614
// TestLsatAuthenticator tests that the authenticator properly handles auth
3715
// headers and the tokens contained in them.
3816
func TestLsatAuthenticator(t *testing.T) {
3917
var (
4018
testPreimage = "49349dfea4abed3cd14f6d356afa83de" +
4119
"9787b609f088c8df09bacc7b4bd21b39"
42-
testMacHex = createDummyMacHex(testPreimage)
20+
testMacHex = auth.CreateDummyMacHex(testPreimage)
4321
testMacBytes, _ = hex.DecodeString(testMacHex)
4422
testMacBase64 = base64.StdEncoding.EncodeToString(
4523
testMacBytes,
@@ -139,10 +117,10 @@ func TestLsatAuthenticator(t *testing.T) {
139117
}
140118
)
141119

142-
c := &mockChecker{}
143-
a := auth.NewLsatAuthenticator(&mockMint{}, c)
120+
c := &auth.MockChecker{}
121+
a := auth.NewLsatAuthenticator(&auth.MockMint{}, c)
144122
for _, testCase := range headerTests {
145-
c.err = testCase.checkErr
123+
c.Err = testCase.checkErr
146124
result := a.Accept(testCase.header, "test")
147125
if result != testCase.result {
148126
t.Fatalf("test case %s failed. got %v expected %v",

auth/mock_test.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

auth/test_utils.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package auth
2+
3+
import (
4+
"context"
5+
"encoding/hex"
6+
"time"
7+
8+
"github.com/lightninglabs/aperture/lsat"
9+
"github.com/lightninglabs/aperture/mint"
10+
"github.com/lightningnetwork/lnd/lnrpc"
11+
"github.com/lightningnetwork/lnd/lntypes"
12+
"gopkg.in/macaroon.v2"
13+
)
14+
15+
// CreateDummyMacHex creates a valid macaroon with dummy content for our tests.
16+
func CreateDummyMacHex(preimage string) string {
17+
dummyMac, err := macaroon.New(
18+
[]byte("aabbccddeeff00112233445566778899"), []byte("AA=="),
19+
"aperture", macaroon.LatestVersion,
20+
)
21+
if err != nil {
22+
panic(err)
23+
}
24+
preimageCaveat := lsat.Caveat{
25+
Condition: lsat.PreimageKey,
26+
Value: preimage,
27+
}
28+
err = lsat.AddFirstPartyCaveats(dummyMac, preimageCaveat)
29+
if err != nil {
30+
panic(err)
31+
}
32+
macBytes, err := dummyMac.MarshalBinary()
33+
if err != nil {
34+
panic(err)
35+
}
36+
return hex.EncodeToString(macBytes)
37+
}
38+
39+
type MockMint struct {
40+
}
41+
42+
var _ Minter = (*MockMint)(nil)
43+
44+
func (m *MockMint) MintLSAT(_ context.Context,
45+
services ...lsat.Service) (*macaroon.Macaroon, string, error) {
46+
47+
return nil, "", nil
48+
}
49+
50+
func (m *MockMint) VerifyLSAT(_ context.Context, p *mint.VerificationParams) error {
51+
return nil
52+
}
53+
54+
type MockChecker struct {
55+
Err error
56+
}
57+
58+
var _ InvoiceChecker = (*MockChecker)(nil)
59+
60+
func (m *MockChecker) VerifyInvoiceStatus(lntypes.Hash,
61+
lnrpc.Invoice_InvoiceState, time.Duration) error {
62+
63+
return m.Err
64+
}

0 commit comments

Comments
 (0)