Convert some code_signing_tests to testWithoutContext (#53142)
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:flutter_tools/src/application_package.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/config.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
@@ -27,8 +27,10 @@ void main() {
|
||||
IosProject mockIosProject;
|
||||
BuildableIOSApp app;
|
||||
AnsiTerminal testTerminal;
|
||||
BufferLogger logger;
|
||||
|
||||
setUp(() async {
|
||||
logger = BufferLogger.test();
|
||||
mockProcessManager = MockProcessManager();
|
||||
// Assume all binaries exist and are executable
|
||||
when(mockProcessManager.canRun(any)).thenReturn(true);
|
||||
@@ -44,38 +46,48 @@ void main() {
|
||||
app = await BuildableIOSApp.fromProject(mockIosProject);
|
||||
});
|
||||
|
||||
testUsingContext('No auto-sign if Xcode project settings are not available', () async {
|
||||
testWithoutContext('No auto-sign if Xcode project settings are not available', () async {
|
||||
when(mockIosProject.buildSettings).thenReturn(null);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
expect(signingConfigs, isNull);
|
||||
});
|
||||
|
||||
testUsingContext('No discovery if development team specified in Xcode project', () async {
|
||||
testWithoutContext('No discovery if development team specified in Xcode project', () async {
|
||||
when(mockIosProject.buildSettings).thenAnswer((_) {
|
||||
return Future<Map<String, String>>.value(<String, String>{
|
||||
'DEVELOPMENT_TEAM': 'abc',
|
||||
});
|
||||
});
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
expect(signingConfigs, isNull);
|
||||
expect(testLogger.statusText, equals(
|
||||
expect(logger.statusText, equals(
|
||||
'Automatically signing iOS for device deployment using specified development team in Xcode project: abc\n'
|
||||
));
|
||||
}, overrides: <Type, Generator>{
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
|
||||
testUsingContext('No auto-sign if security or openssl not available', () async {
|
||||
testWithoutContext('No auto-sign if security or openssl not available', () async {
|
||||
when(mockProcessManager.run(<String>['which', 'security']))
|
||||
.thenAnswer((_) => Future<ProcessResult>.value(exitsFail));
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
expect(signingConfigs, isNull);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
|
||||
testUsingContext('No valid code signing certificates shows instructions', () async {
|
||||
when(mockIosProject.buildSettings).thenAnswer((_) {
|
||||
return Future<Map<String, String>>.value(<String, String>{});
|
||||
});
|
||||
when(mockProcessManager.run(
|
||||
<String>['which', 'security'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
@@ -92,22 +104,17 @@ void main() {
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
)).thenAnswer((_) => Future<ProcessResult>.value(exitsHappy));
|
||||
|
||||
|
||||
Map<String, String> signingConfigs;
|
||||
try {
|
||||
signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
fail('No identity should throw tool error');
|
||||
} on ToolExit {
|
||||
expect(signingConfigs, isNull);
|
||||
expect(testLogger.errorText, contains('No valid code signing certificates were found'));
|
||||
}
|
||||
expect(() async => await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
), throwsToolExit(message: 'No development certificates available to code sign app for device deployment'));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
|
||||
testUsingContext('Test single identity and certificate organization works', () async {
|
||||
testWithoutContext('Test single identity and certificate organization works', () async {
|
||||
when(mockProcessManager.run(
|
||||
<String>['which', 'security'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
@@ -161,20 +168,19 @@ void main() {
|
||||
when(mockProcess.stderr).thenAnswer((Invocation invocation) => mockStdErr);
|
||||
when(mockProcess.exitCode).thenAnswer((_) async => 0);
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(testLogger.statusText, contains('iPhone Developer: Profile 1 (1111AAAA11)'));
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
expect(logger.statusText, contains('iPhone Developer: Profile 1 (1111AAAA11)'));
|
||||
expect(logger.errorText, isEmpty);
|
||||
verify(mockStdIn.write('This is a mock certificate'));
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '3333CCCC33'});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
|
||||
|
||||
testUsingContext('Test single identity (Catalina format) and certificate organization works', () async {
|
||||
testWithoutContext('Test single identity (Catalina format) and certificate organization works', () async {
|
||||
when(mockProcessManager.run(
|
||||
<String>['which', 'security'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
@@ -230,20 +236,20 @@ void main() {
|
||||
|
||||
Map<String, String> signingConfigs;
|
||||
try {
|
||||
signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
// This should not throw
|
||||
fail('Code signing threw: $e');
|
||||
}
|
||||
|
||||
expect(testLogger.statusText, contains('Apple Development: Profile 1 (1111AAAA11)'));
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
expect(logger.statusText, contains('Apple Development: Profile 1 (1111AAAA11)'));
|
||||
expect(logger.errorText, isEmpty);
|
||||
verify(mockStdIn.write('This is a mock certificate'));
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '3333CCCC33'});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
|
||||
testUsingContext('Test multiple identity and certificate organization works', () async {
|
||||
@@ -304,24 +310,27 @@ void main() {
|
||||
when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
|
||||
when(mockOpenSslProcess.exitCode).thenAnswer((_) => Future<int>.value(0));
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
logger.statusText,
|
||||
contains('Please select a certificate for code signing [<bold>1</bold>|2|3|a]: 3'),
|
||||
);
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
logger.statusText,
|
||||
contains('Signing iOS app for device deployment using developer identity: "iPhone Developer: Profile 3 (3333CCCC33)"'),
|
||||
);
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
expect(logger.errorText, isEmpty);
|
||||
verify(mockOpenSslStdIn.write('This is a mock certificate'));
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '4444DDDD44'});
|
||||
|
||||
verify(globals.config.setValue('ios-signing-cert', 'iPhone Developer: Profile 3 (3333CCCC33)'));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Config: () => mockConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
@@ -386,18 +395,21 @@ void main() {
|
||||
when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
|
||||
when(mockOpenSslProcess.exitCode).thenAnswer((_) => Future<int>.value(0));
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
logger.statusText,
|
||||
contains('Signing iOS app for device deployment using developer identity: "iPhone Developer: Profile 1 (1111AAAA11)"'),
|
||||
);
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
expect(logger.errorText, isEmpty);
|
||||
verify(mockOpenSslStdIn.write('This is a mock certificate'));
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '5555EEEE55'});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Config: () => mockConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
@@ -460,22 +472,25 @@ void main() {
|
||||
when(mockOpenSslProcess.exitCode).thenAnswer((_) => Future<int>.value(0));
|
||||
when<String>(mockConfig.getValue('ios-signing-cert') as String).thenReturn('iPhone Developer: Profile 3 (3333CCCC33)');
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
logger.statusText,
|
||||
contains('Found saved certificate choice "iPhone Developer: Profile 3 (3333CCCC33)". To clear, use "flutter config"'),
|
||||
);
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
logger.statusText,
|
||||
contains('Signing iOS app for device deployment using developer identity: "iPhone Developer: Profile 3 (3333CCCC33)"'),
|
||||
);
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
expect(logger.errorText, isEmpty);
|
||||
verify(mockOpenSslStdIn.write('This is a mock certificate'));
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '4444DDDD44'});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Config: () => mockConfig,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
@@ -540,26 +555,29 @@ void main() {
|
||||
when(mockOpenSslProcess.exitCode).thenAnswer((_) => Future<int>.value(0));
|
||||
when<String>(mockConfig.getValue('ios-signing-cert') as String).thenReturn('iPhone Developer: Invalid Profile');
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
expect(
|
||||
testLogger.errorText.replaceAll('\n', ' '),
|
||||
logger.errorText.replaceAll('\n', ' '),
|
||||
contains('Saved signing certificate "iPhone Developer: Invalid Profile" is not a valid development certificate'),
|
||||
);
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
logger.statusText,
|
||||
contains('Certificate choice "iPhone Developer: Profile 3 (3333CCCC33)"'),
|
||||
);
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '4444DDDD44'});
|
||||
verify(globals.config.setValue('ios-signing-cert', 'iPhone Developer: Profile 3 (3333CCCC33)'));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Config: () => mockConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
});
|
||||
|
||||
testUsingContext('find-identity failure', () async {
|
||||
testWithoutContext('find-identity failure', () async {
|
||||
when(mockProcessManager.run(
|
||||
<String>['which', 'security'],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
@@ -578,13 +596,12 @@ void main() {
|
||||
ProcessResult(0, 1, '', '')
|
||||
));
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
expect(signingConfigs, isNull);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Config: () => mockConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
});
|
||||
|
||||
testUsingContext('find-certificate failure', () async {
|
||||
@@ -622,11 +639,14 @@ void main() {
|
||||
ProcessResult(1, 1, '', '' ))
|
||||
);
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
processManager: mockProcessManager,
|
||||
logger: logger,
|
||||
);
|
||||
expect(signingConfigs, isNull);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Config: () => mockConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user