yubioath-flutter/integration_test/oath_test.dart

123 lines
4.2 KiB
Dart
Raw Normal View History

2022-10-04 13:12:54 +03:00
/*
* Copyright (C) 2022 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
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-09-12 07:34:49 +03:00
import 'oath_test_util.dart';
2022-05-12 16:35:14 +03:00
import 'test_util.dart';
void main() {
2022-09-12 07:34:49 +03:00
var binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
2022-09-13 13:32:13 +03:00
group('OATH UI tests', () {
appTest('Menu items exist', (WidgetTester tester) async {
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);
});
});
group('OATH Account tests', () {
2022-09-13 13:32:13 +03:00
appTest('Create account', (WidgetTester tester) async {
// 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-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 {
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 {
var testAccount =
const Account(issuer: 'IssuerToRename', name: 'NameToRename');
2022-09-12 08:01:10 +03:00
/// delete account if it exists
await tester.deleteAccount(testAccount);
await tester.deleteAccount(
const Account(issuer: 'RenamedIssuer', name: 'RenamedName'));
await tester.addAccount(testAccount);
await tester.renameAccount(testAccount, 'RenamedIssuer', 'RenamedName');
});
});
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
});
});
}