From 40f806ed1782654372668f734302284a3cbceea2 Mon Sep 17 00:00:00 2001 From: Adam Velebil Date: Mon, 13 Nov 2023 16:50:20 +0100 Subject: [PATCH] Use env variable for test keys serial numbers --- integration_test/_approved_yubikeys.dart | 20 ------------- integration_test/utils/test_util.dart | 36 +++++++++++++----------- 2 files changed, 19 insertions(+), 37 deletions(-) delete mode 100644 integration_test/_approved_yubikeys.dart 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..449556b2 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,30 @@ 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 (!approvedSerialNumbers.contains(yubiKeySerialNumber)) { + if (yubiKeySerialNumber == null) { + expect( + approvedSerialNumbers.contains(yubiKeySerialNumber), equals(true), + reason: 'No YubiKey connected'); + } else { + expect( + approvedSerialNumbers.contains(yubiKeySerialNumber), equals(true), + reason: + 'YubiKey with S/N $yubiKeySerialNumber is not approved for integration tests.'); + } } return result; @@ -151,7 +164,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; @@ -176,17 +189,6 @@ extension AppWidgetTester on WidgetTester { 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.'); - } - } - collectedYubiKeyInformation = true; } }