Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: runtime/observatory/tests/service/auth_token_test.dart

Issue 2500543002: Add following tests : (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // VMOptions=--error_on_bad_type --error_on_bad_override 4 // VMOptions=--error_on_bad_type --error_on_bad_override
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:developer'; 7 import 'dart:developer';
8 import 'dart:io' as io;
8 import 'package:observatory/service_io.dart'; 9 import 'package:observatory/service_io.dart';
9 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
10 import 'test_helper.dart'; 11 import 'test_helper.dart';
11 12
12 Future<Null> testeeBefore() async { 13 Future<Null> testeeBefore() async {
13 print('testee before'); 14 print('testee before');
14 print(await Service.getInfo()); 15 print(await Service.getInfo());
15 // Start the web server. 16 // Start the web server.
16 ServiceProtocolInfo info = await Service.controlWebServer(enable: true); 17 ServiceProtocolInfo info = await Service.controlWebServer(enable: true);
17 expect(info.serverUri, isNotNull); 18 expect(info.serverUri, isNotNull);
18 // Ensure that we have the auth token in the path segments. 19 // Ensure that we have the auth token in the path segments.
19 expect(info.serverUri.pathSegments.length, greaterThan(1)); 20 expect(info.serverUri.pathSegments.length, greaterThan(1));
20 // Sanity check the length of the auth token. 21 // Sanity check the length of the auth token.
21 expect(info.serverUri.pathSegments[0].length, greaterThan(8)); 22 expect(info.serverUri.pathSegments[0].length, greaterThan(8));
23
24 // Try connecting to the server without the auth token, it should throw
25 // an exception.
26 var port = info.serverUri.port;
27 var url = Uri.parse('http://127.0.0.1:$port');
28 var httpClient = new io.HttpClient();
29 try {
30 var request = await httpClient.getUrl(url);
31 expect(true, false);
32 } catch (e) {
33 expect(true, true);
34 }
35
36 // Try connecting to the server with the auth token, it should succeed.
37 try {
38 var request = await httpClient.getUrl(info.serverUri);
39 expect(true, true);
40 } catch (e) {
41 expect(true, false);
42 }
22 } 43 }
23 44
24 var tests = [ 45 var tests = [
25 (Isolate isolate) async { 46 (Isolate isolate) async {
26 await isolate.reload(); 47 await isolate.reload();
27 // Just getting here means that the testee enabled the service protocol 48 // Just getting here means that the testee enabled the service protocol
28 // web server. 49 // web server.
29 expect(true, true); 50 expect(true, true);
30 } 51 }
31 ]; 52 ];
32 53
33 main(args) => runIsolateTests(args, 54 main(args) => runIsolateTests(args,
34 tests, 55 tests,
35 testeeBefore: testeeBefore, 56 testeeBefore: testeeBefore,
36 // the testee is responsible for starting the 57 // the testee is responsible for starting the
37 // web server. 58 // web server.
38 testeeControlsServer: true, 59 testeeControlsServer: true,
39 useAuthToken: true); 60 useAuthToken: true);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698