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

http2: improve test coverage #15105

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions test/parallel/test-http2-util-assert-valid-pseudoheader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Flags: --expose-internals
'use strict';

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

// Tests the assertValidPseudoHeader function that is used within the
// mapToHeaders function. The assert function is not exported so we
// have to test it through mapToHeaders

const { mapToHeaders } = require('internal/http2/util');
const assert = require('assert');

function isNotError(val) {
assert(!(val instanceof Error));
}

function isError(val) {
common.expectsError({
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
type: Error,
message: '":foo" is an invalid pseudoheader or is used incorrectly'
})(val);
}

isNotError(mapToHeaders({ ':status': 'a' }));
isNotError(mapToHeaders({ ':path': 'a' }));
isNotError(mapToHeaders({ ':authority': 'a' }));
isNotError(mapToHeaders({ ':scheme': 'a' }));
isNotError(mapToHeaders({ ':method': 'a' }));

isError(mapToHeaders({ ':foo': 'a' }));
16 changes: 16 additions & 0 deletions test/parallel/test-http2-util-nghttp2error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
const { strictEqual } = require('assert');
const { NghttpError } = require('internal/http2/util');

common.expectsError(() => {
const err = new NghttpError(-501);
strictEqual(err.errno, -501);
throw err;
}, {
code: 'ERR_HTTP2_ERROR',
type: NghttpError,
message: 'Invalid argument'
});
67 changes: 67 additions & 0 deletions test/parallel/test-http2-util-update-options-buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Flags: --expose-internals
'use strict';

require('../common');

// Test coverage for the updateOptionsBuffer method used internally
// by the http2 implementation.

const { updateOptionsBuffer } = require('internal/http2/util');
const { optionsBuffer } = process.binding('http2');
const { ok, strictEqual } = require('assert');

const IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE = 0;
const IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS = 1;
const IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH = 2;
const IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS = 3;
const IDX_OPTIONS_PADDING_STRATEGY = 4;
const IDX_OPTIONS_FLAGS = 5;

{
updateOptionsBuffer({
maxDeflateDynamicTableSize: 1,
maxReservedRemoteStreams: 2,
maxSendHeaderBlockLength: 3,
peerMaxConcurrentStreams: 4,
paddingStrategy: 5
});

strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 3);
strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4);
strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5);

const flags = optionsBuffer[IDX_OPTIONS_FLAGS];

ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE));
ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS));
ok(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH));
ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS));
ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY));
}

{
optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH] = 0;

updateOptionsBuffer({
maxDeflateDynamicTableSize: 1,
maxReservedRemoteStreams: 2,
peerMaxConcurrentStreams: 4,
paddingStrategy: 5
});

strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS], 2);
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH], 0);
strictEqual(optionsBuffer[IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS], 4);
strictEqual(optionsBuffer[IDX_OPTIONS_PADDING_STRATEGY], 5);

const flags = optionsBuffer[IDX_OPTIONS_FLAGS];

ok(flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE));
ok(flags & (1 << IDX_OPTIONS_MAX_RESERVED_REMOTE_STREAMS));
ok(!(flags & (1 << IDX_OPTIONS_MAX_SEND_HEADER_BLOCK_LENGTH)));
ok(flags & (1 << IDX_OPTIONS_PEER_MAX_CONCURRENT_STREAMS));
ok(flags & (1 << IDX_OPTIONS_PADDING_STRATEGY));
}