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.
|
|
|
|
*/
|
|
|
|
|
2022-05-11 22:42:14 +03:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
2023-11-14 18:44:14 +03:00
|
|
|
import 'package:yubico_authenticator/app/views/keys.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;
|
2023-11-14 18:44:14 +03:00
|
|
|
import 'package:yubico_authenticator/oath/models.dart';
|
|
|
|
import 'package:yubico_authenticator/oath/views/account_list.dart';
|
2022-05-11 22:42:14 +03:00
|
|
|
|
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
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
String randomPadded() {
|
|
|
|
return randomNum(999).toString().padLeft(3, '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
randomNum(int i) {}
|
|
|
|
|
|
|
|
String generateRandomIssuer() {
|
|
|
|
return 'i${randomPadded()}';
|
|
|
|
}
|
|
|
|
|
|
|
|
String generateRandomName() {
|
|
|
|
return 'n${randomPadded()}';
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2023-01-11 12:04:15 +03:00
|
|
|
group('OATH UI tests', () {
|
|
|
|
appTest('Menu items exist', (WidgetTester tester) async {
|
|
|
|
await tester.tapActionIconButton();
|
2023-11-14 18:44:14 +03:00
|
|
|
await tester.shortWait();
|
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-11-14 18:44:14 +03:00
|
|
|
await tester.longWait();
|
2022-07-21 16:42:47 +03:00
|
|
|
});
|
2022-09-11 12:05:00 +03:00
|
|
|
});
|
2022-07-21 16:42:47 +03:00
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
group('Account creation', () {
|
|
|
|
appTest('Initial reset OATH', (WidgetTester tester) async {
|
|
|
|
/// reset OATH application
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
await tester.resetOATH();
|
|
|
|
await tester.longWait();
|
|
|
|
});
|
|
|
|
appTest('Create 32 Accounts', (WidgetTester tester) async {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
2022-09-11 12:05:00 +03:00
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
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();
|
2022-09-11 12:05:00 +03:00
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
expect(
|
|
|
|
find.descendant(
|
|
|
|
of: find.byType(AccountList),
|
|
|
|
matching: find.textContaining(testAccount.name)),
|
|
|
|
findsOneWidget);
|
2022-09-11 12:05:00 +03:00
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
await tester.shortWait();
|
|
|
|
}
|
|
|
|
// TODO: verify one more addAccount() is not possible
|
|
|
|
await tester.resetOATH();
|
|
|
|
await tester.shortWait();
|
2022-07-21 16:42:47 +03:00
|
|
|
});
|
2023-11-14 18:44:14 +03:00
|
|
|
// appTest('Create weird character-accounts and check byte count',
|
|
|
|
// (WidgetTester tester) async {});
|
|
|
|
group('TOTP account tests', () {
|
|
|
|
appTest('TOTP: sha-1', (WidgetTester tester) async {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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);
|
2022-07-21 16:42:47 +03:00
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
await tester.shortWait();
|
|
|
|
});
|
|
|
|
appTest('TOTP: sha-256', (WidgetTester tester) async {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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);
|
2022-09-11 12:05:00 +03:00
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
await tester.shortWait();
|
|
|
|
});
|
|
|
|
appTest('TOTP: sha-512', (WidgetTester tester) async {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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);
|
2022-09-11 12:05:00 +03:00
|
|
|
|
2023-11-14 18:44:14 +03:00
|
|
|
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 {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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 {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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 {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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 {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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 {
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
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
|
|
|
|
var oathDrawerButton = find.byKey(oathAppDrawer).hitTestable();
|
|
|
|
await tester.tap(oathDrawerButton);
|
|
|
|
await tester.longWait();
|
|
|
|
await tester.resetOATH();
|
|
|
|
await tester.longWait();
|
2022-09-11 12:05:00 +03:00
|
|
|
});
|
|
|
|
|
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 {
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-01-02 20:02:32 +03:00
|
|
|
group('Password tests', () {
|
2023-11-14 18:44:14 +03:00
|
|
|
// 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, () {
|
2023-11-14 18:44:14 +03:00
|
|
|
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
|
|
|
});
|
2023-11-14 18:44:14 +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
|
|
|
|
2023-11-14 18:44:14 +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
|
|
|
|
2023-11-14 18:44:14 +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 {
|
2023-11-14 18:44:14 +03:00
|
|
|
// 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
|
|
|
});
|
|
|
|
});
|
2022-05-11 22:42:14 +03:00
|
|
|
}
|