diff --git a/integration_test/_approved_yubikeys.dart b/integration_test/_approved_yubikeys.dart deleted file mode 100644 index fdc17899..00000000 --- a/integration_test/_approved_yubikeys.dart +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -/// list of YubiKey serial numbers which are approved to be used with integration tests -var approvedYubiKeys = [ - '', -]; diff --git a/integration_test/utils/test_util.dart b/integration_test/utils/test_util.dart index 275475c7..ebd87e06 100644 --- a/integration_test/utils/test_util.dart +++ b/integration_test/utils/test_util.dart @@ -23,7 +23,6 @@ import 'package:yubico_authenticator/core/state.dart'; import 'package:yubico_authenticator/management/views/keys.dart'; import 'android/util.dart' as android_test_util; -import '../_approved_yubikeys.dart'; import 'desktop/util.dart' as desktop_test_util; const shortWaitMs = 500; @@ -115,16 +114,28 @@ extension AppWidgetTester on WidgetTester { } Future startUp([Map 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(','); + var result = isAndroid == true ? await android_test_util.startUp(this, startUpParams) : await desktop_test_util.startUp(this, startUpParams); await collectYubiKeyInformation(); - if (!approvedYubiKeys.contains(yubiKeySerialNumber)) { - testLog(false, - 'The connected key is refused by the tests: $yubiKeySerialNumber'); - expect(approvedYubiKeys.contains(yubiKeySerialNumber), equals(true)); + if (yubiKeySerialNumber == null) { + fail('No YubiKey connected'); + } + + if (!approvedSerialNumbers.contains(yubiKeySerialNumber)) { + fail('YubiKey with S/N $yubiKeySerialNumber is not approved for ' + 'integration tests.\nUse --dart-define=' + 'YA_TEST_APPROVED_KEY_SN=$yubiKeySerialNumber test ' + 'parameter to approve it.'); } return result; @@ -151,7 +162,7 @@ extension AppWidgetTester on WidgetTester { .evaluate() .single .widget as ListTile; - //ListTile lt = deviceInfo.evaluate().single.widget as ListTile; + yubiKeyName = (lt.title as Text).data; var subtitle = (lt.subtitle as Text?)?.data; @@ -173,20 +184,10 @@ extension AppWidgetTester on WidgetTester { // close the opened menu await closeDrawer(); - testLog(false, - 'Connected YubiKey: $yubiKeySerialNumber/$yubiKeyFirmware - $yubiKeyName'); - - if (!approvedYubiKeys.contains(yubiKeySerialNumber)) { - if (yubiKeySerialNumber == null) { - expect(approvedYubiKeys.contains(yubiKeySerialNumber), equals(true), - reason: 'No YubiKey connected'); - } else { - expect(approvedYubiKeys.contains(yubiKeySerialNumber), equals(true), - reason: - 'YubiKey with S/N $yubiKeySerialNumber is not approved for integration tests.'); - } + if (yubiKeySerialNumber != null) { + testLog(false, + 'Connected YubiKey: $yubiKeySerialNumber/$yubiKeyFirmware - $yubiKeyName'); } - collectedYubiKeyInformation = true; } }