Skip to content

Commit d856616

Browse files
committed
rpc_proxy+itest: return uniform error for unhandled URI
Currently `basicAuthToMacaroon` returns a different error for an un-handled URI than is returned for other funcions which first check the permissions manager to see if a URI is handled. With this commit, we ensure that the error returned is the same so that the error we assert on in tests can just be one error.
1 parent 089e718 commit d856616

File tree

3 files changed

+30
-43
lines changed

3 files changed

+30
-43
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
422422
endpoint.requestFn,
423423
endpoint.successPattern,
424424
endpointDisabled,
425-
"unknown permissions required for "+
426-
"method",
425+
"unknown request",
427426
)
428427
})
429428
}
@@ -459,8 +458,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
459458
shouldFailWithoutMacaroon,
460459
endpoint.successPattern,
461460
endpointDisabled,
462-
"unknown permissions required for "+
463-
"method",
461+
"unknown request",
464462
)
465463
})
466464
}
@@ -485,8 +483,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
485483
ttt, cfg.LitAddr(), cfg.UIPassword,
486484
endpoint.grpcWebURI,
487485
withoutUIPassword, endpointDisabled,
488-
"unknown permissions required for "+
489-
"method",
486+
"unknown request",
490487
)
491488
})
492489
}
@@ -525,8 +522,7 @@ func integratedTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
525522
endpoint.requestFn,
526523
endpoint.successPattern,
527524
endpointDisabled,
528-
"unknown permissions required for "+
529-
"method",
525+
"unknown request",
530526
)
531527
})
532528
}
@@ -1062,26 +1058,19 @@ func runLNCAuthTest(t *testing.T, rawLNCConn grpc.ClientConnInterface,
10621058
// macaroon permissions properly set up).
10631059
resp, err := makeRequest(ctxt, rawLNCConn)
10641060

1065-
// Is this a disallowed call?
1066-
if !callAllowed {
1067-
if disabled {
1068-
require.ErrorContains(t, err, "unknown permissions "+
1069-
"required for method")
1070-
} else {
1071-
require.ErrorContains(t, err, expectErrContains)
1072-
}
1073-
1074-
return
1075-
}
1076-
1061+
switch {
10771062
// The call should be allowed, so we expect no error unless this is
10781063
// for a disabled sub-server.
1079-
if disabled {
1080-
require.ErrorContains(t, err, "unknown permissions "+
1081-
"required for method")
1064+
case disabled:
1065+
require.ErrorContains(t, err, "unknown request")
10821066

10831067
return
1084-
} else {
1068+
1069+
// Is this a disallowed call?
1070+
case !callAllowed:
1071+
require.ErrorContains(t, err, expectErrContains)
1072+
1073+
default:
10851074
require.NoError(t, err)
10861075
}
10871076

itest/litd_mode_remote_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ func remoteTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
6666
endpoint.requestFn,
6767
endpoint.successPattern,
6868
endpointEnabled,
69-
"unknown permissions required for "+
70-
"method",
69+
"unknown request",
7170
)
7271
})
7372
}
@@ -93,8 +92,7 @@ func remoteTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
9392
shouldFailWithoutMacaroon,
9493
endpoint.successPattern,
9594
endpointEnabled,
96-
"unknown permissions required for "+
97-
"method",
95+
"unknown request",
9896
)
9997
})
10098
}
@@ -117,8 +115,7 @@ func remoteTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
117115
ttt, cfg.LitAddr(), cfg.UIPassword,
118116
endpoint.grpcWebURI, withoutUIPassword,
119117
endpointEnabled,
120-
"unknown permissions required for "+
121-
"method",
118+
"unknown request",
122119
)
123120
})
124121
}
@@ -146,8 +143,7 @@ func remoteTestSuite(ctx context.Context, net *NetworkHarness, t *testing.T,
146143
endpoint.requestFn,
147144
endpoint.successPattern,
148145
endpointEnabled,
149-
"unknown permissions required for "+
150-
"method",
146+
"unknown request",
151147
)
152148
})
153149
}

rpc_proxy.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ const (
3434
HeaderMacaroon = "Macaroon"
3535
)
3636

37-
// ErrWaitingToStart is returned if Lit's rpcProxy is not yet ready to handle
38-
// calls.
39-
var ErrWaitingToStart = fmt.Errorf("waiting for the RPC server to start")
37+
var (
38+
// ErrWaitingToStart is returned if Lit's rpcProxy is not yet ready to
39+
// handle calls.
40+
ErrWaitingToStart = fmt.Errorf("waiting for the RPC server to start")
41+
42+
// ErrUnknownRequest is an error returned when the request URI is
43+
// unknown if the permissions for the request are unknown.
44+
ErrUnknownRequest = fmt.Errorf("unknown request")
45+
)
4046

4147
// proxyErr is an error type that adds more context to an error occurring in the
4248
// proxy.
@@ -375,8 +381,7 @@ func (p *rpcProxy) UnaryServerInterceptor(ctx context.Context, req interface{},
375381

376382
uriPermissions, ok := p.permsMgr.URIPermissions(info.FullMethod)
377383
if !ok {
378-
return nil, fmt.Errorf("%s: unknown permissions "+
379-
"required for method", info.FullMethod)
384+
return nil, ErrUnknownRequest
380385
}
381386

382387
// For now, basic authentication is just a quick fix until we
@@ -420,8 +425,7 @@ func (p *rpcProxy) StreamServerInterceptor(srv interface{},
420425

421426
uriPermissions, ok := p.permsMgr.URIPermissions(info.FullMethod)
422427
if !ok {
423-
return fmt.Errorf("%s: unknown permissions required "+
424-
"for method", info.FullMethod)
428+
return ErrUnknownRequest
425429
}
426430

427431
// For now, basic authentication is just a quick fix until we
@@ -521,8 +525,7 @@ func (p *rpcProxy) basicAuthToMacaroon(basicAuth, requestURI string,
521525
macPath = p.cfg.MacaroonPath
522526

523527
default:
524-
return nil, fmt.Errorf("unknown gRPC web request: %v",
525-
requestURI)
528+
return nil, ErrUnknownRequest
526529
}
527530

528531
switch {
@@ -572,8 +575,7 @@ func (p *rpcProxy) convertSuperMacaroon(ctx context.Context, macHex string,
572575

573576
requiredPermissions, ok := p.permsMgr.URIPermissions(fullMethod)
574577
if !ok {
575-
return nil, fmt.Errorf("%s: unknown permissions required for "+
576-
"method", fullMethod)
578+
return nil, ErrUnknownRequest
577579
}
578580

579581
// We have a super macaroon, from here on out we'll return errors if

0 commit comments

Comments
 (0)