Auto provision iOS deploy 2/3 - prompt user to choose a certificate (#10025)
* first pass * improvements * extract terminal.dart * rebase * add default terminal to context * The analyzer wants the ../ imports in front of the ./ imports * review notes
This commit is contained in:
47
packages/flutter_tools/test/src/base/terminal_test.dart
Normal file
47
packages/flutter_tools/test/src/base/terminal_test.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../context.dart';
|
||||
|
||||
|
||||
void main() {
|
||||
group('character input prompt', () {
|
||||
AnsiTerminal terminalUnderTest;
|
||||
|
||||
setUp(() {
|
||||
terminalUnderTest = new TestTerminal();
|
||||
});
|
||||
|
||||
testUsingContext('character prompt', () async {
|
||||
mockStdInStream = new Stream<String>.fromFutures(<Future<String>>[
|
||||
new Future<String>.value('d'), // Not in accepted list.
|
||||
new Future<String>.value('b'),
|
||||
]).asBroadcastStream();
|
||||
final String choice =
|
||||
await terminalUnderTest.promptForCharInput(
|
||||
<String>['a', 'b', 'c'],
|
||||
prompt: 'Please choose something',
|
||||
);
|
||||
expect(choice, 'b');
|
||||
expect(testLogger.statusText, '''
|
||||
Please choose something [a|b|c]: d
|
||||
Please choose something [a|b|c]: b
|
||||
''');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Stream<String> mockStdInStream;
|
||||
|
||||
class TestTerminal extends AnsiTerminal {
|
||||
@override
|
||||
Stream<String> get onCharInput {
|
||||
return mockStdInStream;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ 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/io.dart';
|
||||
import 'package:flutter_tools/src/ios/mac.dart';
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:flutter_tools/src/ios/code_signing.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@@ -18,9 +19,11 @@ void main() {
|
||||
group('Auto signing', () {
|
||||
ProcessManager mockProcessManager;
|
||||
BuildableIOSApp app;
|
||||
AnsiTerminal testTerminal;
|
||||
|
||||
setUp(() {
|
||||
mockProcessManager = new MockProcessManager();
|
||||
testTerminal = new TestTerminal();
|
||||
app = new BuildableIOSApp(
|
||||
projectBundleId: 'test.app',
|
||||
buildSettings: <String, String>{
|
||||
@@ -81,7 +84,7 @@ void main() {
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
|
||||
testUsingContext('Test extract identity and certificate organization works', () async {
|
||||
testUsingContext('Test single identity and certificate organization works', () async {
|
||||
when(mockProcessManager.runSync(<String>['which', 'security']))
|
||||
.thenReturn(exitsHappy);
|
||||
when(mockProcessManager.runSync(<String>['which', 'openssl']))
|
||||
@@ -93,8 +96,7 @@ void main() {
|
||||
0, // exitCode
|
||||
'''
|
||||
1) 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 "iPhone Developer: Profile 1 (1111AAAA11)"
|
||||
2) da4b9237bacccdf19c0760cab7aec4a8359010b0 "iPhone Developer: Profile 2 (2222BBBB22)"
|
||||
2 valid identities found''',
|
||||
1 valid identities found''',
|
||||
''
|
||||
));
|
||||
when(mockProcessManager.runSync(
|
||||
@@ -135,6 +137,72 @@ void main() {
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
|
||||
testUsingContext('Test multiple identity and certificate organization works', () async {
|
||||
when(mockProcessManager.runSync(<String>['which', 'security']))
|
||||
.thenReturn(exitsHappy);
|
||||
when(mockProcessManager.runSync(<String>['which', 'openssl']))
|
||||
.thenReturn(exitsHappy);
|
||||
when(mockProcessManager.runSync(
|
||||
argThat(contains('find-identity')), environment: any, workingDirectory: any,
|
||||
)).thenReturn(new ProcessResult(
|
||||
1, // pid
|
||||
0, // exitCode
|
||||
'''
|
||||
1) 86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 "iPhone Developer: Profile 1 (1111AAAA11)"
|
||||
2) da4b9237bacccdf19c0760cab7aec4a8359010b0 "iPhone Developer: Profile 2 (2222BBBB22)"
|
||||
3) 5bf1fd927dfb8679496a2e6cf00cbe50c1c87145 "iPhone Developer: Profile 3 (3333CCCC33)"
|
||||
3 valid identities found''',
|
||||
''
|
||||
));
|
||||
mockTerminalStdInStream =
|
||||
new Stream<String>.fromFuture(new Future<String>.value('3'));
|
||||
when(mockProcessManager.runSync(
|
||||
<String>['security', 'find-certificate', '-c', '3333CCCC33', '-p'],
|
||||
environment: any,
|
||||
workingDirectory: any,
|
||||
)).thenReturn(new ProcessResult(
|
||||
1, // pid
|
||||
0, // exitCode
|
||||
'This is a mock certificate',
|
||||
'',
|
||||
));
|
||||
|
||||
final MockProcess mockOpenSslProcess = new MockProcess();
|
||||
final MockStdIn mockOpenSslStdIn = new MockStdIn();
|
||||
final MockStream mockOpenSslStdErr = new MockStream();
|
||||
|
||||
when(mockProcessManager.start(
|
||||
argThat(contains('openssl')), environment: any, workingDirectory: any,
|
||||
)).thenReturn(new Future<Process>.value(mockOpenSslProcess));
|
||||
|
||||
when(mockOpenSslProcess.stdin).thenReturn(mockOpenSslStdIn);
|
||||
when(mockOpenSslProcess.stdout).thenReturn(new Stream<List<int>>.fromFuture(
|
||||
new Future<List<int>>.value(UTF8.encode(
|
||||
'subject= /CN=iPhone Developer: Profile 3 (3333CCCC33)/OU=4444DDDD44/O=My Team/C=US'
|
||||
))
|
||||
));
|
||||
when(mockOpenSslProcess.stderr).thenReturn(mockOpenSslStdErr);
|
||||
when(mockOpenSslProcess.exitCode).thenReturn(0);
|
||||
|
||||
final String developmentTeam = await getCodeSigningIdentityDevelopmentTeam(app);
|
||||
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
contains('Please select a certificate for code signing [1|2|3|a]: 3')
|
||||
);
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
contains('Signing iOS app for device deployment using developer identity: "iPhone Developer: Profile 3 (3333CCCC33)"')
|
||||
);
|
||||
expect(testLogger.errorText, isEmpty);
|
||||
verify(mockOpenSslStdIn.write('This is a mock certificate'));
|
||||
expect(developmentTeam, '4444DDDD44');
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,3 +224,12 @@ class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockProcess extends Mock implements Process {}
|
||||
class MockStream extends Mock implements Stream<List<int>> {}
|
||||
class MockStdIn extends Mock implements IOSink {}
|
||||
|
||||
Stream<String> mockTerminalStdInStream;
|
||||
|
||||
class TestTerminal extends AnsiTerminal {
|
||||
@override
|
||||
Stream<String> get onCharInput {
|
||||
return mockTerminalStdInStream;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user