summaryrefslogtreecommitdiffstats
path: root/test/https.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/https.js')
-rw-r--r--test/https.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/https.js b/test/https.js
new file mode 100644
index 0000000..1ba492c
--- /dev/null
+++ b/test/https.js
@@ -0,0 +1,74 @@
+'use strict'
+
+const { test } = require('tap')
+const { Client } = require('..')
+const { createServer } = require('https')
+const pem = require('https-pem')
+
+test('https get with tls opts', (t) => {
+ t.plan(6)
+
+ const server = createServer(pem, (req, res) => {
+ t.equal('/', req.url)
+ t.equal('GET', req.method)
+ res.setHeader('content-type', 'text/plain')
+ res.end('hello')
+ })
+ t.teardown(server.close.bind(server))
+
+ server.listen(0, () => {
+ const client = new Client(`https://localhost:${server.address().port}`, {
+ tls: {
+ rejectUnauthorized: false
+ }
+ })
+ t.teardown(client.close.bind(client))
+
+ client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
+ t.error(err)
+ t.equal(statusCode, 200)
+ t.equal(headers['content-type'], 'text/plain')
+ const bufs = []
+ body.on('data', (buf) => {
+ bufs.push(buf)
+ })
+ body.on('end', () => {
+ t.equal('hello', Buffer.concat(bufs).toString('utf8'))
+ })
+ })
+ })
+})
+
+test('https get with tls opts ip', (t) => {
+ t.plan(6)
+
+ const server = createServer(pem, (req, res) => {
+ t.equal('/', req.url)
+ t.equal('GET', req.method)
+ res.setHeader('content-type', 'text/plain')
+ res.end('hello')
+ })
+ t.teardown(server.close.bind(server))
+
+ server.listen(0, () => {
+ const client = new Client(`https://127.0.0.1:${server.address().port}`, {
+ tls: {
+ rejectUnauthorized: false
+ }
+ })
+ t.teardown(client.close.bind(client))
+
+ client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
+ t.error(err)
+ t.equal(statusCode, 200)
+ t.equal(headers['content-type'], 'text/plain')
+ const bufs = []
+ body.on('data', (buf) => {
+ bufs.push(buf)
+ })
+ body.on('end', () => {
+ t.equal('hello', Buffer.concat(bufs).toString('utf8'))
+ })
+ })
+ })
+})