2022-05-11 22:42:14 +03:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
2022-09-11 12:05:00 +03:00
|
|
|
import 'package:yubico_authenticator/core/state.dart';
|
2022-09-12 13:58:17 +03:00
|
|
|
import 'package:yubico_authenticator/oath/keys.dart' as keys;
|
2022-05-11 22:42:14 +03:00
|
|
|
|
2022-09-12 07:34:49 +03:00
|
|
|
import 'oath_test_util.dart';
|
2022-05-12 16:35:14 +03:00
|
|
|
import 'test_util.dart';
|
|
|
|
|
2022-05-11 22:42:14 +03:00
|
|
|
void main() {
|
2022-09-12 07:34:49 +03:00
|
|
|
var binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
2022-05-11 22:42:14 +03:00
|
|
|
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
|
|
|
|
2022-09-13 13:32:13 +03:00
|
|
|
group('OATH UI tests', () {
|
|
|
|
appTest('Menu items exist', (WidgetTester tester) async {
|
2022-07-21 16:42:47 +03:00
|
|
|
await tester.tapDeviceButton();
|
2022-09-12 13:58:17 +03:00
|
|
|
expect(find.byKey(keys.addAccountAction), findsOneWidget);
|
|
|
|
expect(find.byKey(keys.setOrManagePasswordAction), findsOneWidget);
|
|
|
|
expect(find.byKey(keys.resetAction), findsOneWidget);
|
2022-07-21 16:42:47 +03:00
|
|
|
});
|
2022-09-11 12:05:00 +03:00
|
|
|
});
|
2022-07-21 16:42:47 +03:00
|
|
|
|
2022-09-11 12:05:00 +03:00
|
|
|
group('OATH Account tests', () {
|
2022-09-13 13:32:13 +03:00
|
|
|
appTest('Create account', (WidgetTester tester) async {
|
2022-09-11 12:05:00 +03:00
|
|
|
// account with issuer
|
|
|
|
var testAccount = const Account(
|
|
|
|
issuer: 'IssuerForTests',
|
|
|
|
name: 'NameForTests',
|
|
|
|
secret: 'aaaaaaaaaaaaaaaa',
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.deleteAccount(testAccount);
|
|
|
|
await tester.addAccount(testAccount, quiet: false);
|
|
|
|
|
|
|
|
// account without issuer
|
|
|
|
testAccount = const Account(
|
|
|
|
name: 'NoIssuerName',
|
|
|
|
secret: 'bbbbbbbbbbbbbbbb',
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.deleteAccount(testAccount);
|
|
|
|
await tester.addAccount(testAccount, quiet: false);
|
2022-07-21 16:42:47 +03:00
|
|
|
});
|
|
|
|
|
2022-09-12 08:01:10 +03:00
|
|
|
/// deletes accounts created in previous test
|
2022-09-13 13:32:13 +03:00
|
|
|
appTest('Delete account', (WidgetTester tester) async {
|
2022-09-11 12:05:00 +03:00
|
|
|
var testAccount =
|
|
|
|
const Account(issuer: 'IssuerForTests', name: 'NameForTests');
|
|
|
|
|
|
|
|
await tester.deleteAccount(testAccount, quiet: false);
|
|
|
|
expect(await tester.findAccount(testAccount), isNull);
|
|
|
|
|
|
|
|
testAccount = const Account(issuer: null, name: 'NoIssuerName');
|
|
|
|
await tester.deleteAccount(testAccount, quiet: false);
|
|
|
|
expect(await tester.findAccount(testAccount), isNull);
|
|
|
|
});
|
|
|
|
|
2022-09-12 08:01:10 +03:00
|
|
|
/// adds an account, renames, verifies
|
2022-09-13 13:32:13 +03:00
|
|
|
appTest('Rename account', (WidgetTester tester) async {
|
2022-09-11 12:05:00 +03:00
|
|
|
var testAccount =
|
|
|
|
const Account(issuer: 'IssuerToRename', name: 'NameToRename');
|
|
|
|
|
2022-09-12 08:01:10 +03:00
|
|
|
/// delete account if it exists
|
2022-09-11 12:05:00 +03:00
|
|
|
await tester.deleteAccount(testAccount);
|
|
|
|
await tester.deleteAccount(
|
|
|
|
const Account(issuer: 'RenamedIssuer', name: 'RenamedName'));
|
|
|
|
|
|
|
|
await tester.addAccount(testAccount);
|
|
|
|
await tester.renameAccount(testAccount, 'RenamedIssuer', 'RenamedName');
|
2022-07-21 16:42:47 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-13 13:32:13 +03:00
|
|
|
group('OATH Password tests', () {
|
2022-09-12 08:01:10 +03:00
|
|
|
/// note that the password groups should be run as whole
|
2022-09-13 13:32:13 +03:00
|
|
|
|
|
|
|
/// TODO implement test for password replacement
|
|
|
|
/// appTest('OATH: replace oath password', (WidgetTester tester) async {
|
|
|
|
/// await tester.replaceOathPassword('aaa111', 'bbb222');
|
|
|
|
/// });
|
|
|
|
|
|
|
|
// cannot restart the app on Android to be able to unlock
|
|
|
|
group('OATH: remove oath password when unlocked', skip: isAndroid, () {
|
|
|
|
var testPassword = 'testPassword';
|
|
|
|
|
|
|
|
appTest('OATH: set oath password', (WidgetTester tester) async {
|
|
|
|
await tester.setOathPassword(testPassword);
|
|
|
|
});
|
|
|
|
|
|
|
|
appTest('OATH: remove oath password', (WidgetTester tester) async {
|
|
|
|
await tester.unlockOathSession(testPassword);
|
|
|
|
await tester.removeOathPassword(testPassword);
|
|
|
|
});
|
2022-09-12 07:34:49 +03:00
|
|
|
});
|
|
|
|
|
2022-09-13 13:32:13 +03:00
|
|
|
group('OATH: remove oath password when locked', () {
|
|
|
|
var testPassword = 'testPasswordX';
|
2022-09-12 07:34:49 +03:00
|
|
|
|
2022-09-13 13:32:13 +03:00
|
|
|
appTest('OATH: set oath password', (WidgetTester tester) async {
|
|
|
|
await tester.setOathPassword(testPassword);
|
|
|
|
});
|
2022-09-12 08:01:10 +03:00
|
|
|
|
2022-09-13 13:32:13 +03:00
|
|
|
appTest('OATH: remove oath password', (WidgetTester tester) async {
|
|
|
|
await tester.removeOathPassword(testPassword);
|
|
|
|
});
|
2022-09-12 07:34:49 +03:00
|
|
|
});
|
|
|
|
});
|
2022-05-11 22:42:14 +03:00
|
|
|
}
|