-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathhttps.test.ts
More file actions
94 lines (78 loc) · 2.79 KB
/
https.test.ts
File metadata and controls
94 lines (78 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import assert from 'node:assert';
import { mm, type MockApplication } from '@eggjs/mock';
import { detectPort } from 'detect-port';
import { HttpClient } from 'urllib';
import { describe, it, afterEach } from 'vitest';
import { getFilepath, cluster } from './utils.ts';
const isBun = !!process.versions.bun;
const httpclient = new HttpClient({ connect: { rejectUnauthorized: false } });
// Bun rejects expired self-signed certificates even with rejectUnauthorized: false
describe.skipIf(isBun)('test/https.test.ts', () => {
let app: MockApplication;
afterEach(mm.restore);
describe('start https server with cluster options', () => {
afterEach(() => app && app.close());
it('should success with status 200', async () => {
const port = await detectPort();
const options = {
baseDir: getFilepath('apps/https-server'),
port,
https: {
key: getFilepath('server.key'),
cert: getFilepath('server.cert'),
ca: getFilepath('server.ca'),
},
};
app = cluster('apps/https-server', options);
await app.ready();
const response = await httpclient.request(`https://127.0.0.1:${port}`, {
dataType: 'text',
});
assert(response.status === 200);
assert(response.data === 'https server');
});
it('should listen https and http at the same time', async () => {
const port = await detectPort();
const debugPort = await detectPort();
const options = {
baseDir: getFilepath('apps/https-server'),
debugPort,
port,
https: {
key: getFilepath('server.key'),
cert: getFilepath('server.cert'),
ca: getFilepath('server.ca'),
},
};
app = cluster('apps/https-server', options);
await app.ready();
let response = await httpclient.request(`https://127.0.0.1:${port}`, {
dataType: 'text',
});
assert(response.status === 200);
assert(response.data === 'https server');
response = await httpclient.request(`http://127.0.0.1:${debugPort}`, {
dataType: 'text',
});
assert(response.status === 200);
assert(response.data === 'https server');
});
});
describe('start https server with app config cluster', () => {
afterEach(() => app && app.close());
it('should success with status 200', async () => {
const port = await detectPort();
const options = {
baseDir: getFilepath('apps/https-server-config'),
port,
};
app = cluster('apps/https-server-config', options);
await app.ready();
const response = await httpclient.request(`https://127.0.0.1:${port}`, {
dataType: 'text',
});
assert(response.status === 200);
assert(response.data === 'https server config');
});
});
});