Skip to content

File tree

lib/socket.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ module.exports = class Socket extends EventEmitter {
77
constructor(options) {
88
super()
99

10+
// Pretend this is a TLSSocket
1011
if (options.proto === 'https') {
1112
// https://github.com/nock/nock/issues/158
1213
this.authorized = true
14+
// https://github.com/nock/nock/issues/2147
15+
this.encrypted = true
1316
}
1417

1518
this.bufferSize = 0

tests/test_socket.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
'use strict'
22

3+
const { expect } = require('chai')
34
const http = require('http')
5+
const https = require('https')
46
const nock = require('..')
57

68
require('./setup')
79

10+
it('should expose TLSSocket attributes for HTTPS requests', done => {
11+
nock('https://example.test').get('/').reply()
12+
13+
https.get('https://example.test').on('socket', socket => {
14+
expect(socket.authorized).to.equal(true)
15+
expect(socket.encrypted).to.equal(true)
16+
done()
17+
})
18+
})
19+
20+
it('should not have TLSSocket attributes for HTTP requests', done => {
21+
nock('http://example.test').get('/').reply()
22+
23+
http.get('http://example.test').on('socket', socket => {
24+
expect(socket.authorized).to.equal(undefined)
25+
expect(socket.encrypted).to.equal(undefined)
26+
done()
27+
})
28+
})
29+
830
describe('`Socket#setTimeout()`', () => {
931
it('adds callback as a one-time listener for parity with a real socket', done => {
1032
nock('http://example.test').get('/').delayConnection(100).reply()

0 commit comments

Comments
 (0)