mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 00:12:09 +03:00
use test resource for approved keys
This commit is contained in:
parent
40f806ed17
commit
34a9d403ac
3
integration_test/test_res/.gitignore
vendored
Normal file
3
integration_test/test_res/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/pubspec.lock
|
||||
/.dart_tool
|
||||
|
6
integration_test/test_res/pubspec.yaml
Normal file
6
integration_test/test_res/pubspec.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
name: test_res
|
||||
environment:
|
||||
sdk: '>=3.0.0 <4.0.0'
|
||||
flutter:
|
||||
assets:
|
||||
- resources/
|
1
integration_test/test_res/resources/.gitignore
vendored
Normal file
1
integration_test/test_res/resources/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
approved_serial_numbers.csv
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:yubico_authenticator/app/views/keys.dart' as app_keys;
|
||||
@ -113,28 +114,42 @@ extension AppWidgetTester on WidgetTester {
|
||||
expect(find.byKey(screenKey), findsOneWidget);
|
||||
}
|
||||
|
||||
Future<void> startUp([Map<dynamic, dynamic> startUpParams = const {}]) async {
|
||||
// YA_TEST_APPROVED_KEY_SN should contain comma separated list of
|
||||
// YubiKey serial numbers which are approved for tests
|
||||
// To pass the variable to the test use:
|
||||
// flutter --dart-define=YA_TEST_APPROVED_KEY_SN=SN1,SN2,...,SNn test t
|
||||
const envVar = String.fromEnvironment('YA_TEST_APPROVED_KEY_SN');
|
||||
final approvedSerialNumbers = envVar.split(',');
|
||||
/// Retrieve a list of test approved serial numbers.
|
||||
///
|
||||
/// To add testing keys add comma separated serial numbers to a file
|
||||
/// `approved_serial_numbers.csv` in `integration_test/test_res/resources/`.
|
||||
/// This file is bundled only during test runs and is explicitly ignored from
|
||||
/// version control.
|
||||
Future<List<String>> getApprovedSerialNumbers() async {
|
||||
const approvedKeysResource = 'approved_serial_numbers.csv';
|
||||
String approved = '';
|
||||
|
||||
try {
|
||||
approved = await rootBundle.loadString(
|
||||
'packages/test_res/resources/$approvedKeysResource',
|
||||
);
|
||||
} catch (_) {
|
||||
testLog(false, 'Failed to read $approvedKeysResource');
|
||||
}
|
||||
|
||||
return approved.split(',').map((e) => e.trim()).toList(growable: false);
|
||||
}
|
||||
|
||||
Future<void> startUp([Map<dynamic, dynamic> startUpParams = const {}]) async {
|
||||
var result = isAndroid == true
|
||||
? await android_test_util.startUp(this, startUpParams)
|
||||
: await desktop_test_util.startUp(this, startUpParams);
|
||||
|
||||
await collectYubiKeyInformation();
|
||||
|
||||
if (!approvedSerialNumbers.contains(yubiKeySerialNumber)) {
|
||||
final approved = await getApprovedSerialNumbers();
|
||||
|
||||
if (!approved.contains(yubiKeySerialNumber)) {
|
||||
if (yubiKeySerialNumber == null) {
|
||||
expect(
|
||||
approvedSerialNumbers.contains(yubiKeySerialNumber), equals(true),
|
||||
expect(approved.contains(yubiKeySerialNumber), equals(true),
|
||||
reason: 'No YubiKey connected');
|
||||
} else {
|
||||
expect(
|
||||
approvedSerialNumbers.contains(yubiKeySerialNumber), equals(true),
|
||||
expect(approved.contains(yubiKeySerialNumber), equals(true),
|
||||
reason:
|
||||
'YubiKey with S/N $yubiKeySerialNumber is not approved for integration tests.');
|
||||
}
|
||||
|
@ -792,6 +792,13 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.0"
|
||||
test_res:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
path: "integration_test/test_res"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.0"
|
||||
timing:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -73,6 +73,8 @@ dev_dependencies:
|
||||
sdk: flutter
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
test_res:
|
||||
path: integration_test/test_res
|
||||
|
||||
# The "flutter_lints" package below contains a set of recommended lints to
|
||||
# encourage good coding practices. The lint set provided by the package is
|
||||
|
Loading…
Reference in New Issue
Block a user