Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing piv settings tests #1400

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 112 additions & 65 deletions integration_test/piv_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,87 +32,111 @@ void main() {
group('PIV Settings', skip: isAndroid, () {
const factoryPin = '123456';
const factoryPuk = '12345678';
const uno = 'abcdabcd';
const due = 'bcdabcda';
const tre = 'cdabcdab';

appTest('Reset PIV (settings-init)', (WidgetTester tester) async {
await tester.resetPiv();
await tester.shortWait();
});
appTest('Lock PIN, unlock with PUK', (WidgetTester tester) async {
await tester.configurePiv();
await tester.shortWait();
await tester.tap(find.byKey(managePinAction).hitTestable());
await tester.shortWait();
await tester.lockPinPuk();
appTest('test pin lock-unlock', (WidgetTester tester) async {
// open pin dialog
await tester.pinView();

// first new pin
await tester.pivFirst();

// open pin dialog
await tester.pinView();

// three lock pins
await tester.pivLock();

// press 'escape', verify blockedness
await tester.shortWait();
await tester.tap(find.byKey(actionsIconButtonKey).hitTestable());

/// TODO: This expect needs to verify that Pin subtitle is 'Blocked'
/// expect(find.byKey(managePinAction), find.byTooltip('Blocked'));
await tester.shortWait();

expect(find.text('Blocked, use PUK to reset'), findsOne);

await tester.tap(find.byKey(managePinAction).hitTestable());
await tester.shortWait();
await tester.enterText(find.byKey(pinPukField).hitTestable(), factoryPuk);
await tester.shortWait();
await tester.enterText(
find.byKey(newPinPukField).hitTestable(), factoryPin);
await tester.shortWait();
await tester.enterText(
find.byKey(confirmPinPukField).hitTestable(), factoryPin);
await tester.shortWait();
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.shortWait();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.longWait();

// PUK field is pre-filled
await tester.pivFirst();

// reset
await tester.resetPiv();
await tester.shortWait();
});

appTest('Lock PUK, lock PIN, factory reset', (WidgetTester tester) async {
await tester.configurePiv();
await tester.shortWait();
await tester.tap(find.byKey(managePukAction).hitTestable());
// lock pin and puk
await tester.pinView();
await tester.pivFirst();
await tester.pinView();
await tester.pivLock();

await tester.pukView();
await tester.pivFirst();
await tester.pukView();
await tester.pivLock();
await tester.ultraLongWait();

// verify blockedness

await tester.tap(find.byKey(actionsIconButtonKey).hitTestable());
await tester.shortWait();
await tester.lockPinPuk();

expect(find.text('Blocked, factory reset needed'), findsAny);

await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.shortWait();
await tester.tap(find.byKey(actionsIconButtonKey).hitTestable());

/// TODO: This expect needs to verify that PUK underline is 'Blocked'
/// expect(find.byKey(managePukAction), find.byTooltip('Blocked'));
await tester.resetPiv();
});
appTest('Change PIN', (WidgetTester tester) async {
//reset factorypin
await tester.pinView();
await tester.pivFirst();

// onepin
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), 'firstpin');
await tester.shortWait();
await tester.tap(find.byKey(managePinAction).hitTestable());
await tester.enterText(find.byKey(newPinPukField).hitTestable(), uno);
await tester.shortWait();
await tester.lockPinPuk();
await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), uno);
await tester.shortWait();
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.shortWait();
await tester.tap(find.byKey(actionsIconButtonKey).hitTestable());

/// TODO: This expect needs to verify that Pin underline is 'Blocked'
/// expect(find.byKey(managePinAction), find.byTooltip('Blocked'));

// onepin
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), uno);
await tester.shortWait();
await tester.tap(find.byKey(managePinAction).hitTestable());
await tester.enterText(find.byKey(newPinPukField).hitTestable(), due);
await tester.shortWait();
await tester.tap(find.byKey(managePukAction).hitTestable());
await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), due);
await tester.shortWait();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.longWait();
await tester.resetPiv();
});
appTest('Change PIN', (WidgetTester tester) async {
const newpin = '123123';
await tester.configurePiv();
await tester.tap(find.byKey(managePinAction).hitTestable());
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.shortWait();
await tester.enterText(find.byKey(pinPukField).hitTestable(), factoryPin);

// onepin
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), due);
await tester.shortWait();
await tester.enterText(find.byKey(newPinPukField).hitTestable(), newpin);
await tester.enterText(find.byKey(newPinPukField).hitTestable(), tre);
await tester.shortWait();
await tester.enterText(
find.byKey(confirmPinPukField).hitTestable(), newpin);
await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), tre);
await tester.shortWait();
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.longWait();
await tester.configurePiv();
await tester.tap(find.byKey(managePinAction).hitTestable());
await tester.shortWait();
await tester.enterText(find.byKey(pinPukField).hitTestable(), newpin);

// factorpin
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), tre);
await tester.shortWait();
await tester.enterText(
find.byKey(newPinPukField).hitTestable(), factoryPin);
Expand All @@ -121,26 +145,49 @@ void main() {
find.byKey(confirmPinPukField).hitTestable(), factoryPin);
await tester.shortWait();
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.longWait();
await tester.shortWait();
});
appTest('Change PUK', (WidgetTester tester) async {
const newpuk = '12341234';
await tester.configurePiv();
await tester.tap(find.byKey(managePukAction).hitTestable());
//reset factorypuk
await tester.pinView();
await tester.pivFirst();

// onepin
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), 'firstpin');
await tester.shortWait();
await tester.enterText(find.byKey(pinPukField).hitTestable(), factoryPuk);
await tester.enterText(find.byKey(newPinPukField).hitTestable(), uno);
await tester.shortWait();
await tester.enterText(find.byKey(newPinPukField).hitTestable(), newpuk);
await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), uno);
await tester.shortWait();
await tester.enterText(
find.byKey(confirmPinPukField).hitTestable(), newpuk);
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.shortWait();

// onepin
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), uno);
await tester.shortWait();
await tester.enterText(find.byKey(newPinPukField).hitTestable(), due);
await tester.shortWait();
await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), due);
await tester.shortWait();
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.longWait();
await tester.configurePiv();
await tester.tap(find.byKey(managePukAction).hitTestable());
await tester.shortWait();
await tester.enterText(find.byKey(pinPukField).hitTestable(), newpuk);

// onepin
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), due);
await tester.shortWait();
await tester.enterText(find.byKey(newPinPukField).hitTestable(), tre);
await tester.shortWait();
await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), tre);
await tester.shortWait();
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.shortWait();

// factorpuk
await tester.pinView();
await tester.enterText(find.byKey(pinPukField).hitTestable(), tre);
await tester.shortWait();
await tester.enterText(
find.byKey(newPinPukField).hitTestable(), factoryPuk);
Expand All @@ -149,7 +196,7 @@ void main() {
find.byKey(confirmPinPukField).hitTestable(), factoryPuk);
await tester.shortWait();
await tester.tap(find.byKey(saveButton).hitTestable());
await tester.longWait();
await tester.shortWait();
});
group('PIV Management Key', () {
const newmanagementkey =
Expand Down
62 changes: 50 additions & 12 deletions integration_test/utils/piv_test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,68 @@ import 'package:yubico_authenticator/piv/keys.dart';
import 'test_util.dart';

extension PIVFunctions on WidgetTester {
static const ett = 'firstpin';
static const tva = 'lockpinn';

/// Open the PIV Configuration
Future<void> configurePiv() async {
// 1. open PIV view
var pivDrawerButton = find.byKey(pivAppDrawer).hitTestable();
await tap(pivDrawerButton);
await longWait();
await tap(find.byKey(pivAppDrawer).hitTestable());
await shortWait();
await tap(find.byKey(actionsIconButtonKey).hitTestable());
await longWait();
await shortWait();
}

Future<void> pinView() async {
await tap(find.byKey(pivAppDrawer).hitTestable());
await shortWait();
await tap(find.byKey(actionsIconButtonKey).hitTestable());
await shortWait();
await tap(find.byKey(managePinAction));
await shortWait();
}

Future<void> pukView() async {
await tap(find.byKey(pivAppDrawer).hitTestable());
await shortWait();
await tap(find.byKey(actionsIconButtonKey).hitTestable());
await shortWait();
await tap(find.byKey(managePukAction));
await shortWait();
}

Future<void> managementKeyView() async {
await tap(find.byKey(pivAppDrawer).hitTestable());
await shortWait();
await tap(find.byKey(actionsIconButtonKey).hitTestable());
await shortWait();
await tap(find.byKey(manageManagementKeyAction));
await shortWait();
}

/// Locks PIN or PUK
Future<void> lockPinPuk() async {
Future<void> pivFirst() async {
// when in pin or puk view, remove factorypin/puk
await enterText(find.byKey(newPinPukField), ett);
await shortWait();
await enterText(find.byKey(confirmPinPukField), ett);
await shortWait();
await tap(find.byKey(saveButton).hitTestable());
await shortWait();
}

Future<void> pivLock() async {
// when in pin or puk view this will lock it
for (var i = 0; i < 3; i += 1) {
var wrongpin = '123456$i';
await enterText(find.byKey(pinPukField).hitTestable(), wrongpin);
await enterText(find.byKey(pinPukField), tva);
await shortWait();
await enterText(find.byKey(newPinPukField).hitTestable(), wrongpin);
await enterText(find.byKey(newPinPukField), tva);
await shortWait();
await enterText(find.byKey(confirmPinPukField).hitTestable(), wrongpin);
await enterText(find.byKey(confirmPinPukField), tva);
await shortWait();
await tap(find.byKey(saveButton).hitTestable());
await longWait();
await shortWait();
}
await sendKeyEvent(LogicalKeyboardKey.escape);
await shortWait();
}

/// Factory reset Piv application
Expand Down
Loading