Shuffle/app/test/features/auth/data/common_passwords_test.dart
cschlaefke 54337ffc59 feat(auth): add auth domain, repository, validators and router redirects
Refs #1

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-03 00:09:47 +01:00

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'));
}