Use env variable for test keys serial numbers

This commit is contained in:
Adam Velebil 2023-11-13 16:50:20 +01:00
parent a8349e4484
commit 40f806ed17
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
2 changed files with 19 additions and 37 deletions

View File

@ -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 = <String>[
'',
];

View File

@ -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<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(',');
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;
}
}