Skip to content

Commit 392ac82

Browse files
committed
auth: export mock mint so we can use it elsewhere
1 parent 651b232 commit 392ac82

File tree

3 files changed

+65
-66
lines changed

3 files changed

+65
-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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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{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+
36+
type MockMint struct {
37+
}
38+
39+
var _ Minter = (*MockMint)(nil)
40+
41+
func (m *MockMint) MintLSAT(_ context.Context,
42+
services ...lsat.Service) (*macaroon.Macaroon, string, error) {
43+
44+
return nil, "", nil
45+
}
46+
47+
func (m *MockMint) VerifyLSAT(_ context.Context, p *mint.VerificationParams) error {
48+
return nil
49+
}
50+
51+
type MockChecker struct {
52+
Err error
53+
}
54+
55+
var _ InvoiceChecker = (*MockChecker)(nil)
56+
57+
func (m *MockChecker) VerifyInvoiceStatus(lntypes.Hash,
58+
lnrpc.Invoice_InvoiceState, time.Duration) error {
59+
60+
return m.Err
61+
}

0 commit comments

Comments
 (0)