Skip to content

Commit 3c6a95f

Browse files
committed
TLS options E2E tests
1 parent ce514f5 commit 3c6a95f

File tree

6 files changed

+299
-0
lines changed

6 files changed

+299
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDR8FlEhQ8XZctL
3+
mGdx78Z5EInK2mcfU9Nq4oUKkPeiql7Sd3cd3prd+m5MYylL255wAZf8Fdupkko2
4+
cjQEsU24jUBWVG5q3YqZ+OidFYdxYnPbDhFtzL3Lr2zHGAi+MgqVENUF6ED2O5tU
5+
9U1crceXmXHb3E8Sg+zXX6TMVCS11OH9VQ1ZutM0fFMPZxmfU5aOfd5kuTmTiaOt
6+
OMyymroUPgzRW6UcbLfSdD7KuNFQgHDHiWkr2MtoZffgGM/cOfmCdgE85MdL6kyb
7+
7TUTbAlTSpJNWwygObce7DN7qwM8HocRWSAfH+y3ewbs2NtzG1Az+a/kUBjhvmjT
8+
WFiwDT+1AgMBAAECggEBALkJMXTeHh4OP2+ipVJb9r/P3tMnSornFEl5268jdNAv
9+
f6HbX+a4xCDwUHUNVWGh8XRhQzcRgOllofl5EPYt3AXUoac1hZi1KStqooOJbTZ3
10+
gwvIy33OXl5/gM2+Fj6k1oTqMAej3FXq1Y69InGUTX4F5b/V3u+/zWlKyHK7mxuT
11+
LIP3/iAxbpST5FB1G7ZPyz5mvzvEQFRiv9ubuMxYg3fzORULtbnnHNAM5jLG3IzZ
12+
9EM/1umaeZu1bg9rGVVgr0l/rWMJSg5u+Z6jcrt9+Oj7hYrMPGHKHXAPhC1gaq+k
13+
tlKHj/mhmJyN0jUXt71UgrsWF3MhrK2W2AlIfxXhIIECgYEA8oaIEOaeNmtDqlH5
14+
MmU0jd2EcMRnLrlfKs4fKObFoSMqELRB3yJ1u5Yt/wQCCSpN9bhkinR0l4Q7YsAy
15+
4sg5Q3VaA/rUWkVKkv2sD04LbBmpHr5vksPnIPKcfAY3csQ1F5pu9gY6zgzdxBvN
16+
nWEu8tqbUSdC5+0F+tB8IDW+/lUCgYEA3ZpVXmBLvgeZJ8rNjCCeKR5hXMYdFKqC
17+
Yd5KfasTKH7h8a4GWo/mtUsS5UPRRjhrP5mPjdUKBFhSaJtX+k9Hhot58RN20fWR
18+
4Ake4yV/cNFRykD1jsv9JJiPkggnVLVXN91+/EnKJozWv46q6nG44iX+q2w2i9FQ
19+
6lohgwQp2+ECgYEAwKJY+0uiiUkD0woPbJb0emZj5wophvRYgfB80YkTmt0KcYAr
20+
/icp6pjr6e3uDAedKrqOqWa8oQi3/sT45ibxTQKuQBEAkL8O79grzXBJJFDxgujy
21+
SFnwgLwTzXNGoZL1NM1Gq4XhOX8Aut72n7Xsi5tV2MzdmMgsgr8MiK0ICo0CgYBA
22+
h4yMauYjc/r5R2kLgQQNXTdk2JvnRK+q6Bww8/wkMq6AvfhDrtuztyTNdi4ekJdK
23+
ceEHoB3GniGBLJs13JgrabocpVpYUXYlEwLXijfOFmYGy1u2NViFq5dDIvSxCg1X
24+
yzwLI0GmcCSoq1bB5lO8Juw95skLdexmEdDoYfH+gQKBgDgaFlF9lYuKd0HhAxxm
25+
oJ8WBv26FWxR8/UsvUPqI8Mzmb8J1Q22tZEMEVr8bN/HkcL+8DVQ4uh2zx9+rqC0
26+
aPqJZNgePGpRDhZ/cwA8xsg+Xkou8rrFjpGRuVuG9FvMEexufkHoDc94ppONuwsR
27+
QzjTUxgXdLjtxT95ISwX83Nr
28+
-----END PRIVATE KEY-----
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIEgjCCAuqgAwIBAgIQBeTmjjlnyrCQUy06Xx/ybzANBgkqhkiG9w0BAQsFADCB
3+
pTEeMBwGA1UEChMVbWtjZXJ0IGRldmVsb3BtZW50IENBMT0wOwYDVQQLDDR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MD+d4aMKpdIJivwXByg6fJCtPOIprAiGeR
20+
GuE9Q9ceUUJVrTYiy5CZeKTIQp4ZqWu5/wBQ+yvbsvxnzq2ESDpGmCkY6/ToMWmu
21+
5cZPbZcyF7XBybSBdvaMGFsthRpawvQMsGHDZBaVhLn099Hjx2p35jNiM+HqCQXn
22+
NweLYMJx9FZtOYyNJoTj0w97ViaSubz7V9n7LVIxW1QXmDXAk+75Fwq3x+n/tfhe
23+
1BTLEOKvARvRVB6M1EE0z+zeNusHIu/TUMSmGv59OhsQdW5Lp1D0o3JK2mHu6tgP
24+
+v1XRMaTQq73oHqU0oXCtsEdPuoFBNREBDhBOGB5wtFjfniu1zD0cKSDbVslSD5B
25+
LKu9Yi1PzZTWVkaOWQolA6sYwWFLhQbHoyQoNjAJz58VNNtYIMjR6fZ0xTYiPQpJ
26+
4Jh3TJKU
27+
-----END CERTIFICATE-----
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: _experiment_sound
2+
version: 1.0.0
3+
description: >-
4+
A fake package used for testing experimental language features.
5+
publish_to: none
6+
7+
environment:
8+
sdk: ^3.2.0
9+
10+
dependencies:
11+
intl: ^0.17.0
12+
path: ^1.8.2
13+
14+
dev_dependencies:
15+
build_runner: ^2.4.0
16+
build_web_compilers: ^4.0.4
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
3+
<head>
4+
<script defer src="main.dart.js"></script>
5+
</head>
6+
7+
</html>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'dart:async';
6+
import 'dart:core';
7+
// TODO: https://github.com/dart-lang/webdev/issues/2508
8+
// ignore: deprecated_member_use
9+
import 'dart:html';
10+
11+
void main() {
12+
// for evaluation
13+
Timer.periodic(const Duration(seconds: 1), (_) {
14+
printSimpleLocalRecord();
15+
printComplexLocalRecord();
16+
printNestedLocalRecord();
17+
printSimpleNamedLocalRecord();
18+
printComplexNamedLocalRecord();
19+
printNestedNamedLocalRecord();
20+
print('Patterns'); // Breakpoint: callTestPattern1
21+
testPattern(['a', 1]);
22+
testPattern([3.14, 'b']);
23+
testPattern([0, 1]);
24+
testPattern2();
25+
print('Classes');
26+
testClass();
27+
});
28+
29+
document.body!.appendText('Program is running!');
30+
}
31+
32+
void printSimpleLocalRecord() {
33+
final record = (true, 3);
34+
print(record); // Breakpoint: printSimpleLocalRecord
35+
}
36+
37+
void printSimpleNamedLocalRecord() {
38+
final record = (true, cat: 'Vasya');
39+
print(record); // Breakpoint: printSimpleNamedLocalRecord
40+
}
41+
42+
void printComplexLocalRecord() {
43+
final record = (true, 3, {'a': 1, 'b': 5});
44+
print(record); // Breakpoint: printComplexLocalRecord
45+
}
46+
47+
void printComplexNamedLocalRecord() {
48+
final record = (true, 3, array: {'a': 1, 'b': 5});
49+
print(record); // Breakpoint: printComplexNamedLocalRecord
50+
}
51+
52+
void printNestedLocalRecord() {
53+
final record = (true, (false, 5));
54+
print(record); // Breakpoint: printNestedLocalRecord
55+
}
56+
57+
void printNestedNamedLocalRecord() {
58+
final record = (true, inner: (false, 5));
59+
print(record); // Breakpoint: printNestedNamedLocalRecord
60+
}
61+
62+
void testClass() {
63+
final greeter = GreeterClass(greeteeName: 'Charlie Brown');
64+
greeter.sayHello();
65+
}
66+
67+
String testPattern(Object obj) {
68+
switch (obj) {
69+
case [final a, final int n] || [final int n, final a]
70+
when n == 1 && a is String:
71+
return a.toString(); // Breakpoint: testPatternCase1
72+
case [final double n, final a] || [final a, final double n]
73+
when (n - 3.14).abs() < 0.001:
74+
return a.toString(); // Breakpoint: testPatternCase2
75+
default:
76+
return 'default'; // Breakpoint: testPatternDefault
77+
}
78+
}
79+
80+
String testPattern2() {
81+
final dog = 'Prismo';
82+
final cats = ['Garfield', 'Tom']; // Breakpoint: testPattern2Case1
83+
final [firstCat, secondCat] = cats;
84+
print(firstCat); // Breakpoint: testPattern2Case2
85+
return '$dog, $firstCat, $secondCat';
86+
}
87+
88+
class GreeterClass {
89+
final String greeteeName;
90+
final bool useFrench;
91+
92+
GreeterClass({
93+
this.greeteeName = 'Snoopy',
94+
this.useFrench = false,
95+
});
96+
97+
void sayHello() {
98+
useFrench ? greetInFrench() : greetInEnglish();
99+
}
100+
101+
void greetInEnglish() {
102+
print('Hello $greeteeName'); // Breakpoint: testClass1Case1
103+
}
104+
105+
void greetInFrench() {
106+
print('Bonjour $greeteeName');
107+
}
108+
}

webdev/test/tls_test.dart

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import 'dart:io';
2+
3+
import 'package:collection/collection.dart';
4+
import 'package:logging/logging.dart';
5+
import 'package:path/path.dart' as p;
6+
import 'package:test/test.dart';
7+
import 'package:test_descriptor/test_descriptor.dart' as d;
8+
import 'package:test_process/test_process.dart';
9+
10+
import 'package:webdev/src/logging.dart';
11+
import 'package:webdev/src/serve/utils.dart';
12+
13+
import 'test_utils.dart';
14+
15+
void main() {
16+
group('serve app with TLS options', () {
17+
// Change to true for debugging.
18+
final debug = false;
19+
20+
final testRunner = TestRunner();
21+
late String soundExampleDirectory;
22+
23+
setUpAll(() async {
24+
configureLogWriter(debug);
25+
await testRunner.setUpAll();
26+
soundExampleDirectory = p.absolute(
27+
p.join(p.current, '..', 'fixtures', '_testTlsHostnameSound'));
28+
29+
final process = await TestProcess.start(
30+
'dart',
31+
['pub', 'upgrade'],
32+
workingDirectory: soundExampleDirectory,
33+
environment: getPubEnvironment(),
34+
);
35+
36+
await process.shouldExit(0);
37+
38+
await d
39+
.file('.dart_tool/package_config.json', isNotEmpty)
40+
.validate(soundExampleDirectory);
41+
await d.file('pubspec.lock', isNotEmpty).validate(soundExampleDirectory);
42+
});
43+
44+
test('listens on a loopback interface', () async {
45+
final port = await findUnusedPort();
46+
final args = [
47+
'serve',
48+
'web:$port',
49+
'--hostname=0.0.0.0',
50+
'--tls-cert-chain=localhost+2.pem',
51+
'--tls-cert-key=localhost+2-key.pem',
52+
];
53+
54+
final process = await testRunner.runWebDev(args,
55+
workingDirectory: soundExampleDirectory);
56+
await expectLater(process.stdout, emitsThrough(contains('Succeeded')));
57+
58+
final client = HttpClient()
59+
..badCertificateCallback = (_, __, ___) => true;
60+
try {
61+
final request =
62+
await client.getUrl(Uri.parse('https://localhost:$port'));
63+
final response = await request.close();
64+
expect(response.statusCode, equals(200));
65+
} finally {
66+
client.close(force: true);
67+
}
68+
69+
await process.kill();
70+
await process.shouldExit();
71+
});
72+
73+
test('listens on a non-loopback interface', () async {
74+
final port = await findUnusedPort();
75+
final args = [
76+
'serve',
77+
'web:$port',
78+
'--hostname=0.0.0.0',
79+
'--tls-cert-chain=localhost+2.pem',
80+
'--tls-cert-key=localhost+2-key.pem',
81+
];
82+
83+
final process = await testRunner.runWebDev(args,
84+
workingDirectory: soundExampleDirectory);
85+
await expectLater(process.stdout, emitsThrough(contains('Succeeded')));
86+
87+
final interfaces = await NetworkInterface.list(
88+
type: InternetAddressType.IPv4,
89+
includeLoopback: false,
90+
);
91+
final nonLoopback = interfaces.expand((i) => i.addresses).firstOrNull;
92+
93+
if (nonLoopback == null) {
94+
Logger.root.info(
95+
'No non-loopback IPv4 address available, skipping hostname test.');
96+
} else {
97+
final client = HttpClient()
98+
..badCertificateCallback = (_, __, ___) => true;
99+
try {
100+
final request = await client
101+
.getUrl(Uri.parse('https://${nonLoopback.address}:$port'));
102+
final response = await request.close();
103+
expect(response.statusCode, equals(200));
104+
} finally {
105+
client.close(force: true);
106+
}
107+
}
108+
109+
await process.kill();
110+
await process.shouldExit();
111+
});
112+
});
113+
}

0 commit comments

Comments
 (0)