11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Tests the basic operation of creating a plaintext or TLS 41cb0ef41Sopenharmony_ci// HTTP2 server. The server does not do anything at this point 51cb0ef41Sopenharmony_ci// other than start listening. 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst common = require('../common'); 81cb0ef41Sopenharmony_ciconst commonFixtures = require('../common/fixtures'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciif (!common.hasCrypto) 111cb0ef41Sopenharmony_ci common.skip('missing crypto'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst assert = require('assert'); 141cb0ef41Sopenharmony_ciconst http2 = require('http2'); 151cb0ef41Sopenharmony_ciconst tls = require('tls'); 161cb0ef41Sopenharmony_ciconst net = require('net'); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciconst options = { 191cb0ef41Sopenharmony_ci key: commonFixtures.readKey('agent2-key.pem'), 201cb0ef41Sopenharmony_ci cert: commonFixtures.readKey('agent2-cert.pem') 211cb0ef41Sopenharmony_ci}; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci// There should not be any throws. 241cb0ef41Sopenharmony_ciconst serverTLS = http2.createSecureServer(options, () => {}); 251cb0ef41Sopenharmony_ciserverTLS.listen(0, common.mustCall(() => serverTLS.close())); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci// There should not be an error event reported either. 281cb0ef41Sopenharmony_ciserverTLS.on('error', common.mustNotCall()); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciconst server = http2.createServer(options, common.mustNotCall()); 311cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => server.close())); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci// There should not be an error event reported either. 341cb0ef41Sopenharmony_ciserver.on('error', common.mustNotCall()); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci// Test the plaintext server socket timeout. 371cb0ef41Sopenharmony_ci{ 381cb0ef41Sopenharmony_ci let client; 391cb0ef41Sopenharmony_ci const server = http2.createServer(); 401cb0ef41Sopenharmony_ci server.on('timeout', common.mustCall(() => { 411cb0ef41Sopenharmony_ci server.close(); 421cb0ef41Sopenharmony_ci if (client) 431cb0ef41Sopenharmony_ci client.end(); 441cb0ef41Sopenharmony_ci })); 451cb0ef41Sopenharmony_ci server.setTimeout(common.platformTimeout(1000), common.mustCall()); 461cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 471cb0ef41Sopenharmony_ci const port = server.address().port; 481cb0ef41Sopenharmony_ci client = net.connect(port, common.mustCall()); 491cb0ef41Sopenharmony_ci })); 501cb0ef41Sopenharmony_ci} 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci// Test that `http2.createServer()` supports `net.Server` options. 531cb0ef41Sopenharmony_ci{ 541cb0ef41Sopenharmony_ci const server = http2.createServer({ allowHalfOpen: true }); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci server.on('connection', common.mustCall((socket) => { 571cb0ef41Sopenharmony_ci assert.strictEqual(socket.allowHalfOpen, true); 581cb0ef41Sopenharmony_ci socket.end(); 591cb0ef41Sopenharmony_ci server.close(); 601cb0ef41Sopenharmony_ci })); 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci assert.strictEqual(server.allowHalfOpen, true); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 651cb0ef41Sopenharmony_ci const port = server.address().port; 661cb0ef41Sopenharmony_ci const socket = net.connect(port, common.mustCall()); 671cb0ef41Sopenharmony_ci socket.resume(); 681cb0ef41Sopenharmony_ci })); 691cb0ef41Sopenharmony_ci} 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci// Test the secure server socket timeout. 721cb0ef41Sopenharmony_ci{ 731cb0ef41Sopenharmony_ci let client; 741cb0ef41Sopenharmony_ci const server = http2.createSecureServer(options); 751cb0ef41Sopenharmony_ci server.on('timeout', common.mustCall(() => { 761cb0ef41Sopenharmony_ci server.close(); 771cb0ef41Sopenharmony_ci if (client) 781cb0ef41Sopenharmony_ci client.end(); 791cb0ef41Sopenharmony_ci })); 801cb0ef41Sopenharmony_ci server.setTimeout(common.platformTimeout(1000), common.mustCall()); 811cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 821cb0ef41Sopenharmony_ci const port = server.address().port; 831cb0ef41Sopenharmony_ci client = tls.connect({ 841cb0ef41Sopenharmony_ci port: port, 851cb0ef41Sopenharmony_ci rejectUnauthorized: false, 861cb0ef41Sopenharmony_ci ALPNProtocols: ['h2'] 871cb0ef41Sopenharmony_ci }, common.mustCall()); 881cb0ef41Sopenharmony_ci })); 891cb0ef41Sopenharmony_ci} 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci// Test that `http2.createSecureServer()` supports `net.Server` options. 921cb0ef41Sopenharmony_ci{ 931cb0ef41Sopenharmony_ci const server = http2.createSecureServer({ 941cb0ef41Sopenharmony_ci allowHalfOpen: true, 951cb0ef41Sopenharmony_ci ...options 961cb0ef41Sopenharmony_ci }); 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci server.on('secureConnection', common.mustCall((socket) => { 991cb0ef41Sopenharmony_ci assert.strictEqual(socket.allowHalfOpen, true); 1001cb0ef41Sopenharmony_ci socket.end(); 1011cb0ef41Sopenharmony_ci server.close(); 1021cb0ef41Sopenharmony_ci })); 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ci assert.strictEqual(server.allowHalfOpen, true); 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 1071cb0ef41Sopenharmony_ci const port = server.address().port; 1081cb0ef41Sopenharmony_ci const socket = tls.connect({ 1091cb0ef41Sopenharmony_ci port: port, 1101cb0ef41Sopenharmony_ci rejectUnauthorized: false, 1111cb0ef41Sopenharmony_ci ALPNProtocols: ['h2'] 1121cb0ef41Sopenharmony_ci }, common.mustCall()); 1131cb0ef41Sopenharmony_ci socket.resume(); 1141cb0ef41Sopenharmony_ci })); 1151cb0ef41Sopenharmony_ci} 116