yubioath-flutter/integration_test/oath_test.dart

126 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;
2023-01-11 12:04:15 +03:00
group('OATH UI tests', () {
appTest('Menu items exist', (WidgetTester tester) async {
await tester.tapActionIconButton();
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);
2023-01-11 12:04:15 +03:00
// close dialog
await tester.tapTopLeftCorner();
});
});
2023-01-02 20:02:32 +03:00
group('Account tests', () {
appTest('Create OATH account', (WidgetTester tester) async {
// account with issuer
var testAccount = const Account(
issuer: 'IssuerForTests',
name: 'NameForTests',
secret: 'aaaaaaaaaaaaaaaa',
);
await tester.deleteAccount(testAccount);
2023-01-02 20:02:32 +03:00
await tester.addAccount(testAccount);
// account without issuer
testAccount = const Account(
name: 'NoIssuerName',
secret: 'bbbbbbbbbbbbbbbb',
);
await tester.deleteAccount(testAccount);
2023-01-02 20:02:32 +03:00
await tester.addAccount(testAccount);
});
2022-09-12 08:01:10 +03:00
/// deletes accounts created in previous test
2023-01-02 20:02:32 +03:00
appTest('Delete OATH account', (WidgetTester tester) async {
var testAccount =
const Account(issuer: 'IssuerForTests', name: 'NameForTests');
2023-01-02 20:02:32 +03:00
await tester.deleteAccount(testAccount);
expect(await tester.findAccount(testAccount), isNull);
testAccount = const Account(issuer: null, name: 'NoIssuerName');
2023-01-02 20:02:32 +03:00
await tester.deleteAccount(testAccount);
expect(await tester.findAccount(testAccount), isNull);
});
2022-09-12 08:01:10 +03:00
/// adds an account, renames, verifies
2023-01-02 20:02:32 +03:00
appTest('Rename OATH 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');
});
});
2023-01-02 20:02:32 +03:00
group('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
2023-01-02 20:02:32 +03:00
group('Desktop password tests', skip: isAndroid, () {
2022-09-13 13:32:13 +03:00
var testPassword = 'testPassword';
2023-01-02 20:02:32 +03:00
appTest('Set OATH password', (WidgetTester tester) async {
2022-09-13 13:32:13 +03:00
await tester.setOathPassword(testPassword);
});
2023-01-02 20:02:32 +03:00
appTest('Remove OATH password', (WidgetTester tester) async {
2022-09-13 13:32:13 +03:00
await tester.unlockOathSession(testPassword);
await tester.removeOathPassword(testPassword);
});
2022-09-12 07:34:49 +03:00
});
2023-01-02 20:02:32 +03:00
group('All password tests', () {
2022-09-13 13:32:13 +03:00
var testPassword = 'testPasswordX';
2022-09-12 07:34:49 +03:00
2023-01-02 20:02:32 +03:00
appTest('Set OATH password', (WidgetTester tester) async {
2022-09-13 13:32:13 +03:00
await tester.setOathPassword(testPassword);
});
2022-09-12 08:01:10 +03:00
2023-01-02 20:02:32 +03:00
appTest('Remove OATH password', (WidgetTester tester) async {
2022-09-13 13:32:13 +03:00
await tester.removeOathPassword(testPassword);
});
2022-09-12 07:34:49 +03:00
});
});
}