Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parthverma1 committed Jul 23, 2024
1 parent a3b3e65 commit 2fac605
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/test-verbose-http2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'

var assert = require('assert')
var tape = require('tape')
var destroyable = require('server-destroy')
var zlib = require('zlib')

var server = require('./server')
var request = require('../index').defaults({protocolVersion: 'http2'})
Expand Down Expand Up @@ -32,6 +34,13 @@ tape('setup', function (t) {
res.writeHead(301, { 'location': 'http://localhost:' + plainServer.port + '/' })
res.end()
})
http2Server.on('/gzip', function (req, res) {
res.writeHead(200, { 'content-encoding': 'gzip' })
zlib.gzip('gzip', function (err, data) {
assert.equal(err, null)
res.end(data)
})
})

t.end()
})
Expand Down Expand Up @@ -150,6 +159,35 @@ tape('HTTPS: verbose=true', function (t) {
})
})

tape('HTTPS Gzip: verbose=true', function (t) {
var options = {
verbose: true,
strictSSL: false,
time: false, // verbose overrides timing setting
protocolVersion: 'http2'
}

request('https://localhost:' + http2Server.port + '/gzip', {...options, gzip: true}, function (err, res, body, debug) {
t.equal(err, null)
t.equal(body, 'gzip')
t.equal(Array.isArray(debug), true)
t.equal(debug.length, 1)

t.equal(typeof res.socket.__SESSION_ID, 'string')
t.equal(typeof res.socket.__SESSION_DATA, 'object')
t.deepEqual(Object.keys(debug[0]), ['request', 'session', 'response', 'timingStart', 'timingStartTimer', 'timings'])
t.deepEqual(Object.keys(debug[0].request), ['method', 'href', 'headers', 'proxy', 'httpVersion'])
t.deepEqual(Object.keys(debug[0].session), ['id', 'reused', 'data'])
t.deepEqual(Object.keys(debug[0].session.data), ['addresses', 'tls'])
t.deepEqual(Object.keys(debug[0].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[0].session.reused, true)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])
t.equal(debug[0].response.downloadedBytes, 24)

t.end()
})
})

tape('HTTPS: redirect(HTTP) + verbose=true', function (t) {
var options = {
verbose: true,
Expand Down
41 changes: 41 additions & 0 deletions tests/test-verbose.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'

var assert = require('assert')
var tape = require('tape')
var destroyable = require('server-destroy')
var zlib = require('zlib')

var server = require('./server')
var request = require('../index')
Expand Down Expand Up @@ -32,6 +34,13 @@ tape('setup', function (t) {
res.writeHead(301, { 'location': 'http://localhost:' + plainServer.port + '/' })
res.end()
})
httpsServer.on('/gzip', function (req, res) {
res.writeHead(200, { 'content-encoding': 'gzip' })
zlib.gzip('gzip', function (err, data) {
assert.equal(err, null)
res.end(data)
})
})

t.end()
})
Expand Down Expand Up @@ -76,6 +85,7 @@ tape('HTTP: verbose=true', function (t) {
t.deepEqual(Object.keys(debug[0].session.data), ['addresses'])
t.equal(debug[0].session.reused, false)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])
t.equal(debug[0].response.downloadedBytes, 5)

t.notEqual(debug[0].response.headers.length, 0)
t.equal(debug[0].response.headers[0].key, 'Date')
Expand Down Expand Up @@ -114,6 +124,7 @@ tape('HTTP: redirect(HTTPS) + verbose=true', function (t) {
t.deepEqual(Object.keys(debug[1].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[1].session.reused, false)
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])
t.equal(debug[1].response.downloadedBytes, 5)

t.end()
})
Expand Down Expand Up @@ -141,6 +152,35 @@ tape('HTTPS: verbose=true', function (t) {
t.deepEqual(Object.keys(debug[0].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[0].session.reused, false)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])
t.equal(debug[0].response.downloadedBytes, 5)

t.end()
})
})

tape('HTTPS Gzip: verbose=true', function (t) {
var options = {
verbose: true,
strictSSL: false,
time: false // verbose overrides timing setting
}

request('https://localhost:' + httpsServer.port + '/gzip', {...options, gzip: true}, function (err, res, body, debug) {
t.equal(err, null)
t.equal(body, 'gzip')
t.equal(Array.isArray(debug), true)
t.equal(debug.length, 1)

t.equal(typeof res.socket.__SESSION_ID, 'string')
t.equal(typeof res.socket.__SESSION_DATA, 'object')
t.deepEqual(Object.keys(debug[0]), ['request', 'session', 'response', 'timingStart', 'timingStartTimer', 'timings'])
t.deepEqual(Object.keys(debug[0].request), ['method', 'href', 'headers', 'proxy', 'httpVersion'])
t.deepEqual(Object.keys(debug[0].session), ['id', 'reused', 'data'])
t.deepEqual(Object.keys(debug[0].session.data), ['addresses', 'tls'])
t.deepEqual(Object.keys(debug[0].session.data.tls), ['reused', 'authorized', 'authorizationError', 'cipher', 'protocol', 'ephemeralKeyInfo', 'peerCertificate'])
t.equal(debug[0].session.reused, false)
t.deepEqual(Object.keys(debug[0].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])
t.equal(debug[0].response.downloadedBytes, 24)

t.end()
})
Expand Down Expand Up @@ -175,6 +215,7 @@ tape('HTTPS: redirect(HTTP) + verbose=true', function (t) {
t.deepEqual(Object.keys(debug[1].session.data), ['addresses'])
t.equal(debug[1].session.reused, false)
t.deepEqual(Object.keys(debug[1].response), ['statusCode', 'headers', 'httpVersion', 'downloadedBytes'])
t.equal(debug[1].response.downloadedBytes, 5)

t.end()
})
Expand Down

0 comments on commit 2fac605

Please sign in to comment.