Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor http2 test to use the fixtures module #15934

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions test/parallel/test-http2-serve-file.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
'use strict';

const common = require('../common');
const fixtures = require('../common/fixtures');

if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const http2 = require('http2');
const fs = require('fs');
const path = require('path');
const tls = require('tls');

const ajs_data = fs.readFileSync(path.resolve(common.fixturesDir, 'a.js'),
'utf8');
const ajs_data = fixtures.readSync('a.js', 'utf8');

const {
HTTP2_HEADER_PATH,
HTTP2_HEADER_STATUS
} = http2.constants;

function loadKey(keyname) {
return fs.readFileSync(
path.join(common.fixturesDir, 'keys', keyname), 'binary');
}

const key = loadKey('agent8-key.pem');
const cert = loadKey('agent8-cert.pem');
const ca = loadKey('fake-startcom-root-cert.pem');
const key = fixtures.readKey('agent8-key.pem', 'binary');
const cert = fixtures.readKey('agent8-cert.pem', 'binary');
const ca = fixtures.readKey('fake-startcom-root-cert.pem', 'binary');

const server = http2.createSecureServer({ key, cert });

server.on('stream', (stream, headers) => {
const name = headers[HTTP2_HEADER_PATH].slice(1);
const file = path.resolve(common.fixturesDir, name);
const file = fixtures.path(name);
fs.stat(file, (err, stat) => {
if (err != null || stat.isDirectory()) {
stream.respond({ [HTTP2_HEADER_STATUS]: 404 });
Expand Down