Skip to content

Commit

Permalink
Merge pull request #1427 from atsign-foundation/device-allow-leading-…
Browse files Browse the repository at this point in the history
…underscore

fix: allow leading underscore in device name
  • Loading branch information
gkc authored Oct 7, 2024
2 parents 5f38930 + 0150c6a commit dc08ff9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ class DefaultSshnpdArgs {
static const String deviceGroupName = '__none__';
static const String sshPublicKeyPermissions = "";
static const Duration policyHeartbeatFrequency = Duration(minutes: 5);
static const String permitOpen ='localhost:22,localhost:3389';
static const String permitOpen = 'localhost:22,localhost:3389';
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import 'package:noports_core/src/common/file_system_utils.dart';
import 'package:noports_core/src/common/io_types.dart';
import 'package:path/path.dart' as path;

const String sshnpDeviceNameRegex = r'[a-z0-9][a-z0-9_\-]{1,35}';
const String sshnpDeviceNameRegex = r'[a-z0-9_][a-z0-9_\-]{1,35}';
const String invalidDeviceNameMsg = 'Device name must be alphanumeric'
' snake case, max length 36. First char must be a-z or 0-9.';
const String deviceNameFormatHelp = 'Alphanumeric snake case, max length 36. First char must be a-z or 0-9.';
' snake case, max length 36. First char must be _, a-z, or 0-9.';
const String deviceNameFormatHelp = 'Alphanumeric snake case, max length 36.'
' First char must be _, a-z, or 0-9.';
const String invalidSshKeyPermissionsMsg =
'Detected newline characters in the ssh public key permissions which malforms the authorized_keys file.';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,33 @@ void main() {
throwsA(TypeMatcher<ArgumentError>()));
});
test('SshnpParams.device invalid must start with a-z or 0-9', () {
expect(
() => SshnpParams(
clientAtSign: '',
sshnpdAtSign: '',
srvdAtSign: '',
device: '_abcde-12345-abcde_12345_abcde_12345'),
throwsA(TypeMatcher<ArgumentError>()));
final l = [
'-abcde',
'#abcde',
' abcde',
'@abcde',
'£abcde',
'\$abcde',
'^abcde',
];
for (final s in l) {
expect(
() => SshnpParams(
clientAtSign: '',
sshnpdAtSign: '',
srvdAtSign: '',
device: s),
throwsA(TypeMatcher<ArgumentError>()));
}
});
test('SshnpParams.device may start with underscore', () {
String deviceName = '_my-device-name_12345';
final params = SshnpParams(
clientAtSign: '',
sshnpdAtSign: '',
srvdAtSign: '',
device: deviceName);
expect(params.device, equals(deviceName));
});
test('SshnpParams.device test pure snake case', () {
String deviceName = 'my_device_name_12345';
Expand Down
10 changes: 5 additions & 5 deletions packages/dart/noports_core/test/sshnpd/sshnpd_params_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import 'package:test/test.dart';

void main() {
group('test sshnpd params defaults', () {
test('require at least one of managers and policyManager options', () async {
test('require at least one of managers and policyManager options',
() async {
List<String> args = '-a @daemon'.split(' ');
await expectLater(
() => SshnpdParams.fromArgs(args),
await expectLater(() => SshnpdParams.fromArgs(args),
throwsA(TypeMatcher<ArgumentError>()));
});
test('just managers option supplied', () async {
Expand All @@ -26,7 +26,7 @@ void main() {
final p = await SshnpdParams.fromArgs(args);
expect(p.deviceAtsign, '@daemon');
expect(p.policyManagerAtsign, '@policy');
expect(p.managerAtsigns, ['@bob','@chuck']);
expect(p.managerAtsigns, ['@bob', '@chuck']);
});
test('test permitOpen default without policyManager', () async {
List<String> args = '-a @daemon -m @bob'.split(' ');
Expand Down Expand Up @@ -57,4 +57,4 @@ void main() {
// local-sshd-port
// sshpublickey-permissions
});
}
}

0 comments on commit dc08ff9

Please sign in to comment.