From 7ed8b741cd906b6e8d728a08a5b98c88d9c8309e Mon Sep 17 00:00:00 2001 From: Nic Hite Date: Mon, 30 Sep 2019 01:22:16 -0700 Subject: [PATCH] Add explicit 'localhost' to tests involving server (#242) * Add explicit 'localhost' to tests involving server * Bump version * Clean up CHANGELOG * Revert version bump. --- lib/grpc.dart | 4 +--- lib/src/auth/auth_io.dart | 4 ++-- lib/src/auth/rsa.dart | 2 -- lib/src/client/call.dart | 6 ++---- lib/src/client/transport/http2_credentials.dart | 6 +++--- test/client_handles_bad_connections_test.dart | 6 ++++-- test/round_trip_test.dart | 4 ++-- test/server_handles_broken_connection_test.dart | 2 +- 8 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/grpc.dart b/lib/grpc.dart index 3fe7fd7..1152726 100644 --- a/lib/grpc.dart +++ b/lib/grpc.dart @@ -20,9 +20,7 @@ export 'src/auth/auth.dart' JwtServiceAccountAuthenticator; export 'src/auth/auth_io.dart' - show - ComputeEngineAuthenticator, - ServiceAccountAuthenticator; + show ComputeEngineAuthenticator, ServiceAccountAuthenticator; export 'src/client/call.dart' show CallOptions, ClientCall, MetadataProvider; export 'src/client/client.dart' show Client; diff --git a/lib/src/auth/auth_io.dart b/lib/src/auth/auth_io.dart index 7d7dd8d..f334695 100644 --- a/lib/src/auth/auth_io.dart +++ b/lib/src/auth/auth_io.dart @@ -8,7 +8,7 @@ import 'auth.dart'; class ComputeEngineAuthenticator extends HttpBasedAuthenticator { Future obtainCredentialsWithClient( - http.Client client, String uri) => + http.Client client, String uri) => auth.obtainAccessCredentialsViaMetadataServer(client); } @@ -27,7 +27,7 @@ class ServiceAccountAuthenticator extends HttpBasedAuthenticator { String get projectId => _projectId; Future obtainCredentialsWithClient( - http.Client client, String uri) => + http.Client client, String uri) => auth.obtainAccessCredentialsViaServiceAccount( _serviceAccountCredentials, _scopes, client); } diff --git a/lib/src/auth/rsa.dart b/lib/src/auth/rsa.dart index 56e589f..8d8149f 100644 --- a/lib/src/auth/rsa.dart +++ b/lib/src/auth/rsa.dart @@ -91,7 +91,6 @@ class RS256Signer { } } - class ASN1Parser { static const INTEGER_TAG = 0x02; static const OCTET_STRING_TAG = 0x04; @@ -222,7 +221,6 @@ class ASN1ObjectIdentifier extends ASN1Object { class ASN1Null extends ASN1Object {} - /// Represents integers obtained while creating a Public/Private key pair. class RSAPrivateKey { /// First prime number. diff --git a/lib/src/client/call.dart b/lib/src/client/call.dart index 3085378..267f95b 100644 --- a/lib/src/client/call.dart +++ b/lib/src/client/call.dart @@ -130,7 +130,6 @@ class ClientCall implements Response { return sanitizedMetadata; } - // TODO(sigurdm): Find out why we do this. static String audiencePath(ClientMethod method) { final lastSlashPos = method.path.lastIndexOf('/'); @@ -139,7 +138,6 @@ class ClientCall implements Response { : method.path.substring(0, lastSlashPos); } - void onConnectionReady(ClientConnection connection) { if (isCancelled) return; @@ -149,8 +147,8 @@ class ClientCall implements Response { final metadata = Map.from(options.metadata); Future.forEach( options.metadataProviders, - (provider) => provider( - metadata, '${connection.scheme}://${connection.authority}${audiencePath(_method)}')) + (provider) => provider(metadata, + '${connection.scheme}://${connection.authority}${audiencePath(_method)}')) .then((_) => _sendRequest(connection, _sanitizeMetadata(metadata))) .catchError(_onMetadataProviderError); } diff --git a/lib/src/client/transport/http2_credentials.dart b/lib/src/client/transport/http2_credentials.dart index 90cd11b..6f54f96 100644 --- a/lib/src/client/transport/http2_credentials.dart +++ b/lib/src/client/transport/http2_credentials.dart @@ -48,9 +48,9 @@ class ChannelCredentials { /// [certificates] is not provided, the default trust store is used. const ChannelCredentials.secure( {List certificates, - String password, - String authority, - BadCertificateHandler onBadCertificate}) + String password, + String authority, + BadCertificateHandler onBadCertificate}) : this._(true, certificates, password, authority, onBadCertificate); SecurityContext get securityContext { diff --git a/test/client_handles_bad_connections_test.dart b/test/client_handles_bad_connections_test.dart index a6d104b..59c94de 100644 --- a/test/client_handles_bad_connections_test.dart +++ b/test/client_handles_bad_connections_test.dart @@ -50,7 +50,7 @@ class FixedConnectionClientChannel extends ClientChannelBase { main() async { test('client reconnects after the connection gets old', () async { final grpc.Server server = grpc.Server([TestService()]); - await server.serve(port: 0); + await server.serve(address: 'localhost', port: 0); final channel = FixedConnectionClientChannel(Http2ClientConnection( 'localhost', @@ -75,7 +75,9 @@ main() async { test('client reconnects when stream limit is used', () async { final grpc.Server server = grpc.Server([TestService()]); await server.serve( - port: 0, http2ServerSettings: ServerSettings(concurrentStreamLimit: 2)); + address: 'localhost', + port: 0, + http2ServerSettings: ServerSettings(concurrentStreamLimit: 2)); final channel = FixedConnectionClientChannel(Http2ClientConnection( 'localhost', diff --git a/test/round_trip_test.dart b/test/round_trip_test.dart index 3a70a30..2ce5ee6 100644 --- a/test/round_trip_test.dart +++ b/test/round_trip_test.dart @@ -6,7 +6,6 @@ import 'package:grpc/service_api.dart' as api; import 'package:grpc/src/client/channel.dart' hide ClientChannel; import 'package:grpc/src/client/connection.dart'; import 'package:grpc/src/client/http2_connection.dart'; -import 'package:http2/http2.dart'; import 'package:test/test.dart'; class TestClient extends Client { @@ -49,7 +48,7 @@ class FixedConnectionClientChannel extends ClientChannelBase { main() async { test('round trip insecure connection', () async { final Server server = Server([TestService()]); - await server.serve(port: 0); + await server.serve(address: 'localhost', port: 0); final channel = FixedConnectionClientChannel(Http2ClientConnection( 'localhost', @@ -64,6 +63,7 @@ main() async { test('round trip secure connection', () async { final Server server = Server([TestService()]); await server.serve( + address: 'localhost', port: 0, security: ServerTlsCredentials( certificate: File('test/data/localhost.crt').readAsBytesSync(), diff --git a/test/server_handles_broken_connection_test.dart b/test/server_handles_broken_connection_test.dart index 0c5fc96..f3b3208 100644 --- a/test/server_handles_broken_connection_test.dart +++ b/test/server_handles_broken_connection_test.dart @@ -76,7 +76,7 @@ main() async { server.shutdown(); }, reason: 'the producer should get cancelled')) ]); - await server.serve(port: 0); + await server.serve(address: 'localhost', port: 0); final receivePort = ReceivePort(); Isolate.spawn( client, ClientData(port: server.port, sendPort: receivePort.sendPort));