From 414bdbfacda0c871c9ff4248bd1010fb0ad6bcf2 Mon Sep 17 00:00:00 2001 From: ToanBarcelona1998 <77067868+ToanBarcelona1998@users.noreply.github.com> Date: Mon, 11 Dec 2023 22:51:22 +0700 Subject: [PATCH] fix: fix how gRPC transport security is determined (#201) * #fix grpc transport secure * test: added network info secure credentials --- lib/wallet/network_info.dart | 2 +- test/types/network_info_test.dart | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/wallet/network_info.dart b/lib/wallet/network_info.dart index dc5ec984..14fbf6f2 100644 --- a/lib/wallet/network_info.dart +++ b/lib/wallet/network_info.dart @@ -63,7 +63,7 @@ class GRPCInfo extends Equatable { return GrpcOrGrpcWebClientChannel.toSeparateEndpoints( grpcHost: host.replaceFirst(RegExp('http(s)?://'), ''), grpcPort: port, - grpcTransportSecure: credentials == ChannelCredentials.secure(), + grpcTransportSecure: credentials.isSecure, grpcWebHost: finaleWebHost.replaceFirst(RegExp('http(s)?://'), ''), grpcWebPort: webPort, grpcWebTransportSecure: webTransportSecure, diff --git a/test/types/network_info_test.dart b/test/types/network_info_test.dart index 96236a68..fe027237 100644 --- a/test/types/network_info_test.dart +++ b/test/types/network_info_test.dart @@ -6,24 +6,34 @@ void main() { group('GRPCInfo', () { group('toJson and fromJson work properly', () { test('with secure credentials', () { + final channelCredential = ChannelCredentials.secure(); final grpcInfo = GRPCInfo( host: 'localhost', port: 1111, - credentials: ChannelCredentials.secure(), + credentials: channelCredential, ); + final channel = grpcInfo.getChannel(); + + expect(channel.options.credentials.isSecure, true); + final json = grpcInfo.toJson(); final fromJson = GRPCInfo.fromJson(json); expect(fromJson, equals(grpcInfo)); }); test('with insecure credentials', () { + final channelCredential = ChannelCredentials.insecure(); final grpcInfo = GRPCInfo( host: 'localhost', port: 1111, - credentials: ChannelCredentials.insecure(), + credentials: channelCredential, ); + final channel = grpcInfo.getChannel(); + + expect(channel.options.credentials.isSecure, false); + final json = grpcInfo.toJson(); final fromJson = GRPCInfo.fromJson(json); expect(fromJson, equals(grpcInfo));