diff --git a/test/common/README.md b/test/common/README.md index 267d28140c5003..7bbff3f11a57a3 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -261,6 +261,134 @@ Platform normalizes the `pwd` command. Synchronous version of `spawnPwd`. +_**Note:** tag functions for tagged template literals (begin with `tag*`) +usually take a multiline template literal with leading and trailing line break: +this allows dividing code noise (like backticks) and pure data. +These leading and trailing line breaks are stripped in the result. +All these functions leave interpolated variables untouched, +only literal parts are processed._ + +### tagGlue() +* return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) + +Tag function for tagged template literals: +removes all literal line breaks and leading spaces. +Handy to code big text blobs not intended for human reading. + + +```js +const assert = require('assert'); +const common = require('../common'); + +const unTagged = + '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + +const tagged = common.tagGlue` + 0123456789 + ABCDEFGHIJKLMNOPQRSTUVWXYZ + abcdefghijklmnopqrstuvwxyz +`; + +assert.strictEqual(unTagged, tagged); +``` + +### tagUnwrap() +* return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) + +Tag function for tagged template literals: +replaces all literal line breaks and leading spaces with a space, +then trims one leading and one trailing space. +Handy to code long readable text one-liners split for either readability +or to respect the 80 char rule. + + +```js +const assert = require('assert'); +const common = require('../common'); + +const unTagged = + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod...'; + +const tagged = common.tagUnwrap` + Lorem ipsum dolor sit amet, + consectetur adipiscing elit, + sed do eiusmod... +`; + +assert.strictEqual(unTagged, tagged); +``` + +### tagLFy() +* return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) + +Tag function for tagged template literals: +removes one framing line break from the start and the end +as well as auxiliary indents (based on the indent of the first text line). +Handy to code multiline readable text, JavaScript metacode, HTML markup. + + +```js +const assert = require('assert'); +const common = require('../common'); + +const unTagged = +` + + + + + + + ${process.versions} + +`; + +const tagged = common.tagLFy` + + + + + + + + ${process.versions} + + +`; + +assert.strictEqual(unTagged, tagged); +``` + +### tagCRLFy() +* return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) + +Tag function for tagged template literals: +same as `tagLFy()`, but replaces all literal `\n` by `\r\n`. +Handy to code raw HTTP requests/responses. + + +```js +const assert = require('assert'); +const common = require('../common'); + +const unTagged = + 'HTTP/1.1 200 OK\r\n' + + 'Content-Type: text/plain\r\n' + + 'Content-Length: ' + `${process.versions}`.length + '\r\n' + + '\r\n' + + process.versions; + +const tagged = common.tagCRLFy` + HTTP/1.1 200 OK + Content-Type: text/plain + Content-Length: ${`${process.versions}`.length} + + ${process.versions} +`; + +assert.strictEqual(unTagged, tagged); +``` + ### tmpDir * return [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) diff --git a/test/common/index.js b/test/common/index.js index cb8d333a289799..79567c947d29aa 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -211,9 +211,11 @@ Object.defineProperty(exports, 'localhostIPv4', { if (process.env.LOCALHOST) { localhostIPv4 = process.env.LOCALHOST; } else { - console.error('Looks like we\'re in a FreeBSD Jail. ' + - 'Please provide your default interface address ' + - 'as LOCALHOST or expect some tests to fail.'); + console.error(exports.tagUnwrap` + Looks like we're in a FreeBSD Jail. + Please provide your default interface address as LOCALHOST + or expect some tests to fail. + `); } } @@ -289,9 +291,10 @@ exports.childShouldThrowAndAbort = function() { testCmd += `"${process.argv[1]}" child`; const child = child_process.exec(testCmd); child.on('exit', function onExit(exitCode, signal) { - const errMsg = 'Test should have aborted ' + - `but instead exited with exit code ${exitCode}` + - ` and signal ${signal}`; + const errMsg = exports.tagUnwrap` + Test should have aborted + but instead exited with exit code ${exitCode} and signal ${signal} + `; assert(exports.nodeProcessAborted(exitCode, signal), errMsg); }); }; @@ -746,3 +749,49 @@ exports.getTTYfd = function getTTYfd() { } return tty_fd; }; + +// exports.tag*: tag functions for tagged template literals + +// Removes all literal line breaks and leading spaces +exports.tagGlue = function tagGlue(strings, ...expressions) { + const breaks = /\n */g; + + return expressions.reduce( + (acc, expr, i) => `${acc}${expr}${strings[i + 1].replace(breaks, '')}`, + strings[0].replace(breaks, '') + ); +}; + +// Replaces all literal line breaks and leading spaces with a space, +// then trims one leading and one trailing space +exports.tagUnwrap = function tagUnwrap(strings, ...expressions) { + const breaks = /(\n *)+/g; + + return expressions.reduce( + (acc, expr, i) => `${acc}${expr}${strings[i + 1].replace(breaks, ' ')}`, + strings[0].replace(breaks, ' ') + ).replace(/^ | $/g, ''); +}; + +// Removes one framing line break from the start and the end +// as well as auxiliary indents (based on the indent of the first text line) +exports.tagLFy = function tagLFy(strings, ...expressions) { + const [, firstIndent = ''] = strings[0].match(/\n+( *)/) || []; + const indent = new RegExp(`\n {0,${firstIndent.length}}`, 'g'); + + return expressions.reduce( + (acc, expr, i) => `${acc}${expr}${strings[i + 1].replace(indent, '\n')}`, + strings[0].replace(indent, '\n') + ).replace(/^\n|\n$/g, ''); +}; + +// Same as tagLFy(), but replaces all literal \n by \r\n +exports.tagCRLFy = function tagCRLFy(strings, ...expressions) { + const [, firstIndent = ''] = strings[0].match(/\n+( *)/) || []; + const indent = new RegExp(`\n {0,${firstIndent.length}}`, 'g'); + + return expressions.reduce( + (acc, expr, i) => `${acc}${expr}${strings[i + 1].replace(indent, '\r\n')}`, + strings[0].replace(indent, '\r\n') + ).replace(/^\r\n|\r\n$/g, ''); +}; diff --git a/test/doctool/test-doctool-html.js b/test/doctool/test-doctool-html.js index ba3e793e8a5aac..aa44e2e916e164 100644 --- a/test/doctool/test-doctool-html.js +++ b/test/doctool/test-doctool-html.js @@ -5,6 +5,8 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); +const { tagUnwrap } = common; + // The doctool currently uses js-yaml from the tool/eslint/ tree. try { require('../../tools/eslint/node_modules/js-yaml'); @@ -23,70 +25,133 @@ const html = require('../../tools/doc/html.js'); const testData = [ { file: path.join(common.fixturesDir, 'sample_document.md'), - html: '
  1. fish
  2. fish

  3. Redfish

  4. ' + - '
  5. Bluefish
' + html: tagUnwrap` +
    +
  1. fish
  2. +
  3. fish

  4. +
  5. Redfish

  6. +
  7. Bluefish
  8. +
+ ` }, { file: path.join(common.fixturesDir, 'order_of_end_tags_5873.md'), - html: '

ClassMethod: Buffer.from(array) ' + - '#

' + html: tagUnwrap` +

ClassMethod: Buffer.from(array) + # +

+
+ +
+ ` }, { file: path.join(common.fixturesDir, 'doc_with_yaml.md'), - html: '

Sample Markdown with YAML info' + - '#

' + - '

Foobar#

' + - '
Added in: v1.0.0
' + - '

Describe Foobar in more detail here.

' + - '

Foobar II#

' + - '
' + - '
History' + - '' + - '' + - '' + - '
VersionChanges
v5.3.0, v4.2.0

Added in: v5.3.0, v4.2.0

' + - '
v4.2.0

The error parameter can now be' + - 'an arrow function.

' + - '
' + - '

Describe Foobar II in more detail here.' + - 'fg(1)

' + - '

Deprecated thingy#' + - '

' + - '
Added in: v1.0.0' + - 'Deprecated since: v2.0.0

Describe ' + - 'Deprecated thingy in more detail here.' + - 'fg(1p)' + - '

' + - '

Something#

' + - ' ' + - '

Describe Something in more detail here. ' + - '

' + html: tagUnwrap` +

+ Sample Markdown with YAML info + # +

+

+ Foobar + # +

+
+ Added in: v1.0.0 +
+

+ Describe Foobar in more detail here. +

+

+ Foobar II + + # + +

+
+
+ History + + + + + + + + + + +
VersionChanges
v5.3.0, v4.2.0

Added in: v5.3.0, v4.2.0

v4.2.0

+ The error parameter can now be an arrow function. +

+
+
+

+ Describe Foobar II in more detail here. + fg(1) +

+

+ Deprecated thingy + + # + +

+
+ Added in: v1.0.0 + Deprecated since: v2.0.0 +
+

+ Describe Deprecated thingy in more detail here. + fg(1p) +

+

+ Something + + # + +

+ +

+ Describe Something in more detail here. +

+ ` }, { file: path.join(common.fixturesDir, 'doc_with_includes.md'), - html: '' + - '

Look here!

' + - '' + - '' + - '

foobar#

' + - '

I exist and am being linked to.

' + - '' + html: tagUnwrap` + +

Look here!

+ + +

+ foobar + + # + +

+

I exist and am being linked to.

+ + ` }, { file: path.join(common.fixturesDir, 'sample_document.md'), - html: '
  1. fish
  2. fish

  3. Redfish

  4. ' + - '
  5. Bluefish
', + html: tagUnwrap` +
    +
  1. fish
  2. +
  3. fish

  4. +
  5. Redfish

  6. +
  7. Bluefish
  8. +
+ `, analyticsId: 'UA-67020396-1' }, ]; diff --git a/test/internet/test-dgram-broadcast-multi-process.js b/test/internet/test-dgram-broadcast-multi-process.js index a79c05e18e1675..89ebff1618ad5c 100644 --- a/test/internet/test-dgram-broadcast-multi-process.js +++ b/test/internet/test-dgram-broadcast-multi-process.js @@ -131,9 +131,10 @@ if (process.argv[2] !== 'child') { } if (done === listeners) { - console.error('[PARENT] All workers have received the ' + - 'required number of ' + - 'messages. Will now compare.'); + console.error(common.tagUnwrap` + [PARENT] All workers have received + the required number of messages. Will now compare. + `); Object.keys(workers).forEach(function(pid) { const worker = workers[pid]; diff --git a/test/internet/test-dgram-multicast-multi-process.js b/test/internet/test-dgram-multicast-multi-process.js index dac8abd6a7a436..792250d6a89d3b 100644 --- a/test/internet/test-dgram-multicast-multi-process.js +++ b/test/internet/test-dgram-multicast-multi-process.js @@ -92,8 +92,10 @@ function launchChildProcess() { } if (done === listeners) { - console.error('[PARENT] All workers have received the ' + - 'required number of messages. Will now compare.'); + console.error(common.tagUnwrap` + [PARENT] All workers have received + the required number of messages. Will now compare. + `); Object.keys(workers).forEach(function(pid) { const worker = workers[pid]; diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index ca68a27a90fe7a..6ba194a5e92c44 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -7,6 +7,7 @@ const buffer = require('buffer'); const Buffer = buffer.Buffer; const SlowBuffer = buffer.SlowBuffer; +const { tagGlue, tagUnwrap } = common; const b = Buffer.allocUnsafe(1024); assert.strictEqual(1024, b.length); @@ -292,18 +293,22 @@ assert.strictEqual('TWFu', (Buffer.from('Man')).toString('base64')); { // big example - const quote = 'Man is distinguished, not only by his reason, but by this ' + - 'singular passion from other animals, which is a lust ' + - 'of the mind, that by a perseverance of delight in the ' + - 'continued and indefatigable generation of knowledge, ' + - 'exceeds the short vehemence of any carnal pleasure.'; - const expected = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb' + - '24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlci' + - 'BhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQ' + - 'gYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu' + - 'dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZ' + - 'GdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm' + - '5hbCBwbGVhc3VyZS4='; + const quote = tagUnwrap` + Man is distinguished, not only by his reason, but by this + singular passion from other animals, which is a lust + of the mind, that by a perseverance of delight in the + continued and indefatigable generation of knowledge, + exceeds the short vehemence of any carnal pleasure. + `; + const expected = tagGlue` + TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb + 24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlci + BhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQ + gYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu + dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZ + GdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm + 5hbCBwbGVhc3VyZS4= + `; assert.strictEqual(expected, (Buffer.from(quote)).toString('base64')); let b = Buffer.allocUnsafe(1024); @@ -490,23 +495,24 @@ assert.deepStrictEqual(Buffer.from('w0 ', 'base64'), hexb[i] = i; } const hexStr = hexb.toString('hex'); - assert.strictEqual(hexStr, - '000102030405060708090a0b0c0d0e0f' + - '101112131415161718191a1b1c1d1e1f' + - '202122232425262728292a2b2c2d2e2f' + - '303132333435363738393a3b3c3d3e3f' + - '404142434445464748494a4b4c4d4e4f' + - '505152535455565758595a5b5c5d5e5f' + - '606162636465666768696a6b6c6d6e6f' + - '707172737475767778797a7b7c7d7e7f' + - '808182838485868788898a8b8c8d8e8f' + - '909192939495969798999a9b9c9d9e9f' + - 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf' + - 'b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' + - 'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + - 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' + - 'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + - 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'); + assert.strictEqual(hexStr, tagGlue` + 000102030405060708090a0b0c0d0e0f + 101112131415161718191a1b1c1d1e1f + 202122232425262728292a2b2c2d2e2f + 303132333435363738393a3b3c3d3e3f + 404142434445464748494a4b4c4d4e4f + 505152535455565758595a5b5c5d5e5f + 606162636465666768696a6b6c6d6e6f + 707172737475767778797a7b7c7d7e7f + 808182838485868788898a8b8c8d8e8f + 909192939495969798999a9b9c9d9e9f + a0a1a2a3a4a5a6a7a8a9aaabacadaeaf + b0b1b2b3b4b5b6b7b8b9babbbcbdbebf + c0c1c2c3c4c5c6c7c8c9cacbcccdcecf + d0d1d2d3d4d5d6d7d8d9dadbdcdddedf + e0e1e2e3e4e5e6e7e8e9eaebecedeeef + f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff + `); const hexb2 = Buffer.from(hexStr, 'hex'); for (let i = 0; i < 256; i++) { diff --git a/test/parallel/test-buffer-ascii.js b/test/parallel/test-buffer-ascii.js index afedb7252cb8dc..a33862a433c2bf 100644 --- a/test/parallel/test-buffer-ascii.js +++ b/test/parallel/test-buffer-ascii.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagUnwrap } = require('../common'); const assert = require('assert'); // ASCII conversion in node.js simply masks off the high bits, @@ -28,12 +28,17 @@ const assert = require('assert'); assert.strictEqual(Buffer.from('hérité').toString('ascii'), 'hC)ritC)'); // 71 characters, 78 bytes. The ’ character is a triple-byte sequence. -const input = 'C’est, graphiquement, la réunion d’un accent aigu ' + - 'et d’un accent grave.'; +const input = tagUnwrap` + C’est, graphiquement, + la réunion d’un accent aigu + et d’un accent grave. +`; -const expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' + - 'db\u0000\u0019un accent aigu et db\u0000\u0019un ' + - 'accent grave.'; +const expected = tagUnwrap` + Cb\u0000\u0019est, graphiquement, + la rC)union db\u0000\u0019un accent aigu + et db\u0000\u0019un accent grave. +`; const buf = Buffer.from(input); diff --git a/test/parallel/test-buffer-pending-deprecation.js b/test/parallel/test-buffer-pending-deprecation.js index e8aabc49fe0bda..bfa0e9694e10cd 100644 --- a/test/parallel/test-buffer-pending-deprecation.js +++ b/test/parallel/test-buffer-pending-deprecation.js @@ -4,11 +4,11 @@ const common = require('../common'); const Buffer = require('buffer').Buffer; -const bufferWarning = 'The Buffer() and new Buffer() constructors are not ' + - 'recommended for use due to security and usability ' + - 'concerns. Please use the new Buffer.alloc(), ' + - 'Buffer.allocUnsafe(), or Buffer.from() construction ' + - 'methods instead.'; +const bufferWarning = common.tagUnwrap` + The Buffer() and new Buffer() constructors are not recommended for use + due to security and usability concerns. Please use the new Buffer.alloc(), + Buffer.allocUnsafe(), or Buffer.from() construction methods instead. +`; common.expectWarning('DeprecationWarning', bufferWarning); diff --git a/test/parallel/test-cluster-worker-isconnected.js b/test/parallel/test-cluster-worker-isconnected.js index 8b2ad865899c60..a07fb11d343baf 100644 --- a/test/parallel/test-cluster-worker-isconnected.js +++ b/test/parallel/test-cluster-worker-isconnected.js @@ -1,19 +1,21 @@ 'use strict'; -require('../common'); +const { tagUnwrap } = require('../common'); const cluster = require('cluster'); const assert = require('assert'); if (cluster.isMaster) { const worker = cluster.fork(); - assert.ok(worker.isConnected(), - 'isConnected() should return true as soon as the worker has ' + - 'been created.'); + assert.ok(worker.isConnected(), tagUnwrap` + isConnected() should return true + as soon as the worker has been created. + `); worker.on('disconnect', function() { - assert.ok(!worker.isConnected(), - 'After a disconnect event has been emitted, ' + - 'isConncted should return false'); + assert.ok(!worker.isConnected(), tagUnwrap` + After a disconnect event has been emitted + isConncted should return false + `); }); worker.on('message', function(msg) { @@ -23,15 +25,17 @@ if (cluster.isMaster) { }); } else { - assert.ok(cluster.worker.isConnected(), - 'isConnected() should return true from within a worker at all ' + - 'times.'); + assert.ok(cluster.worker.isConnected(), tagUnwrap` + isConnected() should return true + from within a worker at all times. + `); cluster.worker.process.on('disconnect', function() { - assert.ok(!cluster.worker.isConnected(), - 'isConnected() should return false from within a worker ' + - 'after its underlying process has been disconnected from ' + - 'the master'); + assert.ok(!cluster.worker.isConnected(), tagUnwrap` + isConnected() should return false from within a worker + after its underlying process has been disconnected + from the master + `); }); process.send('readyToDisconnect'); diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index 2bda20acd94852..2939b4c6d033bb 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -47,3 +47,81 @@ assert.throws( code: 'ERR_ASSERTION', message: /^fhqwhgads$/ })); + +// common.tag*: tag functions for tagged template literals + +const { tagGlue, tagUnwrap, tagLFy, tagCRLFy } = common; + +{ + const unTagged = + '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + + const tagged = tagGlue` + 0123456789 + ABCDEFGHIJKLMNOPQRSTUVWXYZ + abcdefghijklmnopqrstuvwxyz + `; + + assert.strictEqual(unTagged, tagged); +} + +{ + const unTagged = + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod...'; + + const tagged = tagUnwrap` + Lorem ipsum dolor sit amet, + consectetur adipiscing elit, + sed do eiusmod... + `; + + assert.strictEqual(unTagged, tagged); +} + +{ + const unTagged = +` + + + + + + + ${process.versions} + +`; + + const tagged = tagLFy` + + + + + + + + ${process.versions} + + + `; + + assert.strictEqual(unTagged, tagged); +} + +{ + const unTagged = + 'HTTP/1.1 200 OK\r\n' + + 'Content-Type: text/plain\r\n' + + 'Content-Length: ' + `${process.versions}`.length + '\r\n' + + '\r\n' + + process.versions; + + const tagged = tagCRLFy` + HTTP/1.1 200 OK + Content-Type: text/plain + Content-Length: ${`${process.versions}`.length} + + ${process.versions} + `; + + assert.strictEqual(unTagged, tagged); +} diff --git a/test/parallel/test-crypto-authenticated.js b/test/parallel/test-crypto-authenticated.js index c1d70efa5f6d1b..f47c7bd27daa70 100644 --- a/test/parallel/test-crypto-authenticated.js +++ b/test/parallel/test-crypto-authenticated.js @@ -23,6 +23,8 @@ const common = require('../common'); const assert = require('assert'); +const { tagGlue } = common; + if (!common.hasCrypto) { common.skip('missing crypto'); return; @@ -96,67 +98,66 @@ const TEST_CASES = [ { algo: 'aes-128-gcm', key: 'feffe9928665731c6d6a8f9467308308', iv: 'cafebabefacedbaddecaf888', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a721' + - 'c3c0c95956809532fcf0e2449a6b525b1' + - '6aedf5aa0de657ba637b391aafd255', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b391aafd255`, plainIsHex: true, - ct: '42831ec2217774244b7221b784d0d49c' + - 'e3aa212f2c02a4e035c17e2329aca12e2' + - '1d514b25466931c7d8f6a5aac84aa051b' + - 'a30b396a0aac973d58e091473f5985', + ct: tagGlue`42831ec2217774244b7221b784d0d49c + e3aa212f2c02a4e035c17e2329aca12e + 21d514b25466931c7d8f6a5aac84aa05 + 1ba30b396a0aac973d58e091473f5985`, tag: '4d5c2af327cd64a62cf35abd2ba6fab4', tampered: false }, // Test case 4 { algo: 'aes-128-gcm', key: 'feffe9928665731c6d6a8f9467308308', iv: 'cafebabefacedbaddecaf888', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a721' + - 'c3c0c95956809532fcf0e2449a6b525b16' + - 'aedf5aa0de657ba637b39', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a721 + c3c0c95956809532fcf0e2449a6b525b16 + aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: '42831ec2217774244b7221b784d0d49c' + - 'e3aa212f2c02a4e035c17e2329aca12e2' + - '1d514b25466931c7d8f6a5aac84aa051b' + - 'a30b396a0aac973d58e091', + ct: tagGlue`42831ec2217774244b7221b784d0d49c + e3aa212f2c02a4e035c17e2329aca12e2 + 1d514b25466931c7d8f6a5aac84aa051b + a30b396a0aac973d58e091`, tag: '5bc94fbc3221a5db94fae95ae7121a47', tampered: false }, // Test case 5, 8 byte IV { algo: 'aes-128-gcm', key: 'feffe9928665731c6d6a8f9467308308', iv: 'cafebabefacedbad', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', - aad: 'feedfacedeadbeeffeedfacedeadbeef' + - 'abaddad2', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, + aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: '61353b4c2806934a777ff51fa22a4755' + - '699b2a714fcdc6f83766e5f97b6c7423' + - '73806900e49f24b22b097544d4896b42' + - '4989b5e1ebac0f07c23f4598', + ct: tagGlue`61353b4c2806934a777ff51fa22a4755 + 699b2a714fcdc6f83766e5f97b6c7423 + 73806900e49f24b22b097544d4896b42 + 4989b5e1ebac0f07c23f4598`, tag: '3612d2e79e3b0785561be14aaca2fccb', tampered: false }, // Test case 6, 60 byte IV { algo: 'aes-128-gcm', key: 'feffe9928665731c6d6a8f9467308308', - iv: '9313225DF88406E555909C5AFF5269AA' + - '6A7A9538534F7DA1E4C303D2A318A728' + - 'C3C0C95156809539FCF0E2429A6B52541' + - '6AEDBF5A0DE6A57A637B39B', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', + iv: tagGlue`9313225DF88406E555909C5AFF5269AA + 6A7A9538534F7DA1E4C303D2A318A728 + C3C0C95156809539FCF0E2429A6B52541 + 6AEDBF5A0DE6A57A637B39B`, + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: '8ce24998625615b603a033aca13fb894' + - 'be9112a5c3a211a8ba262a3cca7e2ca7' + - '01e4a9a4fba43c90ccdcb281d48c7c6f' + - 'd62875d2aca417034c34aee5', + ct: tagGlue`8ce24998625615b603a033aca13fb894 + be9112a5c3a211a8ba262a3cca7e2ca7 + 01e4a9a4fba43c90ccdcb281d48c7c6f + d62875d2aca417034c34aee5`, tag: '619cc5aefffe0bfa462af43c1699d050', tampered: false }, // Test case 7 @@ -181,66 +182,66 @@ const TEST_CASES = [ { algo: 'aes-192-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c', iv: 'cafebabefacedbaddecaf888', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b391aafd255', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b391aafd255`, plainIsHex: true, - ct: '3980ca0b3c00e841eb06fac4872a2757' + - '859e1ceaa6efd984628593b40ca1e19c' + - '7d773d00c144c525ac619d18c84a3f47' + - '18e2448b2fe324d9ccda2710acade256', + ct: tagGlue`3980ca0b3c00e841eb06fac4872a2757 + 859e1ceaa6efd984628593b40ca1e19c + 7d773d00c144c525ac619d18c84a3f47 + 18e2448b2fe324d9ccda2710acade256`, tag: '9924a7c8587336bfb118024db8674a14', tampered: false }, // Test case 10 { algo: 'aes-192-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c', iv: 'cafebabefacedbaddecaf888', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: '3980ca0b3c00e841eb06fac4872a2757' + - '859e1ceaa6efd984628593b40ca1e19c' + - '7d773d00c144c525ac619d18c84a3f47' + - '18e2448b2fe324d9ccda2710', + ct: tagGlue`3980ca0b3c00e841eb06fac4872a2757 + 859e1ceaa6efd984628593b40ca1e19c + 7d773d00c144c525ac619d18c84a3f47 + 18e2448b2fe324d9ccda2710`, tag: '2519498e80f1478f37ba55bd6d27618c', tampered: false }, // Test case 11 { algo: 'aes-192-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c', iv: 'cafebabefacedbad', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: '0f10f599ae14a154ed24b36e25324db8' + - 'c566632ef2bbb34f8347280fc4507057' + - 'fddc29df9a471f75c66541d4d4dad1c9' + - 'e93a19a58e8b473fa0f062f7', + ct: tagGlue`0f10f599ae14a154ed24b36e25324db8 + c566632ef2bbb34f8347280fc4507057 + fddc29df9a471f75c66541d4d4dad1c9 + e93a19a58e8b473fa0f062f7`, tag: '65dcc57fcf623a24094fcca40d3533f8', tampered: false }, // Test case 12, 60 byte IV { algo: 'aes-192-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c', - iv: '9313225df88406e555909c5aff5269aa' + - '6a7a9538534f7da1e4c303d2a318a728' + - 'c3c0c95156809539fcf0e2429a6b5254' + - '16aedbf5a0de6a57a637b39b', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', + iv: tagGlue`9313225df88406e555909c5aff5269aa + 6a7a9538534f7da1e4c303d2a318a728 + c3c0c95156809539fcf0e2429a6b5254 + 16aedbf5a0de6a57a637b39b`, + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: 'd27e88681ce3243c4830165a8fdcf9ff' + - '1de9a1d8e6b447ef6ef7b79828666e45' + - '81e79012af34ddd9e2f037589b292db3' + - 'e67c036745fa22e7e9b7373b', + ct: tagGlue`d27e88681ce3243c4830165a8fdcf9ff + 1de9a1d8e6b447ef6ef7b79828666e45 + 81e79012af34ddd9e2f037589b292db3 + e67c036745fa22e7e9b7373b`, tag: 'dcf566ff291c25bbb8568fc3d376a6d9', tampered: false }, // Test case 13 @@ -265,66 +266,66 @@ const TEST_CASES = [ { algo: 'aes-256-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308', iv: 'cafebabefacedbaddecaf888', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b391aafd255', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b391aafd255`, plainIsHex: true, - ct: '522dc1f099567d07f47f37a32a84427d' + - '643a8cdcbfe5c0c97598a2bd2555d1aa' + - '8cb08e48590dbb3da7b08b1056828838' + - 'c5f61e6393ba7a0abcc9f662898015ad', + ct: tagGlue`522dc1f099567d07f47f37a32a84427d + 643a8cdcbfe5c0c97598a2bd2555d1aa + 8cb08e48590dbb3da7b08b1056828838 + c5f61e6393ba7a0abcc9f662898015ad`, tag: 'b094dac5d93471bdec1a502270e3cc6c', tampered: false }, // Test case 16 { algo: 'aes-256-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308', iv: 'cafebabefacedbaddecaf888', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: '522dc1f099567d07f47f37a32a84427d' + - '643a8cdcbfe5c0c97598a2bd2555d1aa' + - '8cb08e48590dbb3da7b08b1056828838' + - 'c5f61e6393ba7a0abcc9f662', + ct: tagGlue`522dc1f099567d07f47f37a32a84427d + 643a8cdcbfe5c0c97598a2bd2555d1aa + 8cb08e48590dbb3da7b08b1056828838 + c5f61e6393ba7a0abcc9f662`, tag: '76fc6ece0f4e1768cddf8853bb2d551b', tampered: false }, // Test case 17, 8 byte IV { algo: 'aes-256-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308', iv: 'cafebabefacedbad', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: 'c3762df1ca787d32ae47c13bf19844cb' + - 'af1ae14d0b976afac52ff7d79bba9de0' + - 'feb582d33934a4f0954cc2363bc73f78' + - '62ac430e64abe499f47c9b1f', + ct: tagGlue`c3762df1ca787d32ae47c13bf19844cb + af1ae14d0b976afac52ff7d79bba9de0 + feb582d33934a4f0954cc2363bc73f78 + 62ac430e64abe499f47c9b1f`, tag: '3a337dbf46a792c45e454913fe2ea8f2', tampered: false }, // Test case 18, 60 byte IV { algo: 'aes-256-gcm', key: 'feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308', - iv: '9313225df88406e555909c5aff5269aa' + - '6a7a9538534f7da1e4c303d2a318a728' + - 'c3c0c95156809539fcf0e2429a6b5254' + - '16aedbf5a0de6a57a637b39b', - plain: 'd9313225f88406e5a55909c5aff5269a' + - '86a7a9531534f7da2e4c303d8a318a72' + - '1c3c0c95956809532fcf0e2449a6b525' + - 'b16aedf5aa0de657ba637b39', + iv: tagGlue`9313225df88406e555909c5aff5269aa + 6a7a9538534f7da1e4c303d2a318a728 + c3c0c95156809539fcf0e2429a6b5254 + 16aedbf5a0de6a57a637b39b`, + plain: tagGlue`d9313225f88406e5a55909c5aff5269a + 86a7a9531534f7da2e4c303d8a318a72 + 1c3c0c95956809532fcf0e2449a6b525 + b16aedf5aa0de657ba637b39`, aad: 'feedfacedeadbeeffeedfacedeadbeefabaddad2', plainIsHex: true, - ct: '5a8def2f0c9e53f1f75d7853659e2a20' + - 'eeb2b22aafde6419a058ab4f6f746bf4' + - '0fc0c3b780f244452da3ebf1c5d82cde' + - 'a2418997200ef82e44ae7e3f', + ct: tagGlue`5a8def2f0c9e53f1f75d7853659e2a20 + eeb2b22aafde6419a058ab4f6f746bf4 + 0fc0c3b780f244452da3ebf1c5d82cde + a2418997200ef82e44ae7e3f`, tag: 'a44a8266ee1c8eb0c8b5d4cf5ae9f19a', tampered: false }, ]; diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js index e92f70035bde78..f21169daa73276 100644 --- a/test/parallel/test-crypto-binary-default.js +++ b/test/parallel/test-crypto-binary-default.js @@ -26,6 +26,8 @@ const common = require('../common'); +const { tagGlue, tagUnwrap } = common; + if (!common.hasCrypto) { common.skip('missing crypto'); return; @@ -80,72 +82,61 @@ const rfc4231 = [ hmac: { sha224: '896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22', sha256: - 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c' + - '2e32cff7', - sha384: - 'afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c' + - '7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6', - sha512: - '87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b305' + - '45e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f170' + - '2e696c203a126854' + 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7', + sha384: tagGlue`afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c + 7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6`, + sha512: tagGlue`87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b305 + 45e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f170 + 2e696c203a126854` } }, { key: Buffer.from('4a656665', 'hex'), // 'Jefe' - data: Buffer.from('7768617420646f2079612077616e7420666f72206e6f74686' + - '96e673f', 'hex'), // 'what do ya want for nothing?' + data: Buffer.from( + '7768617420646f2079612077616e7420666f72206e6f7468696e673f', + 'hex'), // 'what do ya want for nothing?' hmac: { sha224: 'a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', sha256: - '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b9' + - '64ec3843', - sha384: - 'af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec373' + - '6322445e8e2240ca5e69e2c78b3239ecfab21649', - sha512: - '164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7' + - 'ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b' + - '636e070a38bce737' + '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843', + sha384: tagGlue`af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec373 + 6322445e8e2240ca5e69e2c78b3239ecfab21649`, + sha512: tagGlue`164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7 + ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b + 636e070a38bce737` } }, { key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: Buffer.from('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), + data: Buffer.from( + tagGlue`dddddddddddddddddddddddddddddddddddddddddddddddddd + dddddddddddddddddddddddddddddddddddddddddddddddddd`, 'hex'), hmac: { sha224: '7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea', sha256: - '773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514' + - 'ced565fe', - sha384: - '88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e5' + - '5966144b2a5ab39dc13814b94e3ab6e101a34f27', - sha512: - 'fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33' + - 'b2279d39bf3e848279a722c806b485a47e67c807b946a337bee89426' + - '74278859e13292fb' + '773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe', + sha384: tagGlue`88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e5 + 5966144b2a5ab39dc13814b94e3ab6e101a34f27`, + sha512: tagGlue`fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33 + b2279d39bf3e848279a722c806b485a47e67c807b946a337bee89426 + 74278859e13292fb` } }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), - data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', - 'hex'), + data: Buffer.from( + tagGlue`cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd + cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd`, 'hex'), hmac: { sha224: '6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a', sha256: - '82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff4' + - '6729665b', - sha384: - '3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e' + - '1f573b4e6801dd23c4a7d679ccf8a386c674cffb', - sha512: - 'b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050' + - '361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2d' + - 'e2adebeb10a298dd' + '82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b', + sha384: tagGlue`3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e + 1f573b4e6801dd23c4a7d679ccf8a386c674cffb`, + sha512: tagGlue`b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050 + 361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2d + e2adebeb10a298dd` } }, @@ -162,59 +153,53 @@ const rfc4231 = [ truncate: true }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaa`, 'hex'), // 'Test Using Larger Than Block-Size Key - Hash Key First' - data: Buffer.from('54657374205573696e67204c6172676572205468616e20426' + - 'c6f636b2d53697a65204b6579202d2048617368204b657920' + - '4669727374', 'hex'), + data: Buffer.from(tagGlue`54657374205573696e67204c6172676572205468616e20426 + c6f636b2d53697a65204b6579202d2048617368204b657920 + 4669727374`, 'hex'), hmac: { sha224: '95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e', sha256: - '60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f' + - '0ee37f54', - sha384: - '4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05' + - '033ac4c60c2ef6ab4030fe8296248df163f44952', - sha512: - '80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b0137' + - '83f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec' + - '8b915a985d786598' + '60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54', + sha384: tagGlue`4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05 + 033ac4c60c2ef6ab4030fe8296248df163f44952`, + sha512: tagGlue`80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b0137 + 83f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec + 8b915a985d786598` } }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaa`, 'hex'), // 'This is a test using a larger than block-size key and a larger ' + // 'than block-size data. The key needs to be hashed before being ' + // 'used by the HMAC algorithm.' - data: Buffer.from('5468697320697320612074657374207573696e672061206c6' + - '172676572207468616e20626c6f636b2d73697a65206b6579' + - '20616e642061206c6172676572207468616e20626c6f636b2' + - 'd73697a6520646174612e20546865206b6579206e65656473' + - '20746f20626520686173686564206265666f7265206265696' + - 'e6720757365642062792074686520484d414320616c676f72' + - '6974686d2e', 'hex'), + data: Buffer.from(tagGlue`5468697320697320612074657374207573696e672061206c6 + 172676572207468616e20626c6f636b2d73697a65206b6579 + 20616e642061206c6172676572207468616e20626c6f636b2 + d73697a6520646174612e20546865206b6579206e65656473 + 20746f20626520686173686564206265666f7265206265696 + e6720757365642062792074686520484d414320616c676f72 + 6974686d2e`, 'hex'), hmac: { sha224: '3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1', sha256: - '9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f5153' + - '5c3a35e2', - sha384: - '6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82' + - '461e99c5a678cc31e799176d3860e6110c46523e', - sha512: - 'e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d' + - '20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de04460' + - '65c97440fa8c6a58' + '9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2', + sha384: tagGlue`6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82 + 461e99c5a678cc31e799176d3860e6110c46523e`, + sha512: tagGlue`e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d + 20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de04460 + 65c97440fa8c6a58` } } ]; @@ -249,18 +234,17 @@ const rfc2202_md5 = [ }, { key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: Buffer.from('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), + data: Buffer.from( + tagGlue`dddddddddddddddddddddddddddddddddddddddddddddddddd + dddddddddddddddddddddddddddddddddddddddddddddddddd`, 'hex'), hmac: '56be34521d144c88dbb8c733f0e8b3f6' }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), - data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), + data: Buffer.from( + tagGlue`cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd + cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd`, 'hex'), hmac: '697eaf0aca3a3aea3a75164746ffaa79' }, { @@ -269,23 +253,20 @@ const rfc2202_md5 = [ hmac: '56461ef2342edc00f9bab995690efd4c' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), data: 'Test Using Larger Than Block-Size Key - Hash Key First', hmac: '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), + data: tagUnwrap`Test Using Larger Than Block-Size Key + and Larger Than One Block-Size Data`, hmac: '6f630fad67cda0ee1fb1f562db3aa53e' } ]; @@ -302,19 +283,17 @@ const rfc2202_sha1 = [ }, { key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: Buffer.from('ddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddd' + - 'dddddddddd', - 'hex'), + data: Buffer.from(tagGlue`ddddddddddddddddddddddddddddddddddddddddddddd + ddddddddddddddddddddddddddddddddddddddddddddd + dddddddddd`, 'hex'), hmac: '125d7342b9ac11cd91a39af48aa17b4f63f175d3' }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), - data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), + data: Buffer.from(tagGlue`cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc + dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd + cdcdcdcdcd`, 'hex'), hmac: '4c9007f4026250c6bc8414f9bf50c86c2d7235da' }, { @@ -323,23 +302,20 @@ const rfc2202_sha1 = [ hmac: '4c1a03424b55e07fe7f27be1d58bb9324a9a5a04' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), data: 'Test Using Larger Than Block-Size Key - Hash Key First', hmac: 'aa4ae5e15272d00e95705637ce8a3b55ed402112' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), + data: tagUnwrap`Test Using Larger Than Block-Size Key + and Larger Than One Block-Size Data`, hmac: 'e8e99d0f45237d786d6bbaa7965c7808bbff1a91' } ]; @@ -387,11 +363,11 @@ assert.strictEqual(a2, '2bX1jws4GYKTlxhloUB09Z66PoJZW+y+hq5R8dnx9l4=', assert.strictEqual( a3, - '\u00c1(4\u00f1\u0003\u001fd\u0097!O\'\u00d4C/&Qz\u00d4' + - '\u0094\u0015l\u00b8\u008dQ+\u00db\u001d\u00c4\u00b5}\u00b2' + - '\u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b\n\n*\u000f' + - '\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' + - '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', + tagGlue`\u00c1(4\u00f1\u0003\u001fd\u0097!O'\u00d4C/&Qz\u00d4 + \u0094\u0015l\u00b8\u008dQ+\u00db\u001d\u00c4\u00b5}\u00b2 + \u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b${'\n\n'}*\u000f + \u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093 + \u00c2\u0006\u00da0\u00a1\u00879(G\u00ed'`, 'Test SHA512 as assumed latin1' ); @@ -477,10 +453,10 @@ function testCipher1(key) { function testCipher2(key) { // encryption and decryption with Base64 // reported in https://github.com/joyent/node/issues/738 - const plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; + const plaintext = tagGlue` + 32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELweCBs + ThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg** + `; const cipher = crypto.createCipher('aes256', key); // encrypt plaintext which is in utf8 format @@ -498,10 +474,10 @@ function testCipher2(key) { function testCipher3(key, iv) { // Test encryption and decryption with explicit key and iv - const plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; + const plaintext = tagGlue` + 32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELweCBs + ThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg** + `; const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); let ciph = cipher.update(plaintext, 'utf8', 'hex'); ciph += cipher.final('hex'); @@ -517,10 +493,10 @@ function testCipher3(key, iv) { function testCipher4(key, iv) { // Test encryption and decryption with explicit key and iv - const plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; + const plaintext = tagGlue` + 32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELweCBs + ThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg** + `; const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); let ciph = cipher.update(plaintext, 'utf8', 'buffer'); ciph = Buffer.concat([ciph, cipher.final('buffer')]); @@ -584,10 +560,12 @@ const secret3 = dh3.computeSecret(key2, 'hex', 'base64'); assert.strictEqual(secret1, secret3); // https://github.com/joyent/node/issues/2338 -const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + - '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + - '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + - 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; +const p = tagGlue` + FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74 + 020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437 + 4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED + EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF +`; const d = crypto.createDiffieHellman(p, 'hex'); assert.strictEqual(d.verifyError, DH_NOT_SUITABLE_GENERATOR); @@ -601,12 +579,13 @@ rsaSign.update(rsaPubPem); const rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); assert.strictEqual( rsaSignature, - '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + - '8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8' + - 'e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f' + - '60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f' + - '40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6' -); + tagGlue` + 5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c + 8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8 + e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f + 60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f + 40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6 + `); rsaVerify.update(rsaPubPem); assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); @@ -622,12 +601,13 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); const input = 'I AM THE WALRUS'; - const signature = - '79d59d34f56d0e94aa6a3e306882b52ed4191f07521f25f505a078dc2f89' + - '396e0c8ac89e996fde5717f4cb89199d8fec249961fcb07b74cd3d2a4ffa' + - '235417b69618e4bcd76b97e29975b7ce862299410e1b522a328e44ac9bb2' + - '8195e0268da7eda23d9825ac43c724e86ceeee0d0d4465678652ccaf6501' + - '0ddfb299bedeb1ad'; + const signature = tagGlue` + 79d59d34f56d0e94aa6a3e306882b52ed4191f07521f25f505a078dc2f89 + 396e0c8ac89e996fde5717f4cb89199d8fec249961fcb07b74cd3d2a4ffa + 235417b69618e4bcd76b97e29975b7ce862299410e1b522a328e44ac9bb2 + 8195e0268da7eda23d9825ac43c724e86ceeee0d0d4465678652ccaf6501 + 0ddfb299bedeb1ad + `; const sign = crypto.createSign('RSA-SHA256'); sign.update(input); @@ -681,24 +661,24 @@ function testPBKDF2(password, salt, iterations, keylen, expected) { testPBKDF2('password', 'salt', 1, 20, - '\x12\x0f\xb6\xcf\xfc\xf8\xb3\x2c\x43\xe7\x22\x52' + - '\x56\xc4\xf8\x37\xa8\x65\x48\xc9'); + tagGlue`\x12\x0f\xb6\xcf\xfc\xf8\xb3\x2c\x43\xe7 + \x22\x52\x56\xc4\xf8\x37\xa8\x65\x48\xc9`); testPBKDF2('password', 'salt', 2, 20, - '\xae\x4d\x0c\x95\xaf\x6b\x46\xd3\x2d\x0a\xdf\xf9' + - '\x28\xf0\x6d\xd0\x2a\x30\x3f\x8e'); + tagGlue`\xae\x4d\x0c\x95\xaf\x6b\x46\xd3\x2d${'\x0a'} + \xdf\xf9\x28\xf0\x6d\xd0\x2a\x30\x3f\x8e`); testPBKDF2('password', 'salt', 4096, 20, - '\xc5\xe4\x78\xd5\x92\x88\xc8\x41\xaa\x53\x0d\xb6' + - '\x84\x5c\x4c\x8d\x96\x28\x93\xa0'); + tagGlue`\xc5\xe4\x78\xd5\x92\x88\xc8\x41\xaa\x53 + \x0d\xb6\x84\x5c\x4c\x8d\x96\x28\x93\xa0`); testPBKDF2('passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 25, - '\x34\x8c\x89\xdb\xcb\xd3\x2b\x2f\x32\xd8\x14\xb8' + - '\x11\x6e\x84\xcf\x2b\x17\x34\x7e\xbc\x18\x00\x18\x1c'); + tagGlue`\x34\x8c\x89\xdb\xcb\xd3\x2b\x2f\x32\xd8\x14\xb8 + \x11\x6e\x84\xcf\x2b\x17\x34\x7e\xbc\x18\x00\x18\x1c`); testPBKDF2('pass\0word', 'sa\0lt', 4096, 16, - '\x89\xb6\x9d\x05\x16\xf8\x29\x89\x3c\x69\x62\x26' + - '\x65\x0a\x86\x87'); + tagGlue`\x89\xb6\x9d\x05\x16\xf8\x29\x89 + \x3c\x69\x62\x26\x65${'\x0a'}\x86\x87`); diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js index dfb68a7f920844..fdccd0111079f0 100644 --- a/test/parallel/test-crypto-cipher-decipher.js +++ b/test/parallel/test-crypto-cipher-decipher.js @@ -48,10 +48,10 @@ function testCipher1(key) { function testCipher2(key) { // encryption and decryption with Base64 // reported in https://github.com/joyent/node/issues/738 - const plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; + const plaintext = common.tagGlue` + 32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELweCBs + ThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg** + `; const cipher = crypto.createCipher('aes256', key); // encrypt plaintext which is in utf8 format diff --git a/test/parallel/test-crypto-cipheriv-decipheriv.js b/test/parallel/test-crypto-cipheriv-decipheriv.js index a03a25d511fe16..a74c0261c12e9d 100644 --- a/test/parallel/test-crypto-cipheriv-decipheriv.js +++ b/test/parallel/test-crypto-cipheriv-decipheriv.js @@ -8,12 +8,14 @@ if (!common.hasCrypto) { } const crypto = require('crypto'); +const { tagGlue } = common; + function testCipher1(key, iv) { // Test encryption and decryption with explicit key and iv - const plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; + const plaintext = tagGlue` + 32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELweCBs + ThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg** + `; const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); let ciph = cipher.update(plaintext, 'utf8', 'hex'); ciph += cipher.final('hex'); @@ -42,10 +44,10 @@ function testCipher1(key, iv) { function testCipher2(key, iv) { // Test encryption and decryption with explicit key and iv - const plaintext = - '32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELw' + - 'eCBsThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJ' + - 'jAfaFg**'; + const plaintext = tagGlue` + 32|RmVZZkFUVmpRRkp0TmJaUm56ZU9qcnJkaXNNWVNpTTU*|iXmckfRWZBGWWELweCBs + ThSsfUHLeRe0KCsK8ooHgxie0zOINpXxfZi/oNG7uq9JWFVCk70gfzQH8ZUJjAfaFg** + `; const cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); let ciph = cipher.update(plaintext, 'utf8', 'buffer'); ciph = Buffer.concat([ciph, cipher.final('buffer')]); diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index fed392cd9f0ba3..a18801197ea426 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -9,6 +9,8 @@ if (!common.hasCrypto) { const crypto = require('crypto'); const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR; +const { tagGlue } = common; + // Test Diffie-Hellman with two parties sharing a secret, // using various encodings as we go along const dh1 = crypto.createDiffieHellman(common.hasFipsCrypto ? 1024 : 256); @@ -163,10 +165,12 @@ for (const buf of [modp2buf, ...common.getArrayBufferViews(modp2buf)]) { } -const p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' + - '020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437' + - '4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED' + - 'EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF'; +const p = tagGlue` + FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74 + 020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F1437 + 4FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED + EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF +`; const bad_dh = crypto.createDiffieHellman(p, 'hex'); assert.strictEqual(bad_dh.verifyError, DH_NOT_SUITABLE_GENERATOR); @@ -237,9 +241,10 @@ if (availableCurves.has('prime256v1') && availableCurves.has('secp256k1')) { // Associated compressed and uncompressed public keys (points). const cafebabePubPtComp = '03672a31bfc59d3f04548ec9b7daeeba2f61814e8ccc40448045007f5479f693a3'; - const cafebabePubPtUnComp = - '04672a31bfc59d3f04548ec9b7daeeba2f61814e8ccc40448045007f5479f693a3' + - '2e02c7f93d13dc2732b760ca377a5897b9dd41a1c1b29dc0442fdce6d0a04d1d'; + const cafebabePubPtUnComp = tagGlue` + 04672a31bfc59d3f04548ec9b7daeeba2f61814e8ccc40448045007f5479f693a + 32e02c7f93d13dc2732b760ca377a5897b9dd41a1c1b29dc0442fdce6d0a04d1d + `; ecdh5.setPrivateKey(cafebabeKey, 'hex'); assert.strictEqual(ecdh5.getPrivateKey('hex'), cafebabeKey); // Show that the public point (key) is generated while setting the @@ -251,9 +256,10 @@ if (availableCurves.has('prime256v1') && availableCurves.has('secp256k1')) { // 0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF const peerPubPtComp = '02c6b754b20826eb925e052ee2c25285b162b51fdca732bcf67e39d647fb6830ae'; - const peerPubPtUnComp = - '04c6b754b20826eb925e052ee2c25285b162b51fdca732bcf67e39d647fb6830ae' + - 'b651944a574a362082a77e3f2b5d9223eb54d7f2f76846522bf75f3bedb8178e'; + const peerPubPtUnComp = tagGlue` + 04c6b754b20826eb925e052ee2c25285b162b51fdca732bcf67e39d647fb6830a + eb651944a574a362082a77e3f2b5d9223eb54d7f2f76846522bf75f3bedb8178e + `; const sharedSecret = '1da220b5329bbe8bfd19ceef5a5898593f411a6f12ea40f2a8eead9a5cf59970'; diff --git a/test/parallel/test-crypto-hmac.js b/test/parallel/test-crypto-hmac.js index 94c5cefa058d02..ab9bc10e478b9c 100644 --- a/test/parallel/test-crypto-hmac.js +++ b/test/parallel/test-crypto-hmac.js @@ -2,6 +2,8 @@ const common = require('../common'); const assert = require('assert'); +const { tagGlue, tagUnwrap } = common; + if (!common.hasCrypto) { common.skip('missing crypto'); return; @@ -31,8 +33,7 @@ const wikipedia = [ md5: '80070713463e7749b90c2dc24911e275', sha1: 'de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9', sha256: - 'f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc' + - '2d1a3cd8' + 'f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8' } }, { @@ -41,8 +42,7 @@ const wikipedia = [ md5: '63530468a04e386459855da0063b6596', sha1: 'f42bb0eeb018ebbd4597ae7213711ec60760843f', sha256: - '5d5d139563c95b5967b9bd9a8c9b233a9dedb45072794cd232dc1b74' + - '832607d0' + '5d5d139563c95b5967b9bd9a8c9b233a9dedb45072794cd232dc1b74832607d0' } }, { @@ -51,8 +51,7 @@ const wikipedia = [ md5: 'ad262969c53bc16032f160081c4a07a0', sha1: '2ba7f707ad5f187c412de3106583c3111d668de8', sha256: - 'fb011e6154a19b9a4c767373c305275a5a69e8b68b0b4c9200c383dc' + - 'ed19a416' + 'fb011e6154a19b9a4c767373c305275a5a69e8b68b0b4c9200c383dced19a416' } }, { @@ -61,8 +60,7 @@ const wikipedia = [ md5: '74e6f7298a9c2d168935f58c001bad88', sha1: 'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d', sha256: - 'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c71214' + - '4292c5ad' + 'b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad' } }, ]; @@ -90,72 +88,61 @@ const rfc4231 = [ hmac: { sha224: '896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22', sha256: - 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c' + - '2e32cff7', - sha384: - 'afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c' + - '7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6', - sha512: - '87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b305' + - '45e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f170' + - '2e696c203a126854' + 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7', + sha384: tagGlue`afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c + 7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6`, + sha512: tagGlue`87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b305 + 45e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f170 + 2e696c203a126854` } }, { key: Buffer.from('4a656665', 'hex'), // 'Jefe' - data: Buffer.from('7768617420646f2079612077616e7420666f72206e6f74686' + - '96e673f', 'hex'), // 'what do ya want for nothing?' + data: Buffer.from( + '7768617420646f2079612077616e7420666f72206e6f7468696e673f', + 'hex'), // 'what do ya want for nothing?' hmac: { sha224: 'a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44', sha256: - '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b9' + - '64ec3843', - sha384: - 'af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec373' + - '6322445e8e2240ca5e69e2c78b3239ecfab21649', - sha512: - '164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7' + - 'ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b' + - '636e070a38bce737' + '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843', + sha384: tagGlue`af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec373 + 6322445e8e2240ca5e69e2c78b3239ecfab21649`, + sha512: tagGlue`164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7 + ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b + 636e070a38bce737` } }, { key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: Buffer.from('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), + data: Buffer.from( + tagGlue`dddddddddddddddddddddddddddddddddddddddddddddddddd + dddddddddddddddddddddddddddddddddddddddddddddddddd`, 'hex'), hmac: { sha224: '7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea', sha256: - '773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514' + - 'ced565fe', - sha384: - '88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e5' + - '5966144b2a5ab39dc13814b94e3ab6e101a34f27', - sha512: - 'fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33' + - 'b2279d39bf3e848279a722c806b485a47e67c807b946a337bee89426' + - '74278859e13292fb' + '773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe', + sha384: tagGlue`88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e5 + 5966144b2a5ab39dc13814b94e3ab6e101a34f27`, + sha512: tagGlue`fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33 + b2279d39bf3e848279a722c806b485a47e67c807b946a337bee89426 + 74278859e13292fb` } }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), - data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd', - 'hex'), + data: Buffer.from( + tagGlue`cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd + cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd`, 'hex'), hmac: { sha224: '6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a', sha256: - '82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff4' + - '6729665b', - sha384: - '3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e' + - '1f573b4e6801dd23c4a7d679ccf8a386c674cffb', - sha512: - 'b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050' + - '361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2d' + - 'e2adebeb10a298dd' + '82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b', + sha384: tagGlue`3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e + 1f573b4e6801dd23c4a7d679ccf8a386c674cffb`, + sha512: tagGlue`b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050 + 361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2d + e2adebeb10a298dd` } }, @@ -172,59 +159,53 @@ const rfc4231 = [ truncate: true }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaa`, 'hex'), // 'Test Using Larger Than Block-Size Key - Hash Key First' - data: Buffer.from('54657374205573696e67204c6172676572205468616e20426' + - 'c6f636b2d53697a65204b6579202d2048617368204b657920' + - '4669727374', 'hex'), + data: Buffer.from(tagGlue`54657374205573696e67204c6172676572205468616e20426 + c6f636b2d53697a65204b6579202d2048617368204b657920 + 4669727374`, 'hex'), hmac: { sha224: '95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e', sha256: - '60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f' + - '0ee37f54', - sha384: - '4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05' + - '033ac4c60c2ef6ab4030fe8296248df163f44952', - sha512: - '80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b0137' + - '83f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec' + - '8b915a985d786598' + '60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54', + sha384: tagGlue`4ece084485813e9088d2c63a041bc5b44f9ef1012a2b588f3cd11f05 + 033ac4c60c2ef6ab4030fe8296248df163f44952`, + sha512: tagGlue`80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b0137 + 83f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec + 8b915a985d786598` } }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaa', 'hex'), + key: Buffer.from(tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaa`, 'hex'), // 'This is a test using a larger than block-size key and a larger ' + // 'than block-size data. The key needs to be hashed before being ' + // 'used by the HMAC algorithm.' - data: Buffer.from('5468697320697320612074657374207573696e672061206c6' + - '172676572207468616e20626c6f636b2d73697a65206b6579' + - '20616e642061206c6172676572207468616e20626c6f636b2' + - 'd73697a6520646174612e20546865206b6579206e65656473' + - '20746f20626520686173686564206265666f7265206265696' + - 'e6720757365642062792074686520484d414320616c676f72' + - '6974686d2e', 'hex'), + data: Buffer.from(tagGlue`5468697320697320612074657374207573696e672061206c6 + 172676572207468616e20626c6f636b2d73697a65206b6579 + 20616e642061206c6172676572207468616e20626c6f636b2 + d73697a6520646174612e20546865206b6579206e65656473 + 20746f20626520686173686564206265666f7265206265696 + e6720757365642062792074686520484d414320616c676f72 + 6974686d2e`, 'hex'), hmac: { sha224: '3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1', sha256: - '9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f5153' + - '5c3a35e2', - sha384: - '6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82' + - '461e99c5a678cc31e799176d3860e6110c46523e', - sha512: - 'e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d' + - '20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de04460' + - '65c97440fa8c6a58' + '9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2', + sha384: tagGlue`6617178e941f020d351e2f254e8fd32c602420feb0b8fb9adccebb82 + 461e99c5a678cc31e799176d3860e6110c46523e`, + sha512: tagGlue`e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d + 20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de04460 + 65c97440fa8c6a58` } } ]; @@ -262,18 +243,17 @@ const rfc2202_md5 = [ }, { key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: Buffer.from('ddddddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddddddddd', - 'hex'), + data: Buffer.from( + tagGlue`dddddddddddddddddddddddddddddddddddddddddddddddddd + dddddddddddddddddddddddddddddddddddddddddddddddddd`, 'hex'), hmac: '56be34521d144c88dbb8c733f0e8b3f6' }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), - data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), + data: Buffer.from( + tagGlue`cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd + cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd`, 'hex'), hmac: '697eaf0aca3a3aea3a75164746ffaa79' }, { @@ -282,23 +262,22 @@ const rfc2202_md5 = [ hmac: '56461ef2342edc00f9bab995690efd4c' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), + key: Buffer.from( + tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), data: 'Test Using Larger Than Block-Size Key - Hash Key First', hmac: '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', + key: Buffer.from( + tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), + data: tagUnwrap`Test Using Larger Than Block-Size Key + and Larger Than One Block-Size Data`, hmac: '6f630fad67cda0ee1fb1f562db3aa53e' } ]; @@ -315,19 +294,17 @@ const rfc2202_sha1 = [ }, { key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'hex'), - data: Buffer.from('ddddddddddddddddddddddddddddddddddddddddddddd' + - 'ddddddddddddddddddddddddddddddddddddddddddddd' + - 'dddddddddd', - 'hex'), + data: Buffer.from( + tagGlue`dddddddddddddddddddddddddddddddddddddddddddddddddd + dddddddddddddddddddddddddddddddddddddddddddddddddd`, 'hex'), hmac: '125d7342b9ac11cd91a39af48aa17b4f63f175d3' }, { key: Buffer.from('0102030405060708090a0b0c0d0e0f10111213141516171819', 'hex'), - data: Buffer.from('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdc' + - 'dcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd' + - 'cdcdcdcdcd', - 'hex'), + data: Buffer.from( + tagGlue`cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd + cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd`, 'hex'), hmac: '4c9007f4026250c6bc8414f9bf50c86c2d7235da' }, { @@ -336,23 +313,22 @@ const rfc2202_sha1 = [ hmac: '4c1a03424b55e07fe7f27be1d58bb9324a9a5a04' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), + key: Buffer.from( + tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), data: 'Test Using Larger Than Block-Size Key - Hash Key First', hmac: 'aa4ae5e15272d00e95705637ce8a3b55ed402112' }, { - key: Buffer.from('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + - 'aaaaaaaaaaaaaaaaaaaaaa', - 'hex'), - data: - 'Test Using Larger Than Block-Size Key and Larger Than One ' + - 'Block-Size Data', + key: Buffer.from( + tagGlue`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaa`, 'hex'), + data: tagUnwrap`Test Using Larger Than Block-Size Key + and Larger Than One Block-Size Data`, hmac: 'e8e99d0f45237d786d6bbaa7965c7808bbff1a91' } ]; diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index daa818705b8488..4f5faabb8cfc8b 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -10,6 +10,7 @@ if (!common.hasCrypto) { const constants = require('crypto').constants; const crypto = require('crypto'); +const { tagGlue } = common; const fixtDir = common.fixturesDir; // Test certificates @@ -138,12 +139,12 @@ let rsaVerify = crypto.createVerify('RSA-SHA1'); assert.ok(rsaSign); assert.ok(rsaVerify); -const expectedSignature = - '5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c' + - '8f020d7e2688b122bfb54c724ac9ee169f83f66d2fe90abeb95e8' + - 'e1290e7e177152a4de3d944cf7d4883114a20ed0f78e70e25ef0f' + - '60f06b858e6af42a2f276ede95bbc6bc9a9bbdda15bd663186a6f' + - '40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6'; +const expectedSignature = tagGlue` + 5c50e3145c4e2497aadb0eabc83b342d0b0021ece0d4c4a064b7c8f020d7e268 + 8b122bfb54c724ac9ee169f83f66d2fe90abeb95e8e1290e7e177152a4de3d94 + 4cf7d4883114a20ed0f78e70e25ef0f60f06b858e6af42a2f276ede95bbc6bc9 + a9bbdda15bd663186a6f40819a7af19e577bb2efa5e579a1f5ce8a0d4ca8b8f6 +`; rsaSign.update(rsaPubPem); let rsaSignature = rsaSign.sign(rsaKeyPem, 'hex'); @@ -182,12 +183,12 @@ assert.throws(() => { const input = 'I AM THE WALRUS'; - const signature = - '79d59d34f56d0e94aa6a3e306882b52ed4191f07521f25f505a078dc2f89' + - '396e0c8ac89e996fde5717f4cb89199d8fec249961fcb07b74cd3d2a4ffa' + - '235417b69618e4bcd76b97e29975b7ce862299410e1b522a328e44ac9bb2' + - '8195e0268da7eda23d9825ac43c724e86ceeee0d0d4465678652ccaf6501' + - '0ddfb299bedeb1ad'; + const signature = tagGlue` + 79d59d34f56d0e94aa6a3e306882b52ed4191f07521f25f505a078dc2f89396e + 0c8ac89e996fde5717f4cb89199d8fec249961fcb07b74cd3d2a4ffa235417b6 + 9618e4bcd76b97e29975b7ce862299410e1b522a328e44ac9bb28195e0268da7 + eda23d9825ac43c724e86ceeee0d0d4465678652ccaf65010ddfb299bedeb1ad + `; const sign = crypto.createSign('RSA-SHA256'); sign.update(input); diff --git a/test/parallel/test-fs-append-file-sync.js b/test/parallel/test-fs-append-file-sync.js index 31e95c2e368656..c52d198251bbdc 100644 --- a/test/parallel/test-fs-append-file-sync.js +++ b/test/parallel/test-fs-append-file-sync.js @@ -28,13 +28,15 @@ const fs = require('fs'); const currentFileData = 'ABCD'; const m = 0o600; const num = 220; -const data = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' + - '广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' + - '南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' + - '前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n'; +const data = ` + 南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、 + 广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。 + 南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。 + 前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年, + 南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年, + 历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度, + 它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。 +`; common.refreshTmpDir(); diff --git a/test/parallel/test-fs-append-file.js b/test/parallel/test-fs-append-file.js index 025a0ed034cd66..9c04014bd4ec94 100644 --- a/test/parallel/test-fs-append-file.js +++ b/test/parallel/test-fs-append-file.js @@ -30,13 +30,15 @@ const filename = join(common.tmpDir, 'append.txt'); const currentFileData = 'ABCD'; const n = 220; -const s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' + - '广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' + - '南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' + - '前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n'; +const s = ` + 南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、 + 广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。 + 南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。 + 前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年, + 南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年, + 历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度, + 它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。 +`; let ncallbacks = 0; diff --git a/test/parallel/test-fs-write-file-uint8array.js b/test/parallel/test-fs-write-file-uint8array.js index 219379c77a920d..6342336a2c1879 100644 --- a/test/parallel/test-fs-write-file-uint8array.js +++ b/test/parallel/test-fs-write-file-uint8array.js @@ -8,13 +8,15 @@ common.refreshTmpDir(); const filename = join(common.tmpDir, 'test.txt'); -const s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' + - '广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' + - '南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' + - '前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n'; +const s = ` + 南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、 + 广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。 + 南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。 + 前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年, + 南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年, + 历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度, + 它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。 +`; const input = Uint8Array.from(Buffer.from(s, 'utf8')); diff --git a/test/parallel/test-fs-write-file.js b/test/parallel/test-fs-write-file.js index 6dd1a58ecba832..7b86f8c06bc8a3 100644 --- a/test/parallel/test-fs-write-file.js +++ b/test/parallel/test-fs-write-file.js @@ -30,13 +30,15 @@ common.refreshTmpDir(); const filename = join(common.tmpDir, 'test.txt'); const n = 220; -const s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' + - '广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' + - '南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' + - '前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' + - '历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' + - '它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n'; +const s = ` + 南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、 + 广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。 + 南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。 + 前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年, + 南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年, + 历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度, + 它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。 +`; fs.writeFile(filename, s, common.mustCall(function(e) { assert.ifError(e); diff --git a/test/parallel/test-http-1.0-keep-alive.js b/test/parallel/test-http-1.0-keep-alive.js index f3b69a4cd059dd..2b666ca571e0a1 100644 --- a/test/parallel/test-http-1.0-keep-alive.js +++ b/test/parallel/test-http-1.0-keep-alive.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagCRLFy } = require('../common'); const http = require('http'); const net = require('net'); @@ -29,14 +29,20 @@ check([{ name: 'keep-alive, no TE header', requests: [{ expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + Connection: keep-alive + + + ` }, { expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + Connection: keep-alive + + + ` }], responses: [{ headers: {'Connection': 'keep-alive'}, @@ -48,14 +54,20 @@ check([{ name: 'keep-alive, with TE: chunked', requests: [{ expectClose: false, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - 'TE: chunked\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + Connection: keep-alive + TE: chunked + + + ` }, { expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + + + ` }], responses: [{ headers: {'Connection': 'keep-alive'}, @@ -67,13 +79,19 @@ check([{ name: 'keep-alive, with Transfer-Encoding: chunked', requests: [{ expectClose: false, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + Connection: keep-alive + + + ` }, { expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + + + ` }], responses: [{ headers: {'Connection': 'keep-alive', @@ -86,13 +104,19 @@ check([{ name: 'keep-alive, with Content-Length', requests: [{ expectClose: false, - data: 'POST / HTTP/1.0\r\n' + - 'Connection: keep-alive\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + Connection: keep-alive + + + ` }, { expectClose: true, - data: 'POST / HTTP/1.0\r\n' + - '\r\n' + data: tagCRLFy` + POST / HTTP/1.0 + + + ` }], responses: [{ headers: {'Connection': 'keep-alive', diff --git a/test/parallel/test-http-1.0.js b/test/parallel/test-http-1.0.js index f67d949bc8f5f6..498881ecd8a362 100644 --- a/test/parallel/test-http-1.0.js +++ b/test/parallel/test-http-1.0.js @@ -25,6 +25,13 @@ const assert = require('assert'); const net = require('net'); const http = require('http'); +const { tagUnwrap, tagCRLFy } = common; + +const userAgent = tagUnwrap` + curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 + OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15 +`; + const body = 'hello world\n'; function test(handler, request_generator, response_validator) { @@ -97,20 +104,24 @@ function test(handler, request_generator, response_validator) { } function request_generator() { - return ('GET / HTTP/1.0\r\n' + - 'User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 ' + - 'OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15\r\n' + - 'Host: 127.0.0.1:1337\r\n' + - 'Accept: */*\r\n' + - '\r\n'); + return (tagCRLFy` + GET / HTTP/1.0 + User-Agent: ${userAgent} + Host: 127.0.0.1:1337 + Accept: */* + + + `); } function response_validator(server_response, client_got_eof, timed_out) { - const expected_response = 'HTTP/1.1 200 OK\r\n' + - 'Content-Type: text/plain\r\n' + - 'Connection: close\r\n' + - '\r\n' + - 'Hello, world!'; + const expected_response = tagCRLFy` + HTTP/1.1 200 OK + Content-Type: text/plain + Connection: close + + Hello, world! + `; assert.strictEqual(expected_response, server_response); assert.strictEqual(true, client_got_eof); @@ -133,27 +144,32 @@ function test(handler, request_generator, response_validator) { } function request_generator() { - return 'GET / HTTP/1.1\r\n' + - 'User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 ' + - 'OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15\r\n' + - 'Connection: close\r\n' + - 'Host: 127.0.0.1:1337\r\n' + - 'Accept: */*\r\n' + - '\r\n'; + return tagCRLFy` + GET / HTTP/1.1 + User-Agent: ${userAgent} + Connection: close + Host: 127.0.0.1:1337 + Accept: */* + + + `; } function response_validator(server_response, client_got_eof, timed_out) { - const expected_response = 'HTTP/1.1 200 OK\r\n' + - 'Content-Type: text/plain\r\n' + - 'Connection: close\r\n' + - 'Transfer-Encoding: chunked\r\n' + - '\r\n' + - '7\r\n' + - 'Hello, \r\n' + - '6\r\n' + - 'world!\r\n' + - '0\r\n' + - '\r\n'; + const expected_response = tagCRLFy` + HTTP/1.1 200 OK + Content-Type: text/plain + Connection: close + Transfer-Encoding: chunked + + 7 + Hello,${' '} + 6 + world! + 0 + + + `; assert.strictEqual(expected_response, server_response); assert.strictEqual(true, client_got_eof); diff --git a/test/parallel/test-http-blank-header.js b/test/parallel/test-http-blank-header.js index 1659dc5ed5fd5d..f91b4825b7ce02 100644 --- a/test/parallel/test-http-blank-header.js +++ b/test/parallel/test-http-blank-header.js @@ -40,12 +40,14 @@ server.listen(0, function() { const c = net.createConnection(this.address().port); c.on('connect', function() { - c.write('GET /blah HTTP/1.1\r\n' + - 'Host: mapdevel.trolologames.ru:443\r\n' + - 'Cookie:\r\n' + - 'Origin: http://mapdevel.trolologames.ru\r\n' + - '\r\n\r\nhello world' - ); + c.write(common.tagCRLFy` + GET /blah HTTP/1.1 + Host: mapdevel.trolologames.ru:443 + Cookie: + Origin: http://mapdevel.trolologames.ru + + hello world + `); }); c.on('end', function() { diff --git a/test/parallel/test-http-chunked.js b/test/parallel/test-http-chunked.js index 133c1d847792b1..f16ffec0f3d40d 100644 --- a/test/parallel/test-http-chunked.js +++ b/test/parallel/test-http-chunked.js @@ -24,15 +24,17 @@ require('../common'); const assert = require('assert'); const http = require('http'); -const UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一个国家,' + - '国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、' + - '贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,' + - '由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,' + - '南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' + - '南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。' + - '南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,' + - '采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + - '有效的改善了岭南地区落后的政治、经济现状。'; +const UTF8_STRING = ` + 南越国是前203年至前111年存在于岭南地区的一个国家, + 国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、 + 贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后, + 由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年, + 南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年, + 南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。 + 南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家, + 采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定, + 有效的改善了岭南地区落后的政治、经济现状。 +`; const server = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'}); diff --git a/test/parallel/test-http-client-reject-chunked-with-content-length.js b/test/parallel/test-http-client-reject-chunked-with-content-length.js index d29e37291dffde..e486a95ff6c1ef 100644 --- a/test/parallel/test-http-client-reject-chunked-with-content-length.js +++ b/test/parallel/test-http-client-reject-chunked-with-content-length.js @@ -5,9 +5,13 @@ const http = require('http'); const net = require('net'); const assert = require('assert'); -const reqstr = 'HTTP/1.1 200 OK\r\n' + - 'Content-Length: 1\r\n' + - 'Transfer-Encoding: chunked\r\n\r\n'; +const reqstr = common.tagCRLFy` + HTTP/1.1 200 OK + Content-Length: 1 + Transfer-Encoding: chunked + + +`; const server = net.createServer((socket) => { socket.write(reqstr); diff --git a/test/parallel/test-http-connect-req-res.js b/test/parallel/test-http-connect-req-res.js index 5db19aedde91d8..ff33043e044d1f 100644 --- a/test/parallel/test-http-connect-req-res.js +++ b/test/parallel/test-http-connect-req-res.js @@ -11,12 +11,12 @@ server.on('connect', common.mustCall(function(req, socket, firstBodyChunk) { // It is legal for the server to send some data intended for the client // along with the CONNECT response - socket.write( - 'HTTP/1.1 200 Connection established\r\n' + - 'Date: Tue, 15 Nov 1994 08:12:31 GMT\r\n' + - '\r\n' + - 'Head' - ); + socket.write(common.tagCRLFy` + HTTP/1.1 200 Connection established + Date: Tue, 15 Nov 1994 08:12:31 GMT + + Head + `); let data = firstBodyChunk.toString(); socket.on('data', function(buf) { diff --git a/test/parallel/test-http-extra-response.js b/test/parallel/test-http-extra-response.js index e71decb0c39b80..05f976f36761ed 100644 --- a/test/parallel/test-http-extra-response.js +++ b/test/parallel/test-http-extra-response.js @@ -30,16 +30,17 @@ const net = require('net'); // Demos this bug: https://github.com/joyent/node/issues/680 const body = 'hello world\r\n'; -const fullResponse = - 'HTTP/1.1 500 Internal Server Error\r\n' + - 'Content-Length: ' + body.length + '\r\n' + - 'Content-Type: text/plain\r\n' + - 'Date: Fri + 18 Feb 2011 06:22:45 GMT\r\n' + - 'Host: 10.20.149.2\r\n' + - 'Access-Control-Allow-Credentials: true\r\n' + - 'Server: badly broken/0.1 (OS NAME)\r\n' + - '\r\n' + - body; +const fullResponse = common.tagCRLFy` + HTTP/1.1 500 Internal Server Error + Content-Length: ${body.length} + Content-Type: text/plain + Date: Fri + 18 Feb 2011 06:22:45 GMT + Host: 10.20.149.2 + Access-Control-Allow-Credentials: true + Server: badly broken/0.1 (OS NAME) + + ${body} +`; const server = net.createServer(function(socket) { let postBody = ''; diff --git a/test/parallel/test-http-incoming-pipelined-socket-destroy.js b/test/parallel/test-http-incoming-pipelined-socket-destroy.js index b9603a5791690c..22b65208bd6e19 100644 --- a/test/parallel/test-http-incoming-pipelined-socket-destroy.js +++ b/test/parallel/test-http-incoming-pipelined-socket-destroy.js @@ -61,10 +61,13 @@ const server = http.createServer(common.mustCall(function(req, res) { // Make a bunch of requests pipelined on the same socket function generator(seeds) { return seeds.map(function(r) { - return 'GET /' + r + ' HTTP/1.1\r\n' + - `Host: localhost:${server.address().port}\r\n` + - '\r\n' + - '\r\n'; + return common.tagCRLFy` + GET /${r} HTTP/1.1 + Host: localhost:${server.address().port} + + + + `; }).join(''); } diff --git a/test/parallel/test-http-many-ended-pipelines.js b/test/parallel/test-http-many-ended-pipelines.js index d17090cec918a0..15e2bb7b705017 100644 --- a/test/parallel/test-http-many-ended-pipelines.js +++ b/test/parallel/test-http-many-ended-pipelines.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagCRLFy } = require('../common'); // no warnings should happen! const trace = console.trace; @@ -52,9 +52,13 @@ server.listen(0, function() { const client = net.connect({ port: this.address().port, allowHalfOpen: true }); for (let i = 0; i < numRequests; i++) { - client.write('GET / HTTP/1.1\r\n' + - 'Host: some.host.name\r\n' + - '\r\n\r\n'); + client.write(tagCRLFy` + GET / HTTP/1.1 + Host: some.host.name + + + + `); } client.end(); client.pipe(process.stdout); diff --git a/test/parallel/test-http-multi-line-headers.js b/test/parallel/test-http-multi-line-headers.js index fb629ccc46ae60..ab25b6bc620ea1 100644 --- a/test/parallel/test-http-multi-line-headers.js +++ b/test/parallel/test-http-multi-line-headers.js @@ -29,15 +29,16 @@ const net = require('net'); const server = net.createServer(function(conn) { const body = 'Yet another node.js server.'; - const response = - 'HTTP/1.1 200 OK\r\n' + - 'Connection: close\r\n' + - 'Content-Length: ' + body.length + '\r\n' + - 'Content-Type: text/plain;\r\n' + - ' x-unix-mode=0600;\r\n' + - ' name="hello.txt"\r\n' + - '\r\n' + - body; + const response = common.tagCRLFy` + HTTP/1.1 200 OK + Connection: close + Content-Length: ${body.length} + Content-Type: text/plain; + x-unix-mode=0600; + name="hello.txt" + + ${body} + `; conn.end(response); server.close(); diff --git a/test/parallel/test-http-parser.js b/test/parallel/test-http-parser.js index f0a525cda3cf0b..03d17b364323f5 100644 --- a/test/parallel/test-http-parser.js +++ b/test/parallel/test-http-parser.js @@ -27,7 +27,8 @@ const binding = process.binding('http_parser'); const methods = binding.methods; const HTTPParser = binding.HTTPParser; -const CRLF = '\r\n'; +const { tagCRLFy } = common; + const REQUEST = HTTPParser.REQUEST; const RESPONSE = HTTPParser.RESPONSE; @@ -92,7 +93,11 @@ function expectBody(expected) { // Simple request test. // { - const request = Buffer.from(`GET /hello HTTP/1.1${CRLF}${CRLF}`); + const request = Buffer.from(tagCRLFy` + GET /hello HTTP/1.1 + + + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -128,12 +133,13 @@ function expectBody(expected) { // Simple response test. // { - const request = Buffer.from( - 'HTTP/1.1 200 OK' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Content-Length: 4' + CRLF + - CRLF + - 'pong'); + const request = Buffer.from(tagCRLFy` + HTTP/1.1 200 OK + Content-Type: text/plain + Content-Length: 4 + + pong + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -161,8 +167,11 @@ function expectBody(expected) { // Response with no headers. // { - const request = Buffer.from( - `HTTP/1.0 200 Connection established${CRLF}${CRLF}`); + const request = Buffer.from(tagCRLFy` + HTTP/1.0 200 Connection established + + + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -185,16 +194,18 @@ function expectBody(expected) { // Trailing headers. // { - const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '4' + CRLF + - 'ping' + CRLF + - '0' + CRLF + - 'Vary: *' + CRLF + - 'Content-Type: text/plain' + CRLF + - CRLF); + const request = Buffer.from(tagCRLFy` + POST /it HTTP/1.1 + Transfer-Encoding: chunked + + 4 + ping + 0 + Vary: * + Content-Type: text/plain + + + `); let seen_body = false; @@ -232,12 +243,14 @@ function expectBody(expected) { // Test header ordering. // { - const request = Buffer.from( - 'GET / HTTP/1.0' + CRLF + - 'X-Filler: 1337' + CRLF + - 'X-Filler: 42' + CRLF + - 'X-Filler2: 42' + CRLF + - CRLF); + const request = Buffer.from(tagCRLFy` + GET / HTTP/1.0 + X-Filler: 1337 + X-Filler: 42 + X-Filler2: 42 + + + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -261,12 +274,14 @@ function expectBody(expected) { // { // 256 X-Filler headers - const lots_of_headers = `X-Filler: 42${CRLF}`.repeat(256); + const lots_of_headers = `X-Filler: 42${'\r\n'}`.repeat(256); + + const request = Buffer.from(tagCRLFy` + GET /foo/bar/baz?quux=42#1337 HTTP/1.0 + ${lots_of_headers} + - const request = Buffer.from( - 'GET /foo/bar/baz?quux=42#1337 HTTP/1.0' + CRLF + - lots_of_headers + - CRLF); + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -295,12 +310,13 @@ function expectBody(expected) { // Test request body // { - const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: application/x-www-form-urlencoded' + CRLF + - 'Content-Length: 15' + CRLF + - CRLF + - 'foo=42&bar=1337'); + const request = Buffer.from(tagCRLFy` + POST /it HTTP/1.1 + Content-Type: application/x-www-form-urlencoded + Content-Length: 15 + + foo=42&bar=1337' + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -327,18 +343,20 @@ function expectBody(expected) { // Test chunked request body // { - const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - 'A' + CRLF + - '1234567890' + CRLF + - '0' + CRLF); + const request = Buffer.from(tagCRLFy` + POST /it HTTP/1.1 + Content-Type: text/plain + Transfer-Encoding: chunked + + 3 + 123 + 6 + 123456 + A + 1234567890 + 0 + + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -368,15 +386,17 @@ function expectBody(expected) { // Test chunked request body spread over multiple buffers (packets) // { - let request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF); + let request = Buffer.from(tagCRLFy` + POST /it HTTP/1.1 + Content-Type: text/plain + Transfer-Encoding: chunked + + 3 + 123 + 6 + 123456 + + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -401,14 +421,16 @@ function expectBody(expected) { parser[kOnBody] = mustCall(onBody, body_parts.length); parser.execute(request, 0, request.length); - request = Buffer.from( - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); + request = Buffer.from(tagCRLFy` + 9 + 123456789 + C + 123456789ABC + F + 123456789ABCDEF + 0 + + `); parser.execute(request, 0, request.length); } @@ -418,22 +440,24 @@ function expectBody(expected) { // Stress test. // { - const request = Buffer.from( - 'POST /helpme HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); + const request = Buffer.from(tagCRLFy` + POST /helpme HTTP/1.1 + Content-Type: text/plain + Transfer-Encoding: chunked + + 3 + 123 + 6 + 123456 + 9 + 123456789 + C + 123456789ABC + F + 123456789ABCDEF + 0 + + `); function test(a, b) { const onHeadersComplete = (versionMajor, versionMinor, headers, @@ -476,22 +500,24 @@ function expectBody(expected) { // Byte by byte test. // { - const request = Buffer.from( - 'POST /it HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '3' + CRLF + - '123' + CRLF + - '6' + CRLF + - '123456' + CRLF + - '9' + CRLF + - '123456789' + CRLF + - 'C' + CRLF + - '123456789ABC' + CRLF + - 'F' + CRLF + - '123456789ABCDEF' + CRLF + - '0' + CRLF); + const request = Buffer.from(tagCRLFy` + POST /it HTTP/1.1 + Content-Type: text/plain + Transfer-Encoding: chunked + + 3 + 123 + 6 + 123456 + 9 + 123456789 + C + 123456789ABC + F + 123456789ABCDEF + 0 + + `); const onHeadersComplete = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -529,21 +555,24 @@ function expectBody(expected) { // Test parser reinit sequence. // { - const req1 = Buffer.from( - 'PUT /this HTTP/1.1' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Transfer-Encoding: chunked' + CRLF + - CRLF + - '4' + CRLF + - 'ping' + CRLF + - '0' + CRLF); - - const req2 = Buffer.from( - 'POST /that HTTP/1.0' + CRLF + - 'Content-Type: text/plain' + CRLF + - 'Content-Length: 4' + CRLF + - CRLF + - 'pong'); + const req1 = Buffer.from(tagCRLFy` + PUT /this HTTP/1.1 + Content-Type: text/plain + Transfer-Encoding: chunked + + 4 + ping + 0 + + `); + + const req2 = Buffer.from(tagCRLFy` + POST /that HTTP/1.0 + Content-Type: text/plain + Content-Length: 4 + + pong + `); const onHeadersComplete1 = (versionMajor, versionMinor, headers, method, url, statusCode, statusMessage, @@ -584,7 +613,11 @@ function expectBody(expected) { // Test parser 'this' safety // https://github.com/joyent/node/issues/6690 assert.throws(function() { - const request = Buffer.from(`GET /hello HTTP/1.1${CRLF}${CRLF}`); + const request = Buffer.from(tagCRLFy` + GET /hello HTTP/1.1 + + + `); const parser = newParser(REQUEST); const notparser = { execute: parser.execute }; diff --git a/test/parallel/test-http-pipeline-regr-3508.js b/test/parallel/test-http-pipeline-regr-3508.js index ff735818f68121..a151eb5605057b 100644 --- a/test/parallel/test-http-pipeline-regr-3508.js +++ b/test/parallel/test-http-pipeline-regr-3508.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const { tagCRLFy } = require('../common'); const http = require('http'); const net = require('net'); @@ -46,8 +46,15 @@ const server = http.createServer(function(req, res) { s.write('GET / HTTP/1.1\r\n\r\n'); }; done = function() { - s.write('GET / HTTP/1.1\r\n\r\n' + - 'GET / HTTP/1.1\r\nConnection: upgrade\r\nUpgrade: ws\r\n\r\naaa'); + s.write(tagCRLFy` + GET / HTTP/1.1 + + GET / HTTP/1.1 + Connection: upgrade + Upgrade: ws + + aaa + `); }; more(); more(); diff --git a/test/parallel/test-http-response-splitting.js b/test/parallel/test-http-response-splitting.js index aebb6b813be35e..66a5b18e6d3c14 100644 --- a/test/parallel/test-http-response-splitting.js +++ b/test/parallel/test-http-response-splitting.js @@ -1,17 +1,18 @@ 'use strict'; -require('../common'); +const { tagGlue } = require('../common'); const http = require('http'); const net = require('net'); const url = require('url'); const assert = require('assert'); // Response splitting example, credit: Amit Klein, Safebreach -const str = '/welcome?lang=bar%c4%8d%c4%8aContent­Length:%200%c4%8d%c4%8a%c' + - '4%8d%c4%8aHTTP/1.1%20200%20OK%c4%8d%c4%8aContent­Length:%202' + - '0%c4%8d%c4%8aLast­Modified:%20Mon,%2027%20Oct%202003%2014:50:18' + - '%20GMT%c4%8d%c4%8aContent­Type:%20text/html%c4%8d%c4%8a%c4%8' + - 'd%c4%8a%3chtml%3eGotcha!%3c/html%3e'; +const str = tagGlue` + /welcome?lang=bar%c4%8d%c4%8aContent­Length:%200%c4%8d%c4%8a%c4%8d%c4%8a + HTTP/1.1%20200%20OK%c4%8d%c4%8aContent­Length:%2020%c4%8d%c4%8a + Last­Modified:%20Mon,%2027%20Oct%202003%2014:50:18%20GMT%c4%8d%c4%8a + Content­Type:%20text/html%c4%8d%c4%8a%c4%8d%c4%8a%3chtml%3eGotcha!%3c/html%3e +`; // Response splitting example, credit: Сковорода Никита Андреевич (@ChALkeR) const x = 'fooഊSet-Cookie: foo=barഊഊ'; diff --git a/test/parallel/test-http-server-reject-chunked-with-content-length.js b/test/parallel/test-http-server-reject-chunked-with-content-length.js index f316d86a7019dc..4ee8b1c3387ff3 100644 --- a/test/parallel/test-http-server-reject-chunked-with-content-length.js +++ b/test/parallel/test-http-server-reject-chunked-with-content-length.js @@ -5,9 +5,13 @@ const http = require('http'); const net = require('net'); const assert = require('assert'); -const reqstr = 'POST / HTTP/1.1\r\n' + - 'Content-Length: 1\r\n' + - 'Transfer-Encoding: chunked\r\n\r\n'; +const reqstr = common.tagCRLFy` + POST / HTTP/1.1 + Content-Length: 1 + Transfer-Encoding: chunked + + +`; const server = http.createServer(common.mustNotCall()); server.on('clientError', common.mustCall((err) => { diff --git a/test/parallel/test-http-server-unconsume-consume.js b/test/parallel/test-http-server-unconsume-consume.js index 0135205eb14ed9..e7f4f7a2739d94 100644 --- a/test/parallel/test-http-server-unconsume-consume.js +++ b/test/parallel/test-http-server-unconsume-consume.js @@ -4,9 +4,12 @@ const http = require('http'); const testServer = http.createServer(common.mustNotCall()); testServer.on('connect', common.mustCall((req, socket, head) => { - socket.write('HTTP/1.1 200 Connection Established\r\n' + - 'Proxy-agent: Node-Proxy\r\n' + - '\r\n'); + socket.write(common.tagCRLFy` + HTTP/1.1 200 Connection Established + Proxy-agent: Node-Proxy + + + `); // This shouldn't raise an assertion in StreamBase::Consume. testServer.emit('connection', socket); testServer.close(); diff --git a/test/parallel/test-http-upgrade-advertise.js b/test/parallel/test-http-upgrade-advertise.js index 99a3e8fd353015..bc78dbe19d5549 100644 --- a/test/parallel/test-http-upgrade-advertise.js +++ b/test/parallel/test-http-upgrade-advertise.js @@ -47,8 +47,11 @@ const server = http.createServer(function(req, res) { }); res.end('hello world'); }).on('upgrade', function(req, socket) { - socket.end('HTTP/1.1 101 Switching protocols\r\n' + - 'Connection: upgrade\r\n' + - 'Upgrade: h2c\r\n\r\n' + - 'ohai'); + socket.end(common.tagCRLFy` + HTTP/1.1 101 Switching protocols + Connection: upgrade + Upgrade: h2c + + ohai + `); }).listen(0, fire); diff --git a/test/parallel/test-http-upgrade-client2.js b/test/parallel/test-http-upgrade-client2.js index 70eaeaa95f1706..989e1a8ff59084 100644 --- a/test/parallel/test-http-upgrade-client2.js +++ b/test/parallel/test-http-upgrade-client2.js @@ -23,13 +23,15 @@ const common = require('../common'); const http = require('http'); -const CRLF = '\r\n'; - const server = http.createServer(); server.on('upgrade', function(req, socket, head) { - socket.write('HTTP/1.1 101 Ok' + CRLF + - 'Connection: Upgrade' + CRLF + - 'Upgrade: Test' + CRLF + CRLF + 'head'); + socket.write(common.tagCRLFy` + HTTP/1.1 101 Ok + Connection: Upgrade + Upgrade: Test + + head + `); socket.on('end', function() { socket.end(); }); diff --git a/test/parallel/test-http-upgrade-server.js b/test/parallel/test-http-upgrade-server.js index 11c0aba5b4dc0e..1dd4a0b369d2f1 100644 --- a/test/parallel/test-http-upgrade-server.js +++ b/test/parallel/test-http-upgrade-server.js @@ -28,6 +28,7 @@ const util = require('util'); const net = require('net'); const http = require('http'); +const { tagCRLFy } = common; let requests_recv = 0; let requests_sent = 0; @@ -51,10 +52,14 @@ function testServer() { }); this.on('upgrade', function(req, socket, upgradeHead) { - socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n\r\n'); + socket.write(tagCRLFy` + HTTP/1.1 101 Web Socket Protocol Handshake + Upgrade: WebSocket + Connection: Upgrade + + + + `); request_upgradeHead = upgradeHead; @@ -87,12 +92,13 @@ function test_upgrade_with_listener() { let state = 0; conn.on('connect', function() { - writeReq(conn, - 'GET / HTTP/1.1\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n' + - 'WjN}|M(6'); + writeReq(conn, tagCRLFy` + GET / HTTP/1.1 + Upgrade: WebSocket + Connection: Upgrade + + WjN}|M(6 + `); }); conn.on('data', function(data) { @@ -128,11 +134,13 @@ function test_upgrade_no_listener() { conn.setEncoding('utf8'); conn.on('connect', function() { - writeReq(conn, - 'GET / HTTP/1.1\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n'); + writeReq(conn, tagCRLFy` + GET / HTTP/1.1 + Upgrade: WebSocket + Connection: Upgrade + + + `); }); conn.on('end', function() { diff --git a/test/parallel/test-http-upgrade-server2.js b/test/parallel/test-http-upgrade-server2.js index 209ea1f4bc7c6e..ffde6bbd1aa059 100644 --- a/test/parallel/test-http-upgrade-server2.js +++ b/test/parallel/test-http-upgrade-server2.js @@ -45,10 +45,14 @@ server.listen(0, function() { const c = net.createConnection(this.address().port); c.on('connect', function() { - c.write('GET /blah HTTP/1.1\r\n' + - 'Upgrade: WebSocket\r\n' + - 'Connection: Upgrade\r\n' + - '\r\n\r\nhello world'); + c.write(common.tagCRLFy` + GET /blah HTTP/1.1 + Upgrade: WebSocket + Connection: Upgrade + + + hello world + `); }); c.on('end', function() { diff --git a/test/parallel/test-https-client-resume.js b/test/parallel/test-https-client-resume.js index 95e1da56d0c46a..cf4c1e2f0633cb 100644 --- a/test/parallel/test-https-client-resume.js +++ b/test/parallel/test-https-client-resume.js @@ -26,6 +26,8 @@ const common = require('../common'); const assert = require('assert'); +const { tagCRLFy } = common; + if (!common.hasCrypto) { common.skip('missing crypto'); return; @@ -56,9 +58,12 @@ server.listen(0, function() { console.log('connect1'); assert.ok(!client1.isSessionReused(), 'Session *should not* be reused.'); session1 = client1.getSession(); - client1.write('GET / HTTP/1.0\r\n' + - 'Server: 127.0.0.1\r\n' + - '\r\n'); + client1.write(tagCRLFy` + GET / HTTP/1.0 + Server: 127.0.0.1 + + + `); }); client1.on('close', function() { @@ -73,9 +78,12 @@ server.listen(0, function() { const client2 = tls.connect(opts, function() { console.log('connect2'); assert.ok(client2.isSessionReused(), 'Session *should* be reused.'); - client2.write('GET / HTTP/1.0\r\n' + - 'Server: 127.0.0.1\r\n' + - '\r\n'); + client2.write(tagCRLFy` + GET / HTTP/1.0 + Server: 127.0.0.1 + + + `); }); client2.on('close', function() { diff --git a/test/parallel/test-https-eof-for-eom.js b/test/parallel/test-https-eof-for-eom.js index 3300dabb54aa7b..52d3d91388f0cd 100644 --- a/test/parallel/test-https-eof-for-eom.js +++ b/test/parallel/test-https-eof-for-eom.js @@ -48,16 +48,19 @@ const options = { const server = tls.Server(options, function(socket) { console.log('2) Server got request'); - socket.write('HTTP/1.1 200 OK\r\n' + - 'Date: Tue, 15 Feb 2011 22:14:54 GMT\r\n' + - 'Expires: -1\r\n' + - 'Cache-Control: private, max-age=0\r\n' + - 'Set-Cookie: xyz\r\n' + - 'Set-Cookie: abc\r\n' + - 'Server: gws\r\n' + - 'X-XSS-Protection: 1; mode=block\r\n' + - 'Connection: close\r\n' + - '\r\n'); + socket.write(common.tagCRLFy` + HTTP/1.1 200 OK + Date: Tue, 15 Feb 2011 22:14:54 GMT + Expires: -1 + Cache-Control: private, max-age=0 + Set-Cookie: xyz + Set-Cookie: abc + Server: gws + X-XSS-Protection: 1; mode=block + Connection: close + + + `); socket.write('hello world\n'); diff --git a/test/parallel/test-https-foafssl.js b/test/parallel/test-https-foafssl.js index 9900cf7a643c10..939c696856e041 100644 --- a/test/parallel/test-https-foafssl.js +++ b/test/parallel/test-https-foafssl.js @@ -46,15 +46,15 @@ const options = { rejectUnauthorized: false }; -const modulus = 'A6F44A9C25791431214F5C87AF9E040177A8BB89AC803F7E09BBC3A5519F' + - '349CD9B9C40BE436D0AA823A94147E26C89248ADA2BE3DD4D34E8C289646' + - '94B2047D217B4F1299371EA93A83C89AB9440724131E65F2B0161DE9560C' + - 'DE9C13455552B2F49CF0FB00D8D77532324913F6F80FF29D0A131D29DB06' + - 'AFF8BE191B7920DC2DAE1C26EA82A47847A10391EF3BF6AABB3CC40FF821' + - '00B03A4F0FF1809278E4DDFDA7DE954ED56DC7AD9A47EEBC37D771A366FC' + - '60A5BCB72373BEC180649B3EFA0E9092707210B41B90032BB18BC91F2046' + - 'EBDAF1191F4A4E26D71879C4C7867B62FCD508E8CE66E82D128A71E91580' + - '9FCF44E8DE774067F1DE5D70B9C03687'; +const modulus = common.tagGlue` + A6F44A9C25791431214F5C87AF9E040177A8BB89AC803F7E09BBC3A5519F349CD9B9C40BE436 + D0AA823A94147E26C89248ADA2BE3DD4D34E8C28964694B2047D217B4F1299371EA93A83C89A + B9440724131E65F2B0161DE9560CDE9C13455552B2F49CF0FB00D8D77532324913F6F80FF29D + 0A131D29DB06AFF8BE191B7920DC2DAE1C26EA82A47847A10391EF3BF6AABB3CC40FF82100B0 + 3A4F0FF1809278E4DDFDA7DE954ED56DC7AD9A47EEBC37D771A366FC60A5BCB72373BEC18064 + 9B3EFA0E9092707210B41B90032BB18BC91F2046EBDAF1191F4A4E26D71879C4C7867B62FCD5 + 08E8CE66E82D128A71E915809FCF44E8DE774067F1DE5D70B9C03687 +`; const CRLF = '\r\n'; const body = 'hello world\n'; diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index 7a367920b0fd49..0985123bcbdfca 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const { tagUnwrap } = require('../common'); const assert = require('assert'); const domain = require('domain'); @@ -106,265 +106,324 @@ function onUnhandledFail(done) { }, 10); } -asyncTest('synchronously rejected promise should trigger' + - ' unhandledRejection', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); +asyncTest( + 'synchronously rejected promise should trigger unhandledRejection', + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + Promise.reject(e); }); - Promise.reject(e); -}); -asyncTest('synchronously rejected promise should trigger' + - ' unhandledRejection', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); +asyncTest( + 'synchronously rejected promise should trigger unhandledRejection', + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + new Promise(function(_, reject) { + reject(e); + }); }); - new Promise(function(_, reject) { - reject(e); + +asyncTest( + 'Promise rejected after setImmediate should trigger unhandledRejection', + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + new Promise(function(_, reject) { + setImmediate(function() { + reject(e); + }); + }); }); -}); -asyncTest('Promise rejected after setImmediate should trigger' + - ' unhandledRejection', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); +asyncTest( + 'Promise rejected after setTimeout(,1) should trigger unhandled rejection', + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }); }); - new Promise(function(_, reject) { + +asyncTest( + tagUnwrap` + Catching a promise rejection after setImmediate + is not soon enough to stop unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + }); + let _reject; + const promise = new Promise(function(_, reject) { + _reject = reject; + }); + _reject(e); setImmediate(function() { - reject(e); + promise.then(assert.fail, function() {}); }); }); -}); -asyncTest('Promise rejected after setTimeout(,1) should trigger' + - ' unhandled rejection', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); +asyncTest( + tagUnwrap` + When re-throwing new errors in a promise catch, + only the re-thrown error should hit unhandledRejection + `, + function(done) { + const e = new Error(); + const e2 = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e2, reason); + assert.strictEqual(promise2, promise); + }); + const promise2 = Promise.reject(e).then(assert.fail, function(reason) { + assert.strictEqual(e, reason); + throw e2; + }); }); - new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); + +asyncTest( + 'Test params of unhandledRejection for a synchronously-rejected promise', + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(promise, promise); + }); + Promise.reject(e); }); -}); - -asyncTest('Catching a promise rejection after setImmediate is not' + - ' soon enough to stop unhandledRejection', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - }); - let _reject; - const promise = new Promise(function(_, reject) { - _reject = reject; - }); - _reject(e); - setImmediate(function() { - promise.then(assert.fail, function() {}); - }); -}); - -asyncTest('When re-throwing new errors in a promise catch, only the' + - ' re-thrown error should hit unhandledRejection', function(done) { - const e = new Error(); - const e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e2, reason); - assert.strictEqual(promise2, promise); - }); - const promise2 = Promise.reject(e).then(assert.fail, function(reason) { - assert.strictEqual(e, reason); - throw e2; - }); -}); - -asyncTest('Test params of unhandledRejection for a synchronously-rejected' + - 'promise', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(promise, promise); - }); - Promise.reject(e); -}); - -asyncTest('When re-throwing new errors in a promise catch, only the ' + - 're-thrown error should hit unhandledRejection: original promise' + - ' rejected async with setTimeout(,1)', function(done) { - const e = new Error(); - const e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e2, reason); - assert.strictEqual(promise2, promise); - }); - const promise2 = new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); - }).then(assert.fail, function(reason) { - assert.strictEqual(e, reason); - throw e2; - }); -}); - -asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' + - ' error should hit unhandledRejection: promise catch attached a' + - ' process.nextTick after rejection', function(done) { - const e = new Error(); - const e2 = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e2, reason); - assert.strictEqual(promise2, promise); - }); - const promise = new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - process.nextTick(function() { - promise2 = promise.then(assert.fail, function(reason) { - assert.strictEqual(e, reason); - throw e2; + +asyncTest( + tagUnwrap` + When re-throwing new errors in a promise catch, + only the re-thrown error should hit unhandledRejection: + original promise rejected async with setTimeout(,1) + `, + function(done) { + const e = new Error(); + const e2 = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e2, reason); + assert.strictEqual(promise2, promise); + }); + const promise2 = new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }).then(assert.fail, function(reason) { + assert.strictEqual(e, reason); + throw e2; + }); + }); + +asyncTest( + tagUnwrap` + When re-throwing new errors in a promise catch, + only the re-thrown error should hit unhandledRejection: + promise catch attached a process.nextTick after rejection + `, + function(done) { + const e = new Error(); + const e2 = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e2, reason); + assert.strictEqual(promise2, promise); + }); + const promise = new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + process.nextTick(function() { + promise2 = promise.then(assert.fail, function(reason) { + assert.strictEqual(e, reason); + throw e2; + }); }); - }); - }, 1); + }, 1); + }); + let promise2; }); - let promise2; -}); asyncTest( - 'unhandledRejection should not be triggered if a promise catch is' + - ' attached synchronously upon the promise\'s creation', + tagUnwrap` + unhandledRejection should not be triggered + if a promise catch is attached synchronously upon the promise's creation + `, function(done) { const e = new Error(); onUnhandledFail(done); Promise.reject(e).then(assert.fail, function() {}); - } -); + }); asyncTest( - 'unhandledRejection should not be triggered if a promise catch is' + - ' attached synchronously upon the promise\'s creation', + tagUnwrap` + unhandledRejection should not be triggered + if a promise catch is attached synchronously upon the promise's creation + `, function(done) { const e = new Error(); onUnhandledFail(done); new Promise(function(_, reject) { reject(e); }).then(assert.fail, function() {}); - } -); - -asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + - ' prevent unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); - const promise = Promise.reject(e); - process.nextTick(function() { - promise.then(assert.fail, function() {}); }); -}); -asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' + - ' prevent unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); - const promise = new Promise(function(_, reject) { - reject(e); +asyncTest( + tagUnwrap` + Attaching a promise catch in a process.nextTick + is soon enough to prevent unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); + const promise = Promise.reject(e); + process.nextTick(function() { + promise.then(assert.fail, function() {}); + }); }); - process.nextTick(function() { - promise.then(assert.fail, function() {}); + +asyncTest( + tagUnwrap` + Attaching a promise catch in a process.nextTick + is soon enough to prevent unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); + const promise = new Promise(function(_, reject) { + reject(e); + }); + process.nextTick(function() { + promise.then(assert.fail, function() {}); + }); }); -}); -asyncTest('While inside setImmediate, catching a rejected promise derived ' + - 'from returning a rejected promise in a fulfillment handler ' + - 'prevents unhandledRejection', function(done) { - onUnhandledFail(done); +asyncTest( + tagUnwrap` + While inside setImmediate, catching a rejected promise + derived from returning a rejected promise in a fulfillment handler + prevents unhandledRejection + `, + function(done) { + onUnhandledFail(done); - setImmediate(function() { - // reproduces on first tick and inside of setImmediate - Promise - .resolve('resolve') - .then(function() { - return Promise.reject('reject'); - }).catch(function(e) {}); + setImmediate(function() { + // reproduces on first tick and inside of setImmediate + Promise + .resolve('resolve') + .then(function() { + return Promise.reject('reject'); + }).catch(function(e) {}); + }); }); -}); // State adapation tests -asyncTest('catching a promise which is asynchronously rejected (via' + - 'resolution to an asynchronously-rejected promise) prevents' + - ' unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); - Promise.resolve().then(function() { - return new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); +asyncTest( + tagUnwrap` + catching a promise which is asynchronously rejected + (via resolution to an asynchronously-rejected promise) + prevents unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); + Promise.resolve().then(function() { + return new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }); + }).then(assert.fail, function(reason) { + assert.strictEqual(e, reason); }); - }).then(assert.fail, function(reason) { - assert.strictEqual(e, reason); - }); -}); - -asyncTest('Catching a rejected promise derived from throwing in a' + - ' fulfillment handler prevents unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); - Promise.resolve().then(function() { - throw e; - }).then(assert.fail, function(reason) { - assert.strictEqual(e, reason); - }); -}); - -asyncTest('Catching a rejected promise derived from returning a' + - ' synchronously-rejected promise in a fulfillment handler' + - ' prevents unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); - Promise.resolve().then(function() { - return Promise.reject(e); - }).then(assert.fail, function(reason) { - assert.strictEqual(e, reason); - }); -}); - -asyncTest('A rejected promise derived from returning an' + - ' asynchronously-rejected promise in a fulfillment handler' + - ' does trigger unhandledRejection', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(_promise, promise); - }); - const _promise = Promise.resolve().then(function() { - return new Promise(function(_, reject) { - setTimeout(function() { - reject(e); - }, 1); + }); + +asyncTest( + tagUnwrap` + Catching a rejected promise + derived from throwing in a fulfillment handler + prevents unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); + Promise.resolve().then(function() { + throw e; + }).then(assert.fail, function(reason) { + assert.strictEqual(e, reason); + }); + }); + +asyncTest( + tagUnwrap` + Catching a rejected promise derived from returning + a synchronously-rejected promise in a fulfillment handler + prevents unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); + Promise.resolve().then(function() { + return Promise.reject(e); + }).then(assert.fail, function(reason) { + assert.strictEqual(e, reason); }); }); -}); -asyncTest('A rejected promise derived from throwing in a fulfillment handler' + - ' does trigger unhandledRejection', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(_promise, promise); +asyncTest( + tagUnwrap` + A rejected promise derived from returning + an asynchronously-rejected promise in a fulfillment handler + does trigger unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(_promise, promise); + }); + const _promise = Promise.resolve().then(function() { + return new Promise(function(_, reject) { + setTimeout(function() { + reject(e); + }, 1); + }); + }); }); - const _promise = Promise.resolve().then(function() { - throw e; + +asyncTest( + tagUnwrap` + A rejected promise derived from throwing in a fulfillment handler + does trigger unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(_promise, promise); + }); + const _promise = Promise.resolve().then(function() { + throw e; + }); }); -}); asyncTest( - 'A rejected promise derived from returning a synchronously-rejected' + - ' promise in a fulfillment handler does trigger unhandledRejection', + tagUnwrap` + A rejected promise derived from returning + a synchronously-rejected promise in a fulfillment handler + does trigger unhandledRejection + `, function(done) { const e = new Error(); onUnhandledSucceed(done, function(reason, promise) { @@ -374,20 +433,26 @@ asyncTest( const _promise = Promise.resolve().then(function() { return Promise.reject(e); }); - } -); + }); // Combinations with Promise.all -asyncTest('Catching the Promise.all() of a collection that includes a' + - 'rejected promise prevents unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); - Promise.all([Promise.reject(e)]).then(assert.fail, function() {}); -}); +asyncTest( + tagUnwrap` + Catching the Promise.all() of a collection that includes a rejected promise + prevents unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); + Promise.all([Promise.reject(e)]).then(assert.fail, function() {}); + }); asyncTest( - 'Catching the Promise.all() of a collection that includes a ' + - 'nextTick-async rejected promise prevents unhandledRejection', + tagUnwrap` + Catching the Promise.all() + of a collection that includes a nextTick-async rejected promise + prevents unhandledRejection + `, function(done) { const e = new Error(); onUnhandledFail(done); @@ -400,72 +465,64 @@ asyncTest( process.nextTick(function() { p.then(assert.fail, function() {}); }); - } -); - -asyncTest('Failing to catch the Promise.all() of a collection that includes' + - ' a rejected promise triggers unhandledRejection for the returned' + - ' promise, not the passed promise', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(p, promise); }); - const p = Promise.all([Promise.reject(e)]); -}); -asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' + - ' unhandledRejection + rejectionHandled pair', function(done) { - clean(); - const unhandledPromises = []; - const e = new Error(); - process.on('unhandledRejection', function(reason, promise) { - assert.strictEqual(e, reason); - unhandledPromises.push(promise); - }); - process.on('rejectionHandled', function(promise) { - assert.strictEqual(1, unhandledPromises.length); - assert.strictEqual(unhandledPromises[0], promise); - assert.strictEqual(thePromise, promise); - done(); +asyncTest( + tagUnwrap` + Failing to catch the Promise.all() + of a collection that includes a rejected promise + triggers unhandledRejection for the returned promise, not the passed promise + `, + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(p, promise); + }); + const p = Promise.all([Promise.reject(e)]); }); - const thePromise = new Promise(function() { - throw e; - }); - setTimeout(function() { - thePromise.then(assert.fail, function(reason) { +asyncTest( + tagUnwrap` + Waiting setTimeout(, 10) to catch a promise + causes an unhandledRejection + rejectionHandled pair + `, + function(done) { + clean(); + const unhandledPromises = []; + const e = new Error(); + process.on('unhandledRejection', function(reason, promise) { assert.strictEqual(e, reason); + unhandledPromises.push(promise); + }); + process.on('rejectionHandled', function(promise) { + assert.strictEqual(1, unhandledPromises.length); + assert.strictEqual(unhandledPromises[0], promise); + assert.strictEqual(thePromise, promise); + done(); }); - }, 10); -}); - -asyncTest('Waiting for some combination of process.nextTick + promise' + - ' microtasks to attach a catch handler is still soon enough to' + - ' prevent unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); - - const a = Promise.reject(e); - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - a.catch(function() {}); - }); - }); + const thePromise = new Promise(function() { + throw e; }); + setTimeout(function() { + thePromise.then(assert.fail, function(reason) { + assert.strictEqual(e, reason); + }); + }, 10); }); -}); -asyncTest('Waiting for some combination of process.nextTick + promise' + - ' microtasks to attach a catch handler is still soon enough to ' + - 'prevent unhandledRejection: inside setImmediate', function(done) { - const e = new Error(); - onUnhandledFail(done); +asyncTest( + tagUnwrap` + Waiting for some combination of process.nextTick + promise microtasks + to attach a catch handler + is still soon enough to prevent unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); + - setImmediate(function() { const a = Promise.reject(e); process.nextTick(function() { Promise.resolve().then(function() { @@ -477,51 +534,84 @@ asyncTest('Waiting for some combination of process.nextTick + promise' + }); }); }); -}); -asyncTest('Waiting for some combination of process.nextTick + promise ' + - 'microtasks to attach a catch handler is still soon enough to ' + - 'prevent unhandledRejection: inside setTimeout', function(done) { - const e = new Error(); - onUnhandledFail(done); +asyncTest( + tagUnwrap` + Waiting for some combination of process.nextTick + promise microtasks + to attach a catch handler + is still soon enough to prevent unhandledRejection: inside setImmediate + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); - setTimeout(function() { - const a = Promise.reject(e); - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - a.catch(function() {}); + setImmediate(function() { + const a = Promise.reject(e); + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + a.catch(function() {}); + }); }); }); }); }); - }, 0); -}); + }); + +asyncTest( + tagUnwrap` + Waiting for some combination of process.nextTick + promise microtasks + to attach a catch handler + is still soon enough to prevent unhandledRejection: inside setTimeout + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); -asyncTest('Waiting for some combination of promise microtasks + ' + - 'process.nextTick to attach a catch handler is still soon enough' + - ' to prevent unhandledRejection', function(done) { - const e = new Error(); - onUnhandledFail(done); + setTimeout(function() { + const a = Promise.reject(e); + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + a.catch(function() {}); + }); + }); + }); + }); + }, 0); + }); +asyncTest( + tagUnwrap` + Waiting for some combination of promise microtasks + process.nextTick + to attach a catch handler + is still soon enough to prevent unhandledRejection + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); - const a = Promise.reject(e); - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - a.catch(function() {}); + + const a = Promise.reject(e); + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + a.catch(function() {}); + }); }); }); }); }); -}); asyncTest( - 'Waiting for some combination of promise microtasks +' + - ' process.nextTick to attach a catch handler is still soon enough' + - ' to prevent unhandledRejection: inside setImmediate', + tagUnwrap` + Waiting for some combination of promise microtasks + process.nextTick + to attach a catch handler + is still soon enough to prevent unhandledRejection: inside setImmediate + `, function(done) { const e = new Error(); onUnhandledFail(done); @@ -538,90 +628,107 @@ asyncTest( }); }); }); - } -); + }); -asyncTest('Waiting for some combination of promise microtasks +' + - ' process.nextTick to attach a catch handler is still soon enough' + - ' to prevent unhandledRejection: inside setTimeout', function(done) { - const e = new Error(); - onUnhandledFail(done); +asyncTest( + tagUnwrap` + Waiting for some combination of promise microtasks + process.nextTick + to attach a catch handler + is still soon enough to prevent unhandledRejection: inside setTimeout + `, + function(done) { + const e = new Error(); + onUnhandledFail(done); - setTimeout(function() { - const a = Promise.reject(e); - Promise.resolve().then(function() { - process.nextTick(function() { - Promise.resolve().then(function() { - process.nextTick(function() { - a.catch(function() {}); + setTimeout(function() { + const a = Promise.reject(e); + Promise.resolve().then(function() { + process.nextTick(function() { + Promise.resolve().then(function() { + process.nextTick(function() { + a.catch(function() {}); + }); }); }); }); - }); - }, 0); -}); - -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + - ' handler; unhandledRejection will be triggered in that case.' + - ' (setImmediate before promise creation/rejection)', function(done) { - const e = new Error(); - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(e, reason); - assert.strictEqual(p, promise); + }, 0); }); - const p = Promise.reject(e); - setImmediate(function() { - Promise.resolve().then(function() { - p.catch(function() {}); + +asyncTest( + tagUnwrap` + setImmediate + promise microtasks is too late to attach a catch handler; + unhandledRejection will be triggered in that case + (setImmediate before promise creation/rejection) + `, + function(done) { + const e = new Error(); + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(e, reason); + assert.strictEqual(p, promise); + }); + const p = Promise.reject(e); + setImmediate(function() { + Promise.resolve().then(function() { + p.catch(function() {}); + }); }); }); -}); -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + - ' handler; unhandledRejection will be triggered in that case' + - ' (setImmediate before promise creation/rejection)', function(done) { - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(undefined, reason); - assert.strictEqual(p, promise); - }); - setImmediate(function() { - Promise.resolve().then(function() { +asyncTest( + tagUnwrap` + setImmediate + promise microtasks is too late to attach a catch handler; + unhandledRejection will be triggered in that case + (setImmediate before promise creation/rejection) + `, + function(done) { + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(undefined, reason); + assert.strictEqual(p, promise); + }); + setImmediate(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { - p.catch(function() {}); + Promise.resolve().then(function() { + p.catch(function() {}); + }); }); }); }); }); + const p = Promise.reject(); }); - const p = Promise.reject(); -}); -asyncTest('setImmediate + promise microtasks is too late to attach a catch' + - ' handler; unhandledRejection will be triggered in that case' + - ' (setImmediate after promise creation/rejection)', function(done) { - onUnhandledSucceed(done, function(reason, promise) { - assert.strictEqual(undefined, reason); - assert.strictEqual(p, promise); - }); - const p = Promise.reject(); - setImmediate(function() { - Promise.resolve().then(function() { +asyncTest( + tagUnwrap` + setImmediate + promise microtasks is too late to attach a catch handler; + unhandledRejection will be triggered in that case + (setImmediate after promise creation/rejection) + `, + function(done) { + onUnhandledSucceed(done, function(reason, promise) { + assert.strictEqual(undefined, reason); + assert.strictEqual(p, promise); + }); + const p = Promise.reject(); + setImmediate(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { Promise.resolve().then(function() { - p.catch(function() {}); + Promise.resolve().then(function() { + p.catch(function() {}); + }); }); }); }); }); }); -}); asyncTest( - 'Promise unhandledRejection handler does not interfere with domain' + - ' error handlers being given exceptions thrown from nextTick.', + tagUnwrap` + Promise unhandledRejection handler does not interfere + with domain error handlers being given exceptions thrown from nextTick. + `, function(done) { const d = domain.create(); let domainReceivedError; @@ -641,47 +748,51 @@ asyncTest( throw domainError; }); }); - } -); + }); -asyncTest('nextTick is immediately scheduled when called inside an event' + - ' handler', function(done) { - clean(); - const e = new Error('error'); - process.on('unhandledRejection', function(reason, promise) { - const order = []; - process.nextTick(function() { - order.push(1); +asyncTest( + 'nextTick is immediately scheduled when called inside an event handler', + function(done) { + clean(); + const e = new Error('error'); + process.on('unhandledRejection', function(reason, promise) { + const order = []; + process.nextTick(function() { + order.push(1); + }); + setTimeout(function() { + order.push(2); + assert.deepStrictEqual([1, 2], order); + done(); + }, 1); }); - setTimeout(function() { - order.push(2); - assert.deepStrictEqual([1, 2], order); - done(); - }, 1); + Promise.reject(e); }); - Promise.reject(e); -}); -asyncTest('Throwing an error inside a rejectionHandled handler goes to' + - ' unhandledException, and does not cause .catch() to throw an' + - 'exception', function(done) { - clean(); - const e = new Error(); - const e2 = new Error(); - const tearDownException = setupException(function(err) { - assert.strictEqual(e2, err); - tearDownException(); - done(); - }); - process.on('rejectionHandled', function() { - throw e2; +asyncTest( + tagUnwrap` + Throwing an error inside a rejectionHandled handler + goes to unhandledException, + and does not cause .catch() to throw an exception + `, + function(done) { + clean(); + const e = new Error(); + const e2 = new Error(); + const tearDownException = setupException(function(err) { + assert.strictEqual(e2, err); + tearDownException(); + done(); + }); + process.on('rejectionHandled', function() { + throw e2; + }); + const p = Promise.reject(e); + setTimeout(function() { + try { + p.catch(function() {}); + } catch (e) { + done(new Error('fail')); + } + }, 1); }); - const p = Promise.reject(e); - setTimeout(function() { - try { - p.catch(function() {}); - } catch (e) { - done(new Error('fail')); - } - }, 1); -}); diff --git a/test/parallel/test-promises-unhandled-symbol-rejections.js b/test/parallel/test-promises-unhandled-symbol-rejections.js index a60a5f2e8aac30..c453417e794679 100644 --- a/test/parallel/test-promises-unhandled-symbol-rejections.js +++ b/test/parallel/test-promises-unhandled-symbol-rejections.js @@ -1,13 +1,13 @@ 'use strict'; const common = require('../common'); -const expectedDeprecationWarning = 'Unhandled promise rejections are ' + - 'deprecated. In the future, promise ' + - 'rejections that are not handled will ' + - 'terminate the Node.js process with a ' + - 'non-zero exit code.'; -const expectedPromiseWarning = 'Unhandled promise rejection (rejection id: ' + - '1): Symbol()'; +const expectedDeprecationWarning = common.tagUnwrap` + Unhandled promise rejections are deprecated. + In the future, promise rejections that are not handled + will terminate the Node.js process with a non-zero exit code. +`; +const expectedPromiseWarning = + 'Unhandled promise rejection (rejection id: 1): Symbol()'; common.expectWarning({ DeprecationWarning: expectedDeprecationWarning, diff --git a/test/parallel/test-punycode.js b/test/parallel/test-punycode.js index 334fceadbe9983..21688ffd27de35 100644 --- a/test/parallel/test-punycode.js +++ b/test/parallel/test-punycode.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagGlue } = require('../common'); const punycode = require('punycode'); const assert = require('assert'); @@ -62,8 +62,10 @@ const tests = [ // (A) Arabic (Egyptian) { encoded: 'egbpdaj6bu4bxfgehfvwxn', - decoded: '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645' + - '\u0648\u0634\u0639\u0631\u0628\u064A\u061F' + decoded: tagGlue` + \u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644 + \u0645\u0648\u0634\u0639\u0631\u0628\u064A\u061F + ` }, // (B) Chinese (simplified) @@ -81,65 +83,81 @@ const tests = [ // (D) Czech: Proprostnemluvesky { encoded: 'Proprostnemluvesky-uyb24dma41a', - decoded: '\u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074\u011B' + - '\u006E\u0065\u006D\u006C\u0075\u0076\u00ED\u010D\u0065\u0073\u006B\u0079' + decoded: tagGlue` + \u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074\u011B\u006E + \u0065\u006D\u006C\u0075\u0076\u00ED\u010D\u0065\u0073\u006B\u0079 + ` }, // (E) Hebrew { encoded: '4dbcagdahymbxekheh6e0a7fei0b', - decoded: '\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC' + - '\u05D0\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA' + decoded: tagGlue` + \u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC\u05D0 + \u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA + ` }, // (F) Hindi (Devanagari) { encoded: 'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd', - decoded: '\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926' + - '\u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C' + - '\u094B\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902' + decoded: tagGlue` + \u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926 + \u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902 + \u092C\u094B\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902 + ` }, // (G) Japanese (kanji and hiragana) { encoded: 'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa', - decoded: '\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71' + - '\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B' + decoded: tagGlue` + \u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092 + \u8A71\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B + ` }, // (H) Korean (Hangul syllables) { - encoded: '989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879' + - 'ccm6fea98c', - decoded: '\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C' + - '\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098' + - '\uC88B\uC744\uAE4C' + encoded: + '989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c', + decoded: tagGlue` + \uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4 + \uC774\uD55C\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C + \uB2E4\uBA74\uC5BC\uB9C8\uB098\uC88B\uC744\uAE4C + ` }, // (I) Russian (Cyrillic) { encoded: 'b1abfaaepdrnnbgefbadotcwatmq2g4l', - decoded: '\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D' + - '\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F' + - '\u043E\u0440\u0443\u0441\u0441\u043A\u0438' + decoded: tagGlue` + \u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E + \u043D\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440 + \u044F\u0442\u043F\u043E\u0440\u0443\u0441\u0441\u043A\u0438 + ` }, // (J) Spanish: PorqunopuedensimplementehablarenEspaol { encoded: 'PorqunopuedensimplementehablarenEspaol-fmd56a', - decoded: '\u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070\u0075' + - '\u0065\u0064\u0065\u006E\u0073\u0069\u006D\u0070\u006C\u0065\u006D' + - '\u0065\u006E\u0074\u0065\u0068\u0061\u0062\u006C\u0061\u0072\u0065' + - '\u006E\u0045\u0073\u0070\u0061\u00F1\u006F\u006C' + decoded: tagGlue` + \u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070\u0075 + \u0065\u0064\u0065\u006E\u0073\u0069\u006D\u0070\u006C\u0065 + \u006D\u0065\u006E\u0074\u0065\u0068\u0061\u0062\u006C\u0061 + \u0072\u0065\u006E\u0045\u0073\u0070\u0061\u00F1\u006F\u006C + ` }, // (K) Vietnamese: Tisaohkhngth // chnitingVit { encoded: 'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g', - decoded: '\u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B\u0068' + - '\u00F4\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068\u1EC9\u006E\u00F3' + - '\u0069\u0074\u0069\u1EBF\u006E\u0067\u0056\u0069\u1EC7\u0074' + decoded: tagGlue` + \u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B\u0068 + \u00F4\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068\u1EC9\u006E + \u00F3\u0069\u0074\u0069\u1EBF\u006E\u0067\u0056\u0069\u1EC7\u0074 + ` }, // (L) 3B @@ -151,17 +169,21 @@ const tests = [ // (M) -with-SUPER-MONKEYS { encoded: '-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n', - decoded: '\u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069\u0074\u0068' + - '\u002D\u0053\u0055\u0050\u0045\u0052\u002D\u004D\u004F\u004E\u004B' + - '\u0045\u0059\u0053' + decoded: tagGlue` + \u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069 + \u0074\u0068\u002D\u0053\u0055\u0050\u0045\u0052 + \u002D\u004D\u004F\u004E\u004B\u0045\u0059\u0053 + ` }, // (N) Hello-Another-Way- { encoded: 'Hello-Another-Way--fc4qua05auwb3674vfr0b', - decoded: '\u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E\u006F\u0074' + - '\u0068\u0065\u0072\u002D\u0057\u0061\u0079\u002D\u305D\u308C\u305E' + - '\u308C\u306E\u5834\u6240' + decoded: tagGlue` + \u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E + \u006F\u0074\u0068\u0065\u0072\u002D\u0057\u0061 + \u0079\u002D\u305D\u308C\u305E\u308C\u306E\u5834\u6240 + ` }, // (O) 2 @@ -173,8 +195,10 @@ const tests = [ // (P) MajiKoi5 { encoded: 'MajiKoi5-783gue6qz075azm5e', - decoded: '\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059\u308B' + - '\u0035\u79D2\u524D' + decoded: tagGlue` + \u004D\u0061\u006A\u0069\u3067\u004B + \u006F\u0069\u3059\u308B\u0035\u79D2\u524D + ` }, // (Q) de @@ -192,8 +216,8 @@ const tests = [ // (S) -> $1.00 <- { encoded: '-> $1.00 <--', - decoded: '\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C' + - '\u002D' + decoded: + '\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C\u002D' } ]; diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index 10f166562ba6c1..e684b32d7eb5d6 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagLFy } = require('../common'); const assert = require('assert'); const inspect = require('util').inspect; @@ -168,17 +168,21 @@ function check(actual, expected, input) { const expectedKeys = Object.keys(expected).sort(); let msg; if (typeof input === 'string') { - msg = `Input: ${inspect(input)}\n` + - `Actual keys: ${inspect(actualKeys)}\n` + - `Expected keys: ${inspect(expectedKeys)}`; + msg = tagLFy` + Input: ${inspect(input)} + Actual keys: ${inspect(actualKeys)} + Expected keys: ${inspect(expectedKeys)} + `; } assert.deepStrictEqual(actualKeys, expectedKeys, msg); expectedKeys.forEach(function(key) { if (typeof input === 'string') { - msg = `Input: ${inspect(input)}\n` + - `Key: ${inspect(key)}\n` + - `Actual value: ${inspect(actual[key])}\n` + - `Expected value: ${inspect(expected[key])}`; + msg = tagLFy` + Input: ${inspect(input)} + Key: ${inspect(key)} + Actual value: ${inspect(actual[key])} + Expected value: ${inspect(expected[key])} + `; } else { msg = undefined; } @@ -335,8 +339,8 @@ assert.strictEqual( } { - const b = qs.unescapeBuffer('%d3%f2Ug%1f6v%24%5e%98%cb' + - '%0d%ac%a2%2f%9d%eb%d8%a2%e6'); + const b = qs.unescapeBuffer( + '%d3%f2Ug%1f6v%24%5e%98%cb%0d%ac%a2%2f%9d%eb%d8%a2%e6'); // assert.strictEqual(0xd3, b[0]); assert.strictEqual(0xf2, b[1]); diff --git a/test/parallel/test-readline-undefined-columns.js b/test/parallel/test-readline-undefined-columns.js index 40fe2c16d609e9..b848fd33cf5517 100644 --- a/test/parallel/test-readline-undefined-columns.js +++ b/test/parallel/test-readline-undefined-columns.js @@ -27,9 +27,11 @@ oStream.on('data', function(data) { }); oStream.on('end', common.mustCall(() => { - const expect = 'process.stdout\r\n' + - 'process.stdin\r\n' + - 'process.stderr'; + const expect = common.tagCRLFy` + process.stdout + process.stdin + process.stderr + `; assert(new RegExp(expect).test(output)); })); diff --git a/test/parallel/test-repl-domain.js b/test/parallel/test-repl-domain.js index ff36eeaf3a4af4..32cbb58abf7749 100644 --- a/test/parallel/test-repl-domain.js +++ b/test/parallel/test-repl-domain.js @@ -38,7 +38,9 @@ putIn.write = function(data) { } }; -putIn.run([ - 'require("domain").create().on("error", function() { console.log("OK") })' + - '.run(function() { throw new Error("threw") })' -]); +putIn.run([common.tagGlue` + require("domain") + .create() + .on("error", function() { console.log("OK") }) + .run(function() { throw new Error("threw") }) +`]); diff --git a/test/parallel/test-repl-editor.js b/test/parallel/test-repl-editor.js index 678d6d5c6d94f8..8dc676732acd5a 100644 --- a/test/parallel/test-repl-editor.js +++ b/test/parallel/test-repl-editor.js @@ -16,9 +16,12 @@ function run({input, output, event, checkTerminalCodes = true}) { stream.write = (msg) => found += msg.replace('\r', ''); - let expected = `${terminalCode}.editor\n` + - '// Entering editor mode (^D to finish, ^C to cancel)\n' + - `${input}${output}\n${terminalCode}`; + let expected = common.tagLFy` + ${terminalCode}.editor + // Entering editor mode (^D to finish, ^C to cancel) + ${input}${output} + ${terminalCode} + `; const replServer = repl.start({ prompt: '> ', diff --git a/test/parallel/test-repl-history-perm.js b/test/parallel/test-repl-history-perm.js index ebca7c9725652f..0747383eedb9bb 100644 --- a/test/parallel/test-repl-history-perm.js +++ b/test/parallel/test-repl-history-perm.js @@ -4,9 +4,10 @@ const common = require('../common'); if (common.isWindows) { - common.skip('Win32 uses ACLs for file permissions, ' + - 'modes are always 0666 and says nothing about group/other ' + - 'read access.'); + common.skip(common.tagUnwrap` + Win32 uses ACLs for file permissions, + modes are always 0666 and says nothing about group/other read access. + `); return; } diff --git a/test/parallel/test-repl-persistent-history.js b/test/parallel/test-repl-persistent-history.js index 2c31a13119fe2e..dd344861b82098 100644 --- a/test/parallel/test-repl-persistent-history.js +++ b/test/parallel/test-repl-persistent-history.js @@ -10,6 +10,8 @@ const fs = require('fs'); const path = require('path'); const os = require('os'); +const { tagLFy } = common; + common.refreshTmpDir(); // Mock os.homedir() @@ -53,20 +55,38 @@ const ENTER = { name: 'enter' }; const CLEAR = { ctrl: true, name: 'u' }; // Common message bits const prompt = '> '; -const replDisabled = '\nPersistent history support disabled. Set the ' + - 'NODE_REPL_HISTORY environment\nvariable to a valid, ' + - 'user-writable path to enable.\n'; -const convertMsg = '\nConverting old JSON repl history to line-separated ' + - 'history.\nThe new repl history file can be found at ' + - path.join(common.tmpDir, '.node_repl_history') + '.\n'; -const homedirErr = '\nError: Could not get the home directory.\n' + - 'REPL session history will not be persisted.\n'; -const replFailedRead = '\nError: Could not open history file.\n' + - 'REPL session history will not be persisted.\n'; -const sameHistoryFilePaths = '\nThe old repl history file has the same name ' + - 'and location as the new one i.e., ' + - path.join(common.tmpDir, '.node_repl_history') + - ' and is empty.\nUsing it as is.\n'; +const replDisabled = tagLFy` + + Persistent history support disabled. Set the NODE_REPL_HISTORY environment + variable to a valid, user-writable path to enable. + +`; +const convertMsg = tagLFy` + + Converting old JSON repl history to line-separated history. + The new repl history file can be found at ${ + path.join(common.tmpDir, '.node_repl_history')}. + +`; +const homedirErr = tagLFy` + + Error: Could not get the home directory. + REPL session history will not be persisted. + +`; +const replFailedRead = tagLFy` + + Error: Could not open history file. + REPL session history will not be persisted. + +`; +const sameHistoryFilePaths = tagLFy` + +The old repl history file has the same name and location as the new one i.e., ${ +path.join(common.tmpDir, '.node_repl_history')} and is empty. +Using it as is. + +`; // File paths const fixtures = common.fixturesDir; const historyFixturePath = path.join(fixtures, '.node_repl_history'); diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 86dd96d55072cb..33f5f6de8d26f7 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -32,9 +32,11 @@ const message = 'Read, Eval, Print Loop'; const prompt_unix = 'node via Unix socket> '; const prompt_tcp = 'node via TCP socket> '; const prompt_multiline = '... '; -const prompt_npm = 'npm should be run outside of the ' + - 'node repl, in your normal shell.\n' + - '(Press Control-D to exit.)\n'; +const prompt_npm = common.tagLFy` + npm should be run outside of the node repl, in your normal shell. + (Press Control-D to exit.) + +`; const expect_npm = prompt_npm + prompt_unix; let server_tcp, server_unix, client_tcp, client_unix, replServer; diff --git a/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js b/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js index 43245e22de8b52..b2bb2a2235a8b9 100644 --- a/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js +++ b/test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js @@ -19,13 +19,14 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -/* eslint-disable max-len */ 'use strict'; const common = require('../common'); const assert = require('assert'); -const content = require(common.fixturesDir + - '/json-with-directory-name-module/module-stub/one-trailing-slash/two/three.js'); +const content = require(common.tagGlue` + ${common.fixturesDir} + /json-with-directory-name-module/module-stub/one-trailing-slash/two/three.js +`); assert.notStrictEqual(content.rocko, 'artischocko'); assert.strictEqual(content, 'hello from module-stub!'); diff --git a/test/parallel/test-require-extensions-same-filename-as-dir.js b/test/parallel/test-require-extensions-same-filename-as-dir.js index 610b8d1ce26584..dc217a769fa77f 100644 --- a/test/parallel/test-require-extensions-same-filename-as-dir.js +++ b/test/parallel/test-require-extensions-same-filename-as-dir.js @@ -23,8 +23,10 @@ const common = require('../common'); const assert = require('assert'); -const content = require(common.fixturesDir + - '/json-with-directory-name-module/module-stub/one/two/three.js'); +const content = require(common.tagGlue` + ${common.fixturesDir} + /json-with-directory-name-module/module-stub/one/two/three.js +`); assert.notStrictEqual(content.rocko, 'artischocko'); assert.strictEqual(content, 'hello from module-stub!'); diff --git a/test/parallel/test-stdout-close-catch.js b/test/parallel/test-stdout-close-catch.js index 322ed76aee8fc0..17a679fbb06166 100644 --- a/test/parallel/test-stdout-close-catch.js +++ b/test/parallel/test-stdout-close-catch.js @@ -6,10 +6,12 @@ const child_process = require('child_process'); const testScript = path.join(common.fixturesDir, 'catch-stdout-error.js'); -const cmd = JSON.stringify(process.execPath) + ' ' + - JSON.stringify(testScript) + ' | ' + - JSON.stringify(process.execPath) + ' ' + - '-pe "process.stdin.on(\'data\' , () => process.exit(1))"'; +const cmd = common.tagUnwrap` + ${JSON.stringify(process.execPath)} + ${JSON.stringify(testScript)} | + ${JSON.stringify(process.execPath)} + -pe "process.stdin.on('data' , () => process.exit(1))" +`; const child = child_process.exec(cmd); let output = ''; diff --git a/test/parallel/test-string-decoder.js b/test/parallel/test-string-decoder.js index 8de0f7ba160ac0..f48cc15496edb4 100644 --- a/test/parallel/test-string-decoder.js +++ b/test/parallel/test-string-decoder.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagLFy } = require('../common'); const assert = require('assert'); const inspect = require('util').inspect; const StringDecoder = require('string_decoder').StringDecoder; @@ -152,12 +152,12 @@ function test(encoding, input, expected, singleSequence) { }); output += decoder.end(); if (output !== expected) { - const message = - 'Expected "' + unicodeEscape(expected) + '", ' + - 'but got "' + unicodeEscape(output) + '"\n' + - 'input: ' + input.toString('hex').match(/.{2}/g) + '\n' + - 'Write sequence: ' + JSON.stringify(sequence) + '\n' + - 'Full Decoder State: ' + inspect(decoder); + const message = tagLFy` + Expected "${unicodeEscape(expected)}", but got "${unicodeEscape(output)}" + input: ${input.toString('hex').match(/.{2}/g)} + Write sequence: ${JSON.stringify(sequence)} + Full Decoder State: ${inspect(decoder)} + `; assert.fail(output, expected, message); } }); diff --git a/test/parallel/test-tls-0-dns-altname.js b/test/parallel/test-tls-0-dns-altname.js index 7ac40eeda162b6..624690e7a5298c 100644 --- a/test/parallel/test-tls-0-dns-altname.js +++ b/test/parallel/test-tls-0-dns-altname.js @@ -46,12 +46,13 @@ const server = tls.createServer({ rejectUnauthorized: false }, common.mustCall(function() { const cert = c.getPeerCertificate(); - assert.strictEqual(cert.subjectaltname, - 'DNS:good.example.org\0.evil.example.com, ' + - 'DNS:just-another.example.com, ' + - 'IP Address:8.8.8.8, ' + - 'IP Address:8.8.4.4, ' + - 'DNS:last.example.com'); + assert.strictEqual(cert.subjectaltname, common.tagUnwrap` + DNS:good.example.org\0.evil.example.com, + DNS:just-another.example.com, + IP Address:8.8.8.8, + IP Address:8.8.4.4, + DNS:last.example.com + `); c.write('ok'); })); })); diff --git a/test/parallel/test-tls-over-http-tunnel.js b/test/parallel/test-tls-over-http-tunnel.js index 638886e92e92c9..af1300d2b3e6a8 100644 --- a/test/parallel/test-tls-over-http-tunnel.js +++ b/test/parallel/test-tls-over-http-tunnel.js @@ -33,6 +33,8 @@ const fs = require('fs'); const net = require('net'); const http = require('http'); +const { tagCRLFy } = common; + let gotRequest = false; const key = fs.readFileSync(`${common.fixturesDir}/keys/agent1-key.pem`); @@ -60,11 +62,14 @@ const proxy = net.createServer(function(clientSocket) { clientSocket.on('data', function(chunk) { if (!serverSocket) { // Verify the CONNECT request - assert.strictEqual(`CONNECT localhost:${server.address().port} ` + - 'HTTP/1.1\r\n' + - 'Proxy-Connections: keep-alive\r\n' + - `Host: localhost:${proxy.address().port}\r\n` + - 'Connection: close\r\n\r\n', + assert.strictEqual(tagCRLFy` + CONNECT localhost:${server.address().port} HTTP/1.1 + Proxy-Connections: keep-alive + Host: localhost:${proxy.address().port} + Connection: close + + + `, chunk.toString()); console.log('PROXY: got CONNECT request'); @@ -75,9 +80,14 @@ const proxy = net.createServer(function(clientSocket) { console.log('PROXY: replying to client CONNECT request'); // Send the response - clientSocket.write('HTTP/1.1 200 OK\r\nProxy-Connections: keep' + - '-alive\r\nConnections: keep-alive\r\nVia: ' + - `localhost:${proxy.address().port}\r\n\r\n`); + clientSocket.write(tagCRLFy` + HTTP/1.1 200 OK + Proxy-Connections: keep-alive + Connections: keep-alive + Via: localhost:${proxy.address().port} + + + `); }); serverSocket.on('data', function(chunk) { diff --git a/test/parallel/test-tls-parse-cert-string.js b/test/parallel/test-tls-parse-cert-string.js index c6cdbf2e36e677..d7cb58dfd8d2e6 100644 --- a/test/parallel/test-tls-parse-cert-string.js +++ b/test/parallel/test-tls-parse-cert-string.js @@ -8,9 +8,18 @@ if (!common.hasCrypto) { const assert = require('assert'); const tls = require('tls'); +const { tagLFy } = common; + { - const singles = 'C=US\nST=CA\nL=SF\nO=Node.js Foundation\nOU=Node.js\n' + - 'CN=ca1\nemailAddress=ry@clouds.org'; + const singles = tagLFy` + C=US + ST=CA + L=SF + O=Node.js Foundation + OU=Node.js + CN=ca1 + emailAddress=ry@clouds.org + `; const singlesOut = tls.parseCertString(singles); assert.deepStrictEqual(singlesOut, { C: 'US', @@ -24,8 +33,11 @@ const tls = require('tls'); } { - const doubles = 'OU=Domain Control Validated\nOU=PositiveSSL Wildcard\n' + - 'CN=*.nodejs.org'; + const doubles = tagLFy` + OU=Domain Control Validated + OU=PositiveSSL Wildcard + CN=*.nodejs.org + `; const doublesOut = tls.parseCertString(doubles); assert.deepStrictEqual(doublesOut, { OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ], diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index c8ee5f72edbe50..8208a7f9b5acec 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -25,6 +25,8 @@ const assert = require('assert'); const util = require('util'); const vm = require('vm'); +const { tagLFy } = common; + assert.strictEqual(util.inspect(1), '1'); assert.strictEqual(util.inspect(false), 'false'); assert.strictEqual(util.inspect(''), "''"); @@ -105,30 +107,33 @@ for (const showHidden of [true, false]) { util.inspect(ab, showHidden), 'ArrayBuffer { byteLength: 4 }' ); - assert.strictEqual(util.inspect(new DataView(ab, 1, 2), showHidden), - 'DataView {\n' + - ' byteLength: 2,\n' + - ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + assert.strictEqual(util.inspect(new DataView(ab, 1, 2), showHidden), tagLFy` + DataView { + byteLength: 2, + byteOffset: 1, + buffer: ArrayBuffer { byteLength: 4 } } + `); assert.strictEqual( util.inspect(ab, showHidden), 'ArrayBuffer { byteLength: 4 }' ); - assert.strictEqual(util.inspect(dv, showHidden), - 'DataView {\n' + - ' byteLength: 2,\n' + - ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + assert.strictEqual(util.inspect(dv, showHidden), tagLFy` + DataView { + byteLength: 2, + byteOffset: 1, + buffer: ArrayBuffer { byteLength: 4 } } + `); ab.x = 42; dv.y = 1337; assert.strictEqual(util.inspect(ab, showHidden), 'ArrayBuffer { byteLength: 4, x: 42 }'); - assert.strictEqual(util.inspect(dv, showHidden), - 'DataView {\n' + - ' byteLength: 2,\n' + - ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4, x: 42 },\n' + - ' y: 1337 }'); + assert.strictEqual(util.inspect(dv, showHidden), tagLFy` + DataView { + byteLength: 2, + byteOffset: 1, + buffer: ArrayBuffer { byteLength: 4, x: 42 }, + y: 1337 } + `); } // Now do the same checks but from a different context @@ -139,30 +144,33 @@ for (const showHidden of [true, false]) { util.inspect(ab, showHidden), 'ArrayBuffer { byteLength: 4 }' ); - assert.strictEqual(util.inspect(new DataView(ab, 1, 2), showHidden), - 'DataView {\n' + - ' byteLength: 2,\n' + - ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + assert.strictEqual(util.inspect(new DataView(ab, 1, 2), showHidden), tagLFy` + DataView { + byteLength: 2, + byteOffset: 1, + buffer: ArrayBuffer { byteLength: 4 } } + `); assert.strictEqual( util.inspect(ab, showHidden), 'ArrayBuffer { byteLength: 4 }' ); - assert.strictEqual(util.inspect(dv, showHidden), - 'DataView {\n' + - ' byteLength: 2,\n' + - ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4 } }'); + assert.strictEqual(util.inspect(dv, showHidden), tagLFy` + DataView { + byteLength: 2, + byteOffset: 1, + buffer: ArrayBuffer { byteLength: 4 } } + `); ab.x = 42; dv.y = 1337; assert.strictEqual(util.inspect(ab, showHidden), 'ArrayBuffer { byteLength: 4, x: 42 }'); - assert.strictEqual(util.inspect(dv, showHidden), - 'DataView {\n' + - ' byteLength: 2,\n' + - ' byteOffset: 1,\n' + - ' buffer: ArrayBuffer { byteLength: 4, x: 42 },\n' + - ' y: 1337 }'); + assert.strictEqual(util.inspect(dv, showHidden), tagLFy` + DataView { + byteLength: 2, + byteOffset: 1, + buffer: ArrayBuffer { byteLength: 4, x: 42 }, + y: 1337 } + `); } @@ -182,14 +190,16 @@ for (const showHidden of [true, false]) { array[1] = 97; assert.strictEqual( util.inspect(array, true), - `${constructor.name} [\n` + - ' 65,\n' + - ' 97,\n' + - ` [BYTES_PER_ELEMENT]: ${constructor.BYTES_PER_ELEMENT},\n` + - ` [length]: ${length},\n` + - ` [byteLength]: ${byteLength},\n` + - ' [byteOffset]: 0,\n' + - ` [buffer]: ArrayBuffer { byteLength: ${byteLength} } ]`); + tagLFy` + ${constructor.name} [ + 65, + 97, + [BYTES_PER_ELEMENT]: ${constructor.BYTES_PER_ELEMENT}, + [length]: ${length}, + [byteLength]: ${byteLength}, + [byteOffset]: 0, + [buffer]: ArrayBuffer { byteLength: ${byteLength} } ] + `); assert.strictEqual( util.inspect(array, false), `${constructor.name} [ 65, 97 ]` @@ -216,14 +226,16 @@ for (const showHidden of [true, false]) { array[1] = 97; assert.strictEqual( util.inspect(array, true), - `${constructor.name} [\n` + - ' 65,\n' + - ' 97,\n' + - ` [BYTES_PER_ELEMENT]: ${constructor.BYTES_PER_ELEMENT},\n` + - ` [length]: ${length},\n` + - ` [byteLength]: ${byteLength},\n` + - ' [byteOffset]: 0,\n' + - ` [buffer]: ArrayBuffer { byteLength: ${byteLength} } ]`); + tagLFy` + ${constructor.name} [ + 65, + 97, + [BYTES_PER_ELEMENT]: ${constructor.BYTES_PER_ELEMENT}, + [length]: ${length}, + [byteLength]: ${byteLength}, + [byteOffset]: 0, + [buffer]: ArrayBuffer { byteLength: ${byteLength} } ] + `); assert.strictEqual( util.inspect(array, false), `${constructor.name} [ 65, 97 ]` diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 1cf2d5f90aaf54..76c1b4f0f6c53c 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagLFy } = require('../common'); const assert = require('assert'); const vm = require('vm'); @@ -78,9 +78,13 @@ const contextifiedSandboxErrorMsg = // Issue GH-693: console.error('test RegExp as argument to assert.throws'); -script = vm.createScript('const assert = require(\'assert\'); assert.throws(' + - 'function() { throw "hello world"; }, /hello/);', - 'some.js'); +script = vm.createScript( + tagLFy` + const assert = require('assert'); + assert.throws(function() { throw "hello world"; }, /hello/); + `, + 'some.js' +); script.runInNewContext({ require: require }); // Issue GH-7529 diff --git a/test/parallel/test-vm-global-define-property.js b/test/parallel/test-vm-global-define-property.js index 30709fccaab453..3c8f1c362c697b 100644 --- a/test/parallel/test-vm-global-define-property.js +++ b/test/parallel/test-vm-global-define-property.js @@ -20,20 +20,21 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const { tagLFy } = require('../common'); const assert = require('assert'); const vm = require('vm'); -const code = - 'Object.defineProperty(this, "f", {\n' + - ' get: function() { return x; },\n' + - ' set: function(k) { x = k; },\n' + - ' configurable: true,\n' + - ' enumerable: true\n' + - '});\n' + - 'g = f;\n' + - 'f;\n'; +const code = tagLFy` + Object.defineProperty(this, 'f', { + get: function() { return x; }, + set: function(k) { x = k; }, + configurable: true, + enumerable: true + }); + g = f; + f; +`; const x = {}; const o = vm.createContext({ console: console, x: x }); diff --git a/test/parallel/test-vm-new-script-new-context.js b/test/parallel/test-vm-new-script-new-context.js index 8909cc846305c2..a99258eae6b2e8 100644 --- a/test/parallel/test-vm-new-script-new-context.js +++ b/test/parallel/test-vm-new-script-new-context.js @@ -55,9 +55,11 @@ assert.strictEqual(5, global.hello); console.error('pass values in and out'); -global.code = 'foo = 1;' + - 'bar = 2;' + - 'if (baz !== 3) throw new Error(\'test fail\');'; +global.code = common.tagLFy` + foo = 1; + bar = 2; + if (baz !== 3) throw new Error('test fail'); +`; global.foo = 2; global.obj = { foo: 0, baz: 3 }; script = new Script(global.code); diff --git a/test/parallel/test-vm-new-script-this-context.js b/test/parallel/test-vm-new-script-this-context.js index dfa9b1130b1f55..58074b7368347c 100644 --- a/test/parallel/test-vm-new-script-this-context.js +++ b/test/parallel/test-vm-new-script-this-context.js @@ -44,9 +44,11 @@ assert.strictEqual(2, global.hello); console.error('pass values'); -global.code = 'foo = 1;' + - 'bar = 2;' + - 'if (typeof baz !== "undefined") throw new Error("test fail");'; +global.code = common.tagLFy` + foo = 1; + bar = 2; + if (typeof baz !== 'undefined') throw new Error('test fail'); +`; global.foo = 2; global.obj = { foo: 0, baz: 3 }; script = new Script(global.code); diff --git a/test/parallel/test-vm-run-in-new-context.js b/test/parallel/test-vm-run-in-new-context.js index 0da73ea6a90726..a5f3c09f6ef3d2 100644 --- a/test/parallel/test-vm-run-in-new-context.js +++ b/test/parallel/test-vm-run-in-new-context.js @@ -46,9 +46,11 @@ assert.strictEqual(5, global.hello); console.error('pass values in and out'); -global.code = 'foo = 1;' + - 'bar = 2;' + - 'if (baz !== 3) throw new Error(\'test fail\');'; +global.code = common.tagLFy` + foo = 1; + bar = 2; + if (baz !== 3) throw new Error('test fail'); +`; global.foo = 2; global.obj = { foo: 0, baz: 3 }; /* eslint-disable no-unused-vars */ diff --git a/test/parallel/test-vm-static-this.js b/test/parallel/test-vm-static-this.js index 5306e31dc0e4a7..660f62deff6034 100644 --- a/test/parallel/test-vm-static-this.js +++ b/test/parallel/test-vm-static-this.js @@ -41,10 +41,11 @@ assert.strictEqual(2, global.hello); // pass values -const code = 'foo = 1;' + - 'bar = 2;' + - 'if (typeof baz !== \'undefined\')' + - 'throw new Error(\'test fail\');'; +const code = common.tagLFy` + foo = 1; + bar = 2; + if (typeof baz !== 'undefined') throw new Error('test fail'); +`; global.foo = 2; global.obj = { foo: 0, baz: 3 }; /* eslint-disable no-unused-vars */ diff --git a/test/parallel/test-vm-syntax-error-message.js b/test/parallel/test-vm-syntax-error-message.js index 89589c5cc9d881..30b45e7d0010de 100644 --- a/test/parallel/test-vm-syntax-error-message.js +++ b/test/parallel/test-vm-syntax-error-message.js @@ -1,14 +1,16 @@ 'use strict'; -require('../common'); +const { tagGlue } = require('../common'); const assert = require('assert'); const child_process = require('child_process'); const p = child_process.spawn(process.execPath, [ '-e', - 'vm = require("vm");' + - 'context = vm.createContext({});' + - 'try { vm.runInContext("throw new Error(\'boo\')", context); } ' + - 'catch (e) { console.log(e.message); }' + tagGlue` + vm = require('vm'); + context = vm.createContext({}); + try { vm.runInContext("throw new Error('boo')", context); } + catch (e) { console.log(e.message); } + ` ]); p.stderr.on('data', function(data) { diff --git a/test/parallel/test-zlib-from-string.js b/test/parallel/test-zlib-from-string.js index a17f2bb728bcba..9e183c5189eaf0 100644 --- a/test/parallel/test-zlib-from-string.js +++ b/test/parallel/test-zlib-from-string.js @@ -22,37 +22,43 @@ 'use strict'; // test compressing and uncompressing a string with zlib -require('../common'); +const { tagGlue, tagUnwrap } = require('../common'); const assert = require('assert'); const zlib = require('zlib'); -const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing eli' + - 't. Morbi faucibus, purus at gravida dictum, libero arcu ' + - 'convallis lacus, in commodo libero metus eu nisi. Nullam' + - ' commodo, neque nec porta placerat, nisi est fermentum a' + - 'ugue, vitae gravida tellus sapien sit amet tellus. Aenea' + - 'n non diam orci. Proin quis elit turpis. Suspendisse non' + - ' diam ipsum. Suspendisse nec ullamcorper odio. Vestibulu' + - 'm arcu mi, sodales non suscipit id, ultrices ut massa. S' + - 'ed ac sem sit amet arcu malesuada fermentum. Nunc sed. '; -const expectedBase64Deflate = 'eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpmX' + - 'AKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkD' + - 'lKWLJWkncJG5403HQXAkT3Jw29B9uIEmToMukglZ0vS6oc' + - 'iBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491LofoA' + - 'bWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+' + - 'RSQsGoC7dn2t/xjhduTA1NWyQIZR0pbHwMDatnD+crPqKS' + - 'qGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqqq' + - 'fKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOH' + - 'aFE4RdpnGavKtrB5xzfO/Ll9'; -const expectedBase64Gzip = 'H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN4' + - '96pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajN' + - 'Pk6QOUpYslaSdwkbnjTcdBcCRPcnDb0H24gSZOgy6SCVnS9Lq' + - 'hyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYrLj3Uuh+gBt' + - 'aHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCw' + - 'agLt2fa3/GOF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+' + - 'eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9hN9ory+qqp8oG00yF7c5' + - 'mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2' + - 'sHnHNzRtagj5AQAA'; +const inputString = tagUnwrap` + ΩΩLorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi faucibus, + purus at gravida dictum, libero arcu convallis lacus, in commodo libero + metus eu nisi. Nullam commodo, neque nec porta placerat, nisi est fermentum + augue, vitae gravida tellus sapien sit amet tellus. Aenean non diam orci. + Proin quis elit turpis. Suspendisse non diam ipsum. Suspendisse nec + ullamcorper odio. Vestibulum arcu mi, sodales non suscipit id, ultrices + ut massa. Sed ac sem sit amet arcu malesuada fermentum. Nunc sed.${' '} +`; + +const expectedBase64Deflate = tagGlue` + eJxdUUtOQzEMvMoc4OndgT0gJCT2buJWlpI4jePeqZfpmX + AKLRKbLOzx/HK73q6vOrhCunlF1qIDJhNUeW5I2ozT5OkD + lKWLJWkncJG5403HQXAkT3Jw29B9uIEmToMukglZ0vS6oc + iBh4JG8sV4oVLEUCitK2kxq1WzPnChHDzsaGKy491LofoA + bWh8do43oeuYhB5EPCjcLjzYJo48KrfQBvnJecNFJvHT1+ + RSQsGoC7dn2t/xjhduTA1NWyQIZR0pbHwMDatnD+crPqKS + qGPHp1vnlsWM/07ubf7bheF7kqSj84Bm0R1fYTfaK8vqqq + fKBtNMhe3OZh6N95CTvMX5HJJi4xOVzCgUOIMSLH7wmeOH + aFE4RdpnGavKtrB5xzfO/Ll9 +`; + +const expectedBase64Gzip = tagGlue` + H4sIAAAAAAAAA11RS05DMQy8yhzg6d2BPSAkJPZu4laWkjiN4 + 96pl+mZcAotEpss7PH8crverq86uEK6eUXWogMmE1R5bkjajN + Pk6QOUpYslaSdwkbnjTcdBcCRPcnDb0H24gSZOgy6SCVnS9Lq + hyIGHgkbyxXihUsRQKK0raTGrVbM+cKEcPOxoYrLj3Uuh+gBt + aHx2jjeh65iEHkQ8KNwuPNgmjjwqt9AG+cl5w0Um8dPX5FJCw + agLt2fa3/GOF25MDU1bJAhlHSlsfAwNq2cP5ys+opKoY8enW+ + eWxYz/Tu5t/tuF4XuSpKPzgGbRHV9hN9ory+qqp8oG00yF7c5 + mHo33kJO8xfkckmLjE5XMKBQ4gxIsfvCZ44doUThF2mcZq8q2 + sHnHNzRtagj5AQAA +`; zlib.deflate(inputString, function(err, buffer) { assert.strictEqual(buffer.toString('base64'), expectedBase64Deflate, diff --git a/test/parallel/test-zlib-truncated.js b/test/parallel/test-zlib-truncated.js index c7b84c0d703711..d96002d4753e1a 100644 --- a/test/parallel/test-zlib-truncated.js +++ b/test/parallel/test-zlib-truncated.js @@ -1,19 +1,19 @@ 'use strict'; // tests zlib streams with truncated compressed input -require('../common'); +const { tagUnwrap } = require('../common'); const assert = require('assert'); const zlib = require('zlib'); -const inputString = 'ΩΩLorem ipsum dolor sit amet, consectetur adipiscing eli' + - 't. Morbi faucibus, purus at gravida dictum, libero arcu ' + - 'convallis lacus, in commodo libero metus eu nisi. Nullam' + - ' commodo, neque nec porta placerat, nisi est fermentum a' + - 'ugue, vitae gravida tellus sapien sit amet tellus. Aenea' + - 'n non diam orci. Proin quis elit turpis. Suspendisse non' + - ' diam ipsum. Suspendisse nec ullamcorper odio. Vestibulu' + - 'm arcu mi, sodales non suscipit id, ultrices ut massa. S' + - 'ed ac sem sit amet arcu malesuada fermentum. Nunc sed. '; +const inputString = tagUnwrap` + ΩΩLorem ipsum dolor sit amet, consectetur adipiscing elit. + Morbi faucibus, purus at gravida dictum, libero arcu convallis lacus, + in commodo libero metus eu nisi. Nullam commodo, neque nec porta placerat, + nisi est fermentum augue, vitae gravida tellus sapien sit amet tellus. + Aenean non diam orci. Proin quis elit turpis. Suspendisse non diam ipsum. + Suspendisse nec ullamcorper odio. Vestibulum arcu mi, sodales non suscipit id, + ultrices ut massa. Sed ac sem sit amet arcu malesuada fermentum. Nunc sed. +`; [ { comp: 'gzip', decomp: 'gunzip', decompSync: 'gunzipSync' }, diff --git a/test/sequential/test-repl-timeout-throw.js b/test/sequential/test-repl-timeout-throw.js index aa933394b42ae7..2f366954a811a8 100644 --- a/test/sequential/test-repl-timeout-throw.js +++ b/test/sequential/test-repl-timeout-throw.js @@ -36,16 +36,19 @@ child.stdout.once('data', function() { } function eeTest() { - child.stdin.write('setTimeout(function() {\n' + - ' const events = require("events");\n' + - ' var e = new events.EventEmitter;\n' + - ' process.nextTick(function() {\n' + - ' e.on("x", thrower);\n' + - ' setTimeout(function() {\n' + - ' e.emit("x");\n' + - ' });\n' + - ' });\n' + - '});"";\n'); + child.stdin.write(common.tagLFy` + setTimeout(function() { + const events = require('events'); + var e = new events.EventEmitter; + process.nextTick(function() { + e.on('x', thrower); + setTimeout(function() { + e.emit('x'); + }); + }); + });''; + + `); setTimeout(child.stdin.end.bind(child.stdin), common.platformTimeout(200)); } diff --git a/test/sequential/test-util-debug.js b/test/sequential/test-util-debug.js index 242c536125aff2..325e920953e405 100644 --- a/test/sequential/test-util-debug.js +++ b/test/sequential/test-util-debug.js @@ -40,8 +40,11 @@ function parent() { function test(environ, shouldWrite) { let expectErr = ''; if (shouldWrite) { - expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' + - 'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\n'; + expectErr = common.tagLFy` + TUD %PID%: this { is: 'a' } /debugging/ + TUD %PID%: number=1234 string=asdf obj={"foo":"bar"} + + `; } const expectOut = 'ok\n';