@@ -37,9 +37,8 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
37
37
name string
38
38
run func (ctxt context.Context , t * testing.T )
39
39
}{{
40
- // First test: Make sure we get an error if we use no macaroons
41
- // but try to connect to a node that has macaroon authentication
42
- // enabled.
40
+ // Make sure we get an error if we use no macaroons but try to
41
+ // connect to a node that has macaroon authentication enabled.
43
42
name : "no macaroon" ,
44
43
run : func (ctxt context.Context , t * testing.T ) {
45
44
conn , err := testNode .ConnectRPCWithMacaroon (nil )
@@ -51,8 +50,7 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
51
50
require .Contains (t , err .Error (), "expected 1 macaroon" )
52
51
},
53
52
}, {
54
- // Second test: Ensure that an invalid macaroon also triggers an
55
- // error.
53
+ // Ensure that an invalid macaroon also triggers an error.
56
54
name : "invalid macaroon" ,
57
55
run : func (ctxt context.Context , t * testing.T ) {
58
56
invalidMac , _ := macaroon .New (
@@ -68,8 +66,7 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
68
66
require .Contains (t , err .Error (), "invalid ID" )
69
67
},
70
68
}, {
71
- // Third test: Try to access a write method with read-only
72
- // macaroon.
69
+ // Try to access a write method with read-only macaroon.
73
70
name : "read only macaroon" ,
74
71
run : func (ctxt context.Context , t * testing.T ) {
75
72
readonlyMac , err := testNode .ReadMacaroon (
@@ -85,8 +82,8 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
85
82
require .Contains (t , err .Error (), "permission denied" )
86
83
},
87
84
}, {
88
- // Fourth test: Check first-party caveat with timeout that
89
- // expired 30 seconds ago.
85
+ // Check first-party caveat with timeout that expired 30 seconds
86
+ // ago.
90
87
name : "expired macaroon" ,
91
88
run : func (ctxt context.Context , t * testing.T ) {
92
89
readonlyMac , err := testNode .ReadMacaroon (
@@ -106,7 +103,7 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
106
103
require .Contains (t , err .Error (), "macaroon has expired" )
107
104
},
108
105
}, {
109
- // Fifth test: Check first-party caveat with invalid IP address.
106
+ // Check first-party caveat with invalid IP address.
110
107
name : "invalid IP macaroon" ,
111
108
run : func (ctxt context.Context , t * testing.T ) {
112
109
readonlyMac , err := testNode .ReadMacaroon (
@@ -128,7 +125,7 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
128
125
require .Contains (t , err .Error (), "different IP address" )
129
126
},
130
127
}, {
131
- // Sixth test: Make sure that if we do everything correct and
128
+ // Make sure that if we do everything correct and
132
129
// send the admin macaroon with first-party caveats that we can
133
130
// satisfy, we get a correct answer.
134
131
name : "correct macaroon" ,
@@ -149,8 +146,51 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
149
146
assert .Contains (t , res .Address , "bcrt1" )
150
147
},
151
148
}, {
152
- // Seventh test: Bake a macaroon that can only access exactly
153
- // two RPCs and make sure it works as expected.
149
+ // Check first-party caveat with invalid IP range.
150
+ name : "invalid IP range macaroon" ,
151
+ run : func (ctxt context.Context , t * testing.T ) {
152
+ readonlyMac , err := testNode .ReadMacaroon (
153
+ testNode .Cfg .ReadMacPath , defaultTimeout ,
154
+ )
155
+ require .NoError (t , err )
156
+ invalidIPRangeMac , err := macaroons .AddConstraints (
157
+ readonlyMac , macaroons .IPRangeLockConstraint (
158
+ "1.1.1.1/32" ,
159
+ ),
160
+ )
161
+ require .NoError (t , err )
162
+ cleanup , client := macaroonClient (
163
+ t , testNode , invalidIPRangeMac ,
164
+ )
165
+ defer cleanup ()
166
+ _ , err = client .GetInfo (ctxt , infoReq )
167
+ require .Error (t , err )
168
+ require .Contains (t , err .Error (), "different IP range" )
169
+ },
170
+ }, {
171
+ // Make sure that if we do everything correct and send the admin
172
+ // macaroon with first-party caveats that we can satisfy, we get
173
+ // a correct answer.
174
+ name : "correct macaroon" ,
175
+ run : func (ctxt context.Context , t * testing.T ) {
176
+ adminMac , err := testNode .ReadMacaroon (
177
+ testNode .Cfg .AdminMacPath , defaultTimeout ,
178
+ )
179
+ require .NoError (t , err )
180
+ adminMac , err = macaroons .AddConstraints (
181
+ adminMac , macaroons .TimeoutConstraint (30 ),
182
+ macaroons .IPRangeLockConstraint ("127.0.0.0/8" ),
183
+ )
184
+ require .NoError (t , err )
185
+ cleanup , client := macaroonClient (t , testNode , adminMac )
186
+ defer cleanup ()
187
+ res , err := client .NewAddress (ctxt , newAddrReq )
188
+ require .NoError (t , err , "get new address" )
189
+ assert .Contains (t , res .Address , "bcrt1" )
190
+ },
191
+ }, {
192
+ // Bake a macaroon that can only access exactly two RPCs and
193
+ // make sure it works as expected.
154
194
name : "custom URI permissions" ,
155
195
run : func (ctxt context.Context , t * testing.T ) {
156
196
entity := macaroons .PermissionEntityCustomURI
@@ -199,9 +239,9 @@ func testMacaroonAuthentication(ht *lntest.HarnessTest) {
199
239
require .Contains (t , err .Error (), "permission denied" )
200
240
},
201
241
}, {
202
- // Eighth test: check that with the CheckMacaroonPermissions
203
- // RPC, we can check that a macaroon follows (or doesn't)
204
- // permissions and constraints.
242
+ // Check that with the CheckMacaroonPermissions RPC, we can
243
+ // check that a macaroon follows (or doesn't) permissions and
244
+ // constraints.
205
245
name : "unknown permissions" ,
206
246
run : func (ctxt context.Context , t * testing.T ) {
207
247
// A test macaroon created with permissions from pool,
0 commit comments