yubioath-flutter/integration_test/oath_test.dart

295 lines
10 KiB
Dart
Raw Normal View History

2022-10-04 13:12:54 +03:00
/*
2023-12-04 17:28:07 +03:00
* Copyright (C) 2023 Yubico.
2022-10-04 13:12:54 +03:00
*
* 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.
*/
2023-11-28 18:51:44 +03:00
@Tags(['android', 'desktop', 'oath'])
2024-07-03 13:44:20 +03:00
library;
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:yubico_authenticator/app/views/keys.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;
import 'package:yubico_authenticator/oath/models.dart';
import 'package:yubico_authenticator/oath/views/account_list.dart';
2023-06-30 16:32:10 +03:00
import 'utils/oath_test_util.dart';
import 'utils/test_util.dart';
2022-05-12 16:35:14 +03:00
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();
await tester.shortWait();
2022-09-12 13:58:17 +03:00
expect(find.byKey(keys.addAccountAction), findsOneWidget);
expect(find.byKey(keys.setOrManagePasswordAction), findsOneWidget);
2023-01-11 12:04:15 +03:00
// close dialog
await tester.tapTopLeftCorner();
await tester.longWait();
});
});
group('Account creation', () {
appTest('Initial reset OATH', (WidgetTester tester) async {
/// reset OATH application
//await tester.tapAppDrawerButton(oathAppDrawer);
await tester.resetOATH();
await tester.shortWait();
});
appTest('Create 32 Accounts', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
for (var i = 0; i < 32; i += 1) {
// just now merely 32 accounts
var testAccount = Account(
issuer: 'MaxAccount_issuer_$i',
name: 'MaxAccount_name_$i',
secret: 'abbaabba',
);
await tester.addAccount(testAccount);
await tester.shortWait();
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
}
// TODO: verify one more addAccount() is not possible
await tester.resetOATH();
await tester.shortWait();
2023-11-28 18:51:44 +03:00
}, tags: ['slow']);
// appTest('Create weird character-accounts and check byte count',
// (WidgetTester tester) async {});
group('TOTP account tests', () {
appTest('TOTP: sha-1', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_totp_sha1',
name: 'n__totp_sha1',
secret: 'abbaabba',
touch: false,
oathType: OathType.totp,
hashAlgorithm: HashAlgorithm.sha1);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
appTest('TOTP: sha-256', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_totp_sha256',
name: 'n__totp_sha256',
secret: 'abbaabba',
touch: false,
oathType: OathType.totp,
hashAlgorithm: HashAlgorithm.sha256);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
appTest('TOTP: sha-512', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_totp_sha512',
name: 'n__totp_sha512',
secret: 'abbaabba',
touch: false,
oathType: OathType.totp,
hashAlgorithm: HashAlgorithm.sha512);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
// appTest('TOTP: period-20',
// (WidgetTester tester) async {});
// appTest('TOTP: period-45',
// (WidgetTester tester) async {});
// appTest('TOTP: period-60',
// (WidgetTester tester) async {});
// appTest('TOTP: digits-8',
// (WidgetTester tester) async {});
appTest('TOTP: touch', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_totp_touch',
name: 'n_totp_touch',
secret: 'abbaabba',
touch: true,
oathType: OathType.totp,
hashAlgorithm: HashAlgorithm.sha1);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
});
// group('HOTP account tests', () {
appTest('HOTP: sha-1', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_hotp_sha1',
name: 'n__hotp_sha1',
secret: 'abbaabba',
touch: false,
oathType: OathType.hotp,
hashAlgorithm: HashAlgorithm.sha1);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
appTest('HOTP: sha-256', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_hotp_sha256',
name: 'n__hotp_sha256',
secret: 'abbaabba',
touch: false,
oathType: OathType.hotp,
hashAlgorithm: HashAlgorithm.sha256);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
appTest('HOTP: sha-512', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_hotp_sha512',
name: 'n__hotp_sha512',
secret: 'abbaabba',
touch: false,
oathType: OathType.hotp,
hashAlgorithm: HashAlgorithm.sha512);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
// appTest('TOTP: digits-8',
// (WidgetTester tester) async {});
appTest('HOTP: touch', (WidgetTester tester) async {
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
const testAccount = Account(
issuer: 'i_hotp_touch',
name: 'n_hotp_touch',
secret: 'abbaabba',
touch: true,
oathType: OathType.hotp,
hashAlgorithm: HashAlgorithm.sha1);
await tester.addAccount(testAccount);
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(testAccount.name)),
findsOneWidget);
await tester.shortWait();
});
// group('QR Code scanning', () {});
appTest('Final reset OATH', (WidgetTester tester) async {
/// reset OATH application
2023-11-24 14:18:30 +03:00
await tester.tapAppDrawerButton(oathAppDrawer);
await tester.resetOATH();
await tester.longWait();
});
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'));
2023-11-24 14:18:30 +03:00
await tester.longWait();
await tester.addAccount(testAccount);
2023-11-24 14:18:30 +03:00
await tester.longWait();
await tester.renameAccount(testAccount, 'RenamedIssuer', 'RenamedName');
});
});
2023-01-02 20:02:32 +03:00
group('Password tests', () {
// NOTE: that the password groups should be run as whole
// NOTE: cannot restart the app on Android to be able to unlock: skip
2023-01-02 20:02:32 +03:00
group('Desktop password tests', skip: isAndroid, () {
var firstPassword = 'firstPassword';
var secondPassword = 'secondPassword';
var thirdPassword = 'thirdPassword';
2023-12-04 17:28:07 +03:00
appTest('Reset OATH', (WidgetTester tester) async {
await tester.resetOATH();
2022-09-13 13:32:13 +03:00
});
appTest('Set first OATH password', (WidgetTester tester) async {
// Sets a password for OATH
await tester.setOathPassword(firstPassword);
2022-09-13 13:32:13 +03:00
});
2022-09-12 07:34:49 +03:00
appTest('Set second OATH password', (WidgetTester tester) async {
// Without removing the first, change to a second password
await tester.unlockOathSession(firstPassword);
await tester.replaceOathPassword(firstPassword, secondPassword);
});
2022-09-12 07:34:49 +03:00
appTest('Set third OATH password', (WidgetTester tester) async {
// Without removing the second, set a third password
await tester.unlockOathSession(secondPassword);
await tester.replaceOathPassword(secondPassword, thirdPassword);
2022-09-13 13:32:13 +03:00
});
2022-09-12 08:01:10 +03:00
2023-01-02 20:02:32 +03:00
appTest('Remove OATH password', (WidgetTester tester) async {
// restarts the app, unlocks with password, removes password req.
await tester.unlockOathSession(thirdPassword);
await tester.removeOathPassword(thirdPassword);
2022-09-13 13:32:13 +03:00
});
2022-09-12 07:34:49 +03:00
});
});
}