Add an environment variable toggle to control new service protocol auth token

BUG=
R=asiva@google.com

Review URL: https://codereview.chromium.org/2486443002 .
This commit is contained in:
John McCutchan 2016-11-07 14:45:52 -08:00
parent a9d4575788
commit 14297ee480
4 changed files with 76 additions and 13 deletions

View file

@ -832,6 +832,8 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
result = Dart_CompileAll();
CHECK_RESULT(result);
}
result = Dart_SetEnvironmentCallback(EnvironmentCallback);
CHECK_RESULT(result);
Dart_ExitScope();
Dart_ExitIsolate();
return isolate;

View file

@ -0,0 +1,39 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--error_on_bad_type --error_on_bad_override
import 'dart:async';
import 'dart:developer';
import 'package:observatory/service_io.dart';
import 'package:unittest/unittest.dart';
import 'test_helper.dart';
Future<Null> testeeBefore() async {
print('testee before');
print(await Service.getInfo());
// Start the web server.
ServiceProtocolInfo info = await Service.controlWebServer(enable: true);
expect(info.serverUri, isNotNull);
// Ensure that we have the auth token in the path segments.
expect(info.serverUri.pathSegments.length, greaterThan(1));
// Sanity check the length of the auth token.
expect(info.serverUri.pathSegments[0].length, greaterThan(8));
}
var tests = [
(Isolate isolate) async {
await isolate.reload();
// Just getting here means that the testee enabled the service protocol
// web server.
expect(true, true);
}
];
main(args) => runIsolateTests(args,
tests,
testeeBefore: testeeBefore,
// the testee is responsible for starting the
// web server.
testeeControlsServer: true,
useAuthToken: true);

View file

@ -92,13 +92,15 @@ class _ServiceTesteeLauncher {
bool pause_on_unhandled_exceptions,
bool trace_service,
bool trace_compiler,
bool testeeControlsServer) {
bool testeeControlsServer,
bool useAuthToken) {
assert(pause_on_start != null);
assert(pause_on_exit != null);
assert(pause_on_unhandled_exceptions != null);
assert(trace_service != null);
assert(trace_compiler != null);
assert(testeeControlsServer != null);
assert(useAuthToken != null);
if (_shouldLaunchSkyShell()) {
return _spawnSkyProcess(pause_on_start,
@ -113,7 +115,8 @@ class _ServiceTesteeLauncher {
pause_on_unhandled_exceptions,
trace_service,
trace_compiler,
testeeControlsServer);
testeeControlsServer,
useAuthToken);
}
}
@ -122,7 +125,8 @@ class _ServiceTesteeLauncher {
bool pause_on_unhandled_exceptions,
bool trace_service,
bool trace_compiler,
bool testeeControlsServer) {
bool testeeControlsServer,
bool useAuthToken) {
assert(!_shouldLaunchSkyShell());
String dartExecutable = Platform.executable;
@ -151,7 +155,12 @@ class _ServiceTesteeLauncher {
}
fullArgs.addAll(args);
return _spawnCommon(dartExecutable, fullArgs);
return _spawnCommon(
dartExecutable,
fullArgs,
<String, String>{
'DART_SERVICE_USE_AUTH': '$useAuthToken'
});
}
Future<Process> _spawnSkyProcess(bool pause_on_start,
@ -193,13 +202,20 @@ class _ServiceTesteeLauncher {
fullArgs.add('--dart-flags=${dartFlags.join(' ')}');
fullArgs.addAll(args);
return _spawnCommon(dartExecutable, fullArgs);
return _spawnCommon(dartExecutable, fullArgs, <String, String>{});
}
Future<Process> _spawnCommon(String executable, List<String> arguments) {
Future<Process> _spawnCommon(String executable,
List<String> arguments,
Map<String, String> dartEnvironment) {
var environment = _TESTEE_SPAWN_ENV;
var bashEnvironment = new StringBuffer();
environment.forEach((k, v) => bashEnvironment.write("$k=$v "));
if (dartEnvironment != null) {
dartEnvironment.forEach((k, v) {
arguments.insert(0, '-D$k=$v');
});
}
print('** Launching $bashEnvironment$executable ${arguments.join(' ')}');
return Process.start(executable, arguments, environment: environment);
}
@ -209,13 +225,15 @@ class _ServiceTesteeLauncher {
bool pause_on_unhandled_exceptions,
bool trace_service,
bool trace_compiler,
bool testeeControlsServer) {
bool testeeControlsServer,
bool useAuthToken) {
return _spawnProcess(pause_on_start,
pause_on_exit,
pause_on_unhandled_exceptions,
trace_service,
trace_compiler,
testeeControlsServer).then((p) {
testeeControlsServer,
useAuthToken).then((p) {
Completer<Uri> completer = new Completer<Uri>();
process = p;
Uri uri;
@ -278,12 +296,14 @@ class _ServiceTesterRunner {
bool trace_compiler: false,
bool verbose_vm: false,
bool pause_on_unhandled_exceptions: false,
bool testeeControlsServer: false}) {
bool testeeControlsServer: false,
bool useAuthToken: false}) {
var process = new _ServiceTesteeLauncher();
process.launch(pause_on_start, pause_on_exit,
pause_on_unhandled_exceptions,
trace_service, trace_compiler,
testeeControlsServer).then((Uri serverAddress) async {
testeeControlsServer,
useAuthToken).then((Uri serverAddress) async {
if (mainArgs.contains("--gdb")) {
var pid = process.process.pid;
var wait = new Duration(seconds: 10);
@ -348,7 +368,8 @@ Future runIsolateTests(List<String> mainArgs,
bool trace_compiler: false,
bool verbose_vm: false,
bool pause_on_unhandled_exceptions: false,
bool testeeControlsServer: false}) async {
bool testeeControlsServer: false,
bool useAuthToken: false}) async {
assert(!pause_on_start || testeeBefore == null);
if (_isTestee()) {
new _ServiceTesteeRunner().run(testeeBefore: testeeBefore,
@ -365,7 +386,8 @@ Future runIsolateTests(List<String> mainArgs,
trace_compiler: trace_compiler,
verbose_vm: verbose_vm,
pause_on_unhandled_exceptions: pause_on_unhandled_exceptions,
testeeControlsServer: testeeControlsServer);
testeeControlsServer: testeeControlsServer,
useAuthToken: useAuthToken);
}
}

View file

@ -42,7 +42,7 @@ String _makeAuthToken() {
final String serviceAuthToken = _makeAuthToken();
// TODO(johnmccutchan): Enable the auth token and drop the origin check.
final bool useAuthToken = false;
final bool useAuthToken = const bool.fromEnvironment('DART_SERVICE_USE_AUTH');
// This is for use by the embedder. It is a map from the isolateId to
// anything implementing IsolateEmbedderData. When an isolate goes away,