Skip to content

Commit 8de6b69

Browse files

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy