@@ -87,7 +87,7 @@ type testCase struct {
87
87
expectedIP netip.Addr
88
88
}
89
89
90
- func (c testCase ) optsFromTesCase () []Option {
90
+ func (c * testCase ) optsFromTestCase () []Option {
91
91
return []Option {
92
92
WithTrustedPeers (c .trustedPeers ),
93
93
WithTrustedProxies (c .trustedProxies ),
@@ -96,8 +96,8 @@ func (c testCase) optsFromTesCase() []Option {
96
96
}
97
97
}
98
98
99
- func testUnaryServerInterceptor (t * testing.T , c testCase ) {
100
- interceptor := UnaryServerInterceptorOpts (c .optsFromTesCase ()... )
99
+ func testUnaryServerInterceptor (t * testing.T , c * testCase ) {
100
+ interceptor := UnaryServerInterceptorOpts (c .optsFromTestCase ()... )
101
101
handler := func (ctx context.Context , req any ) (any , error ) {
102
102
ip , _ := FromContext (ctx )
103
103
@@ -121,8 +121,8 @@ func testUnaryServerInterceptor(t *testing.T, c testCase) {
121
121
assert .NoError (t , err )
122
122
}
123
123
124
- func testStreamServerInterceptor (t * testing.T , c testCase ) {
125
- interceptor := StreamServerInterceptorOpts (c .optsFromTesCase ()... )
124
+ func testStreamServerInterceptor (t * testing.T , c * testCase ) {
125
+ interceptor := StreamServerInterceptorOpts (c .optsFromTestCase ()... )
126
126
handler := func (srv any , stream grpc.ServerStream ) error {
127
127
ip , _ := FromContext (stream .Context ())
128
128
@@ -147,7 +147,7 @@ func testStreamServerInterceptor(t *testing.T, c testCase) {
147
147
148
148
func TestInterceptor (t * testing.T ) {
149
149
t .Run ("no peer" , func (t * testing.T ) {
150
- tc := testCase {
150
+ tc := & testCase {
151
151
// Test that if there is no peer, we don't get an IP.
152
152
trustedPeers : localnet ,
153
153
headerKeys : []string {XForwardedFor },
@@ -165,7 +165,7 @@ func TestInterceptor(t *testing.T) {
165
165
})
166
166
})
167
167
t .Run ("trusted peer header csv" , func (t * testing.T ) {
168
- tc := testCase {
168
+ tc := & testCase {
169
169
// Test that if the remote peer is trusted and the header contains
170
170
// a comma separated list of valid IPs, we get right most one.
171
171
trustedPeers : localnet ,
@@ -184,7 +184,7 @@ func TestInterceptor(t *testing.T) {
184
184
})
185
185
})
186
186
t .Run ("trusted proxy list with XForwardedFor" , func (t * testing.T ) {
187
- tc := testCase {
187
+ tc := & testCase {
188
188
// Test that if the remote peer is trusted and the header contains
189
189
// a comma separated list of valid IPs,
190
190
// we get the first going from right to left that is not in local net
@@ -205,7 +205,7 @@ func TestInterceptor(t *testing.T) {
205
205
})
206
206
})
207
207
t .Run ("trusted proxy list private net with XForwardedFor" , func (t * testing.T ) {
208
- tc := testCase {
208
+ tc := & testCase {
209
209
// Test that if the remote peer is trusted and the header contains
210
210
// a comma separated list of valid IPs,
211
211
// we get the first going from right to left that is not in private net
@@ -226,7 +226,7 @@ func TestInterceptor(t *testing.T) {
226
226
})
227
227
})
228
228
t .Run ("trusted proxy count with XForwardedFor" , func (t * testing.T ) {
229
- tc := testCase {
229
+ tc := & testCase {
230
230
// Test that if the remote peer is trusted and the header contains
231
231
// a comma separated list of valid IPs, we get right most one -1 proxiesCount.
232
232
trustedPeers : localnet ,
@@ -246,7 +246,7 @@ func TestInterceptor(t *testing.T) {
246
246
})
247
247
})
248
248
t .Run ("wrong trusted proxy count with XForwardedFor" , func (t * testing.T ) {
249
- tc := testCase {
249
+ tc := & testCase {
250
250
// Test that if the remote peer is trusted and the header contains
251
251
// a comma separated list of valid IPs,
252
252
// we get peer ip as the proxiesCount is wrongly configured
@@ -267,7 +267,7 @@ func TestInterceptor(t *testing.T) {
267
267
})
268
268
})
269
269
t .Run ("trusted peer single" , func (t * testing.T ) {
270
- tc := testCase {
270
+ tc := & testCase {
271
271
// Test that if the remote peer is trusted and the header contains
272
272
// a single valid IP, we get that IP.
273
273
trustedPeers : localnet ,
@@ -286,7 +286,7 @@ func TestInterceptor(t *testing.T) {
286
286
})
287
287
})
288
288
t .Run ("trusted peer multiple" , func (t * testing.T ) {
289
- tc := testCase {
289
+ tc := & testCase {
290
290
// Test that if the trusted peers list is larger than 1 network and
291
291
// the remote peer is in the third network, we get the right IP.
292
292
trustedPeers : privatenet ,
@@ -305,7 +305,7 @@ func TestInterceptor(t *testing.T) {
305
305
})
306
306
})
307
307
t .Run ("untrusted peer single" , func (t * testing.T ) {
308
- tc := testCase {
308
+ tc := & testCase {
309
309
// Test that if the remote peer is not trusted and the header
310
310
// contains a single valid IP, we get that the peer IP.
311
311
trustedPeers : localnet ,
@@ -324,7 +324,7 @@ func TestInterceptor(t *testing.T) {
324
324
})
325
325
})
326
326
t .Run ("trusted peer multiple headers" , func (t * testing.T ) {
327
- tc := testCase {
327
+ tc := & testCase {
328
328
// Test that if the peer is trusted and several headers are
329
329
// provided, the interceptor reads the IP from the first header in
330
330
// the list.
@@ -345,7 +345,7 @@ func TestInterceptor(t *testing.T) {
345
345
})
346
346
})
347
347
t .Run ("trusted peer multiple header configured single provided" , func (t * testing.T ) {
348
- tc := testCase {
348
+ tc := & testCase {
349
349
// Test that if the peer is trusted and several headers are
350
350
// configured, but only one is provided, the interceptor reads the
351
351
// IP from the provided header.
@@ -365,7 +365,7 @@ func TestInterceptor(t *testing.T) {
365
365
})
366
366
})
367
367
t .Run ("trusted peer multiple header configured none provided" , func (t * testing.T ) {
368
- tc := testCase {
368
+ tc := & testCase {
369
369
// Test that if the peer is trusted and several headers are, but no
370
370
// header is provided, the interceptor reads the IP from the peer.
371
371
//
@@ -384,7 +384,7 @@ func TestInterceptor(t *testing.T) {
384
384
})
385
385
})
386
386
t .Run ("untrusted peer multiple headers" , func (t * testing.T ) {
387
- tc := testCase {
387
+ tc := & testCase {
388
388
// Test that if the peer is not trusted, but several headers are
389
389
// provided, the interceptor reads the IP from peer.
390
390
trustedPeers : nil ,
@@ -403,7 +403,7 @@ func TestInterceptor(t *testing.T) {
403
403
})
404
404
})
405
405
t .Run ("untrusted peer multiple header configured single provided" , func (t * testing.T ) {
406
- tc := testCase {
406
+ tc := & testCase {
407
407
// Test that if the peer is not trusted and several headers are
408
408
// configured, but only one is provided, the interceptor reads the
409
409
// IP from the peer.
@@ -426,7 +426,7 @@ func TestInterceptor(t *testing.T) {
426
426
})
427
427
})
428
428
t .Run ("trusted peer malformed header" , func (t * testing.T ) {
429
- tc := testCase {
429
+ tc := & testCase {
430
430
// Test that if the peer is trusted, but the provided headers
431
431
// contain malformed IP addresses, the interceptor reads the IP
432
432
// from the peer.
@@ -446,7 +446,7 @@ func TestInterceptor(t *testing.T) {
446
446
})
447
447
})
448
448
t .Run ("ipv6 from grpc peer" , func (t * testing.T ) {
449
- tc := testCase {
449
+ tc := & testCase {
450
450
trustedPeers : localnet ,
451
451
headerKeys : []string {},
452
452
peer : localhost6Peer (),
@@ -460,7 +460,7 @@ func TestInterceptor(t *testing.T) {
460
460
})
461
461
})
462
462
t .Run ("ipv6 from header" , func (t * testing.T ) {
463
- tc := testCase {
463
+ tc := & testCase {
464
464
trustedPeers : privatenet ,
465
465
headerKeys : []string {XForwardedFor },
466
466
inputHeaders : map [string ]string {
@@ -477,7 +477,7 @@ func TestInterceptor(t *testing.T) {
477
477
})
478
478
})
479
479
t .Run ("unix" , func (t * testing.T ) {
480
- tc := testCase {
480
+ tc := & testCase {
481
481
trustedPeers : localnet ,
482
482
headerKeys : []string {XRealIp },
483
483
peer : & peer.Peer {
@@ -493,7 +493,7 @@ func TestInterceptor(t *testing.T) {
493
493
})
494
494
})
495
495
t .Run ("header casing" , func (t * testing.T ) {
496
- tc := testCase {
496
+ tc := & testCase {
497
497
// Test that header casing is ignored.
498
498
trustedPeers : localnet ,
499
499
headerKeys : []string {XRealIp },
0 commit comments