Skip to content

Commit

Permalink
Fixed linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vicajilau committed Aug 29, 2024
1 parent 5a784b7 commit d29b77a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 49 deletions.
75 changes: 42 additions & 33 deletions test/src/algorithm/ssh_cipher_type_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'dart:typed_data';

import 'package:dartssh2/dartssh2.dart';
import 'package:dartssh2/src/ssh_algorithm.dart';
import 'package:dartssh2/src/utils/cipher_ext.dart';
import 'package:test/test.dart';
import 'dart:typed_data';

void main() {
testCipher(SSHCipherType.aes128cbc);
Expand Down Expand Up @@ -42,41 +43,49 @@ void main() {
test('Default values are set correctly', () {
final algorithms = SSHAlgorithms();

expect(algorithms.kex, equals([
SSHKexType.x25519,
SSHKexType.nistp521,
SSHKexType.nistp384,
SSHKexType.nistp256,
SSHKexType.dhGexSha256,
SSHKexType.dh14Sha256,
SSHKexType.dh14Sha1,
SSHKexType.dhGexSha1,
SSHKexType.dh1Sha1,
]));
expect(
algorithms.kex,
equals([
SSHKexType.x25519,
SSHKexType.nistp521,
SSHKexType.nistp384,
SSHKexType.nistp256,
SSHKexType.dhGexSha256,
SSHKexType.dh14Sha256,
SSHKexType.dh14Sha1,
SSHKexType.dhGexSha1,
SSHKexType.dh1Sha1,
]));

expect(algorithms.hostkey, equals([
SSHHostkeyType.ed25519,
SSHHostkeyType.rsaSha512,
SSHHostkeyType.rsaSha256,
SSHHostkeyType.rsaSha1,
SSHHostkeyType.ecdsa521,
SSHHostkeyType.ecdsa384,
SSHHostkeyType.ecdsa256,
]));
expect(
algorithms.hostkey,
equals([
SSHHostkeyType.ed25519,
SSHHostkeyType.rsaSha512,
SSHHostkeyType.rsaSha256,
SSHHostkeyType.rsaSha1,
SSHHostkeyType.ecdsa521,
SSHHostkeyType.ecdsa384,
SSHHostkeyType.ecdsa256,
]));

expect(algorithms.cipher, equals([
SSHCipherType.aes128ctr,
SSHCipherType.aes128cbc,
SSHCipherType.aes256ctr,
SSHCipherType.aes256cbc,
]));
expect(
algorithms.cipher,
equals([
SSHCipherType.aes128ctr,
SSHCipherType.aes128cbc,
SSHCipherType.aes256ctr,
SSHCipherType.aes256cbc,
]));

expect(algorithms.mac, equals([
SSHMacType.hmacSha1,
SSHMacType.hmacSha256,
SSHMacType.hmacSha512,
SSHMacType.hmacMd5,
]));
expect(
algorithms.mac,
equals([
SSHMacType.hmacSha1,
SSHMacType.hmacSha256,
SSHMacType.hmacSha512,
SSHMacType.hmacMd5,
]));
});
}

Expand Down
21 changes: 14 additions & 7 deletions test/src/algorithm/ssh_hostkey_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ void main() {
});

test('toString() returns correct format', () {
expect(SSHHostkeyType.rsaSha1.toString(), equals('SSHHostkeyType(ssh-rsa)'));
expect(SSHHostkeyType.rsaSha256.toString(), equals('SSHHostkeyType(rsa-sha2-256)'));
expect(SSHHostkeyType.rsaSha512.toString(), equals('SSHHostkeyType(rsa-sha2-512)'));
expect(SSHHostkeyType.ecdsa256.toString(), equals('SSHHostkeyType(ecdsa-sha2-nistp256)'));
expect(SSHHostkeyType.ecdsa384.toString(), equals('SSHHostkeyType(ecdsa-sha2-nistp384)'));
expect(SSHHostkeyType.ecdsa521.toString(), equals('SSHHostkeyType(ecdsa-sha2-nistp521)'));
expect(SSHHostkeyType.ed25519.toString(), equals('SSHHostkeyType(ssh-ed25519)'));
expect(
SSHHostkeyType.rsaSha1.toString(), equals('SSHHostkeyType(ssh-rsa)'));
expect(SSHHostkeyType.rsaSha256.toString(),
equals('SSHHostkeyType(rsa-sha2-256)'));
expect(SSHHostkeyType.rsaSha512.toString(),
equals('SSHHostkeyType(rsa-sha2-512)'));
expect(SSHHostkeyType.ecdsa256.toString(),
equals('SSHHostkeyType(ecdsa-sha2-nistp256)'));
expect(SSHHostkeyType.ecdsa384.toString(),
equals('SSHHostkeyType(ecdsa-sha2-nistp384)'));
expect(SSHHostkeyType.ecdsa521.toString(),
equals('SSHHostkeyType(ecdsa-sha2-nistp521)'));
expect(SSHHostkeyType.ed25519.toString(),
equals('SSHHostkeyType(ssh-ed25519)'));
});
});
}
17 changes: 12 additions & 5 deletions test/src/algorithm/ssh_kex_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ void main() {
expect(SSHKexType.nistp256.name, equals('ecdh-sha2-nistp256'));
expect(SSHKexType.nistp384.name, equals('ecdh-sha2-nistp384'));
expect(SSHKexType.nistp521.name, equals('ecdh-sha2-nistp521'));
expect(SSHKexType.dhGexSha256.name, equals('diffie-hellman-group-exchange-sha256'));
expect(SSHKexType.dhGexSha1.name, equals('diffie-hellman-group-exchange-sha1'));
expect(SSHKexType.dhGexSha256.name,
equals('diffie-hellman-group-exchange-sha256'));
expect(SSHKexType.dhGexSha1.name,
equals('diffie-hellman-group-exchange-sha1'));
expect(SSHKexType.dh14Sha1.name, equals('diffie-hellman-group14-sha1'));
expect(SSHKexType.dh14Sha256.name, equals('diffie-hellman-group14-sha256'));
expect(
SSHKexType.dh14Sha256.name, equals('diffie-hellman-group14-sha256'));
expect(SSHKexType.dh1Sha1.name, equals('diffie-hellman-group1-sha1'));
});

test('Static constants have correct digestFactory and isGroupExchange values', () {
test(
'Static constants have correct digestFactory and isGroupExchange values',
() {
expect(SSHKexType.x25519.digestFactory, equals(digestSha256));
expect(SSHKexType.nistp256.digestFactory, equals(digestSha256));
expect(SSHKexType.nistp384.digestFactory, equals(digestSha384));
Expand All @@ -40,7 +45,9 @@ void main() {
expect(digest, isA<SHA256Digest>());
});

test('createDigest() returns correct Digest instance for different algorithms', () {
test(
'createDigest() returns correct Digest instance for different algorithms',
() {
final kexTypeSha1 = SSHKexType.dhGexSha1;
final digestSha1 = kexTypeSha1.createDigest();
expect(digestSha1, isA<SHA1Digest>());
Expand Down
5 changes: 3 additions & 2 deletions test/src/algorithm/ssh_mac_type_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:typed_data';

import 'package:dartssh2/dartssh2.dart';
import 'package:pointycastle/export.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -26,13 +27,13 @@ void main() {
test('createMac() throws ArgumentError for incorrect key length', () {
final shortKey = Uint8List(15); // One byte too short for hmacMd5
expect(
() => SSHMacType.hmacMd5.createMac(shortKey),
() => SSHMacType.hmacMd5.createMac(shortKey),
throwsArgumentError,
);

final longKey = Uint8List(17); // One byte too long for hmacMd5
expect(
() => SSHMacType.hmacMd5.createMac(longKey),
() => SSHMacType.hmacMd5.createMac(longKey),
throwsArgumentError,
);
});
Expand Down
6 changes: 4 additions & 2 deletions test/src/mocks/mock_ssh_http_headers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class MockSSHHttpHeaders extends SSHHttpHeaders {
@override
void add(String name, Object value, {bool preserveHeaderCase = false}) {
final headerName = preserveHeaderCase ? name : name.toLowerCase();
final valueStr = value is DateTime ? value.toIso8601String() : value.toString();
final valueStr =
value is DateTime ? value.toIso8601String() : value.toString();
_headers.putIfAbsent(headerName, () => []).add(valueStr);
}

@override
void set(String name, Object value, {bool preserveHeaderCase = false}) {
final headerName = preserveHeaderCase ? name : name.toLowerCase();
final valueStr = value is DateTime ? value.toIso8601String() : value.toString();
final valueStr =
value is DateTime ? value.toIso8601String() : value.toString();
_headers[headerName] = [valueStr];
}

Expand Down

0 comments on commit d29b77a

Please sign in to comment.