80 lines
2.4 KiB
Dart
80 lines
2.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shuffle/features/auth/data/asset_common_password_list.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('KTO-01 Kriterium 3: common password asset', () {
|
|
late List<String> lines;
|
|
|
|
setUpAll(() {
|
|
lines = File(AssetCommonPasswordList.assetPath)
|
|
.readAsStringSync()
|
|
.split('\n')
|
|
.where((l) => l.isNotEmpty)
|
|
.toList();
|
|
});
|
|
|
|
test('has a bounded size', () {
|
|
expect(lines.length, inInclusiveRange(5000, 15000));
|
|
expect(
|
|
File(AssetCommonPasswordList.assetPath).lengthSync(),
|
|
lessThan(200 * 1024),
|
|
);
|
|
});
|
|
|
|
test('contains only normalized entries of at least 10 code points', () {
|
|
for (final line in lines) {
|
|
expect(line.runes.length, greaterThanOrEqualTo(10), reason: line);
|
|
expect(line, line.trim(), reason: line);
|
|
expect(line, line.toLowerCase(), reason: line);
|
|
expect(line.startsWith('#'), isFalse, reason: line);
|
|
}
|
|
});
|
|
|
|
test('has no duplicates', () {
|
|
expect(lines.toSet().length, lines.length);
|
|
});
|
|
|
|
test('is declared as a bundle asset and loads lazily into a set', () async {
|
|
final list = await const AssetCommonPasswordList().load();
|
|
|
|
expect(list.contains('passwort1234'), isTrue);
|
|
expect(list.contains('Hallo12345'), isTrue);
|
|
expect(list.contains(' PASSWORT1234 '), isTrue);
|
|
expect(list.contains('korrekt-pferd-batterie-heftklammer'), isFalse);
|
|
});
|
|
|
|
test('fails loudly if the asset is missing', () async {
|
|
await expectLater(
|
|
AssetCommonPasswordList(bundle: _EmptyBundle()).load(),
|
|
throwsA(isA<FlutterError>()),
|
|
);
|
|
});
|
|
});
|
|
|
|
group('parseCommonPasswords', () {
|
|
test('normalizes lines and skips blanks and comments', () {
|
|
final list = parseCommonPasswords(
|
|
'# c\n\n ABCDEFGHIJ \r\nklmnopqrstu\n',
|
|
);
|
|
|
|
expect(list.contains('abcdefghij'), isTrue);
|
|
expect(list.contains('klmnopqrstu'), isTrue);
|
|
expect(list.contains('# c'), isFalse);
|
|
expect(list.contains(''), isFalse);
|
|
});
|
|
});
|
|
}
|
|
|
|
class _EmptyBundle extends CachingAssetBundle {
|
|
_EmptyBundle();
|
|
|
|
@override
|
|
Future<ByteData> load(String key) =>
|
|
Future.error(FlutterError('missing asset $key'));
|
|
}
|