69 lines
2 KiB
Dart
69 lines
2 KiB
Dart
|
|
import 'package:halkyon_base_server/base.dart';
|
||
|
|
import 'package:test/test.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
group('The accounts mode from the environment', () {
|
||
|
|
test('without settings, the server holds its own register, with no '
|
||
|
|
'members', () {
|
||
|
|
final mode = AccountsMode.fromEnvironment(const {});
|
||
|
|
|
||
|
|
expect(mode, isA<HoldsRegister>());
|
||
|
|
expect((mode as HoldsRegister).members, isEmpty);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the register tells the members it names, separated by commas or '
|
||
|
|
'spaces', () {
|
||
|
|
final mode = AccountsMode.fromEnvironment(const {
|
||
|
|
'INSTANCE_MEMBERS': ' https://todo.example.com, http://todo:8082 ',
|
||
|
|
});
|
||
|
|
|
||
|
|
expect((mode as HoldsRegister).members, [
|
||
|
|
Uri.parse('https://todo.example.com'),
|
||
|
|
Uri.parse('http://todo:8082'),
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('a register named makes the server its member', () {
|
||
|
|
final mode = AccountsMode.fromEnvironment(const {
|
||
|
|
'ACCOUNT_REGISTER_URL': 'http://learn:8082',
|
||
|
|
'INSTANCE_MEMBERS': 'http://ignored',
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(
|
||
|
|
(mode as MemberOfRegister).register,
|
||
|
|
Uri.parse('http://learn:8082'),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('empty values count as unset, as Compose passes them on', () {
|
||
|
|
expect(
|
||
|
|
AccountsMode.fromEnvironment(const {
|
||
|
|
'ACCOUNT_REGISTER_URL': '',
|
||
|
|
'INSTANCE_MEMBERS': ' ',
|
||
|
|
}),
|
||
|
|
isA<HoldsRegister>(),
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('anything but an HTTP(S) address is refused, not guessed at', () {
|
||
|
|
expect(
|
||
|
|
() => AccountsMode.fromEnvironment(const {
|
||
|
|
'ACCOUNT_REGISTER_URL': 'learn:8082',
|
||
|
|
}),
|
||
|
|
throwsArgumentError,
|
||
|
|
);
|
||
|
|
expect(
|
||
|
|
() => AccountsMode.fromEnvironment(const {
|
||
|
|
'INSTANCE_MEMBERS': 'ftp://todo',
|
||
|
|
}),
|
||
|
|
throwsArgumentError,
|
||
|
|
);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
test('the shared secret is the same only when it is', () {
|
||
|
|
expect(isInstanceSecret('s3cret', 's3cret'), isTrue);
|
||
|
|
expect(isInstanceSecret('s3cret!', 's3cret'), isFalse);
|
||
|
|
expect(isInstanceSecret('', 's3cret'), isFalse);
|
||
|
|
});
|
||
|
|
}
|