1 | 'use strict'
|
2 |
|
3 | const t = require('tap')
|
4 | const test = t.test
|
5 | const sget = require('simple-get').concat
|
6 | const fs = require('fs')
|
7 | const path = require('path')
|
8 | const Fastify = require('../..')
|
9 |
|
10 | try {
|
11 | var fastify = Fastify({
|
12 | https: {
|
13 | key: fs.readFileSync(path.join(__dirname, 'fastify.key')),
|
14 | cert: fs.readFileSync(path.join(__dirname, 'fastify.cert'))
|
15 | }
|
16 | })
|
17 | t.pass('Key/cert successfully loaded')
|
18 | } catch (e) {
|
19 | t.fail('Key/cert loading failed', e)
|
20 | }
|
21 |
|
22 | test('https get', t => {
|
23 | t.plan(1)
|
24 | try {
|
25 | fastify.get('/', function (req, reply) {
|
26 | reply.code(200).send({ hello: 'world' })
|
27 | })
|
28 | t.pass()
|
29 | } catch (e) {
|
30 | t.fail()
|
31 | }
|
32 | })
|
33 |
|
34 | fastify.listen(0, err => {
|
35 | t.error(err)
|
36 | fastify.server.unref()
|
37 |
|
38 | test('https get request', t => {
|
39 | t.plan(4)
|
40 | sget({
|
41 | method: 'GET',
|
42 | url: 'https://localhost:' + fastify.server.address().port,
|
43 | rejectUnauthorized: false
|
44 | }, (err, response, body) => {
|
45 | t.error(err)
|
46 | t.strictEqual(response.statusCode, 200)
|
47 | t.strictEqual(response.headers['content-length'], '' + body.length)
|
48 | t.deepEqual(JSON.parse(body), { hello: 'world' })
|
49 | })
|
50 | })
|
51 | })
|