Skip to content

Commit

Permalink
fix: fix how gRPC transport security is determined (#201)
Browse files Browse the repository at this point in the history
* #fix grpc transport secure

* test: added network info secure credentials
  • Loading branch information
ToanBarcelona1998 authored Dec 11, 2023
1 parent b8385cc commit 414bdbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/wallet/network_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 12 additions & 2 deletions test/types/network_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 414bdbf

Please sign in to comment.