Sha256: c66017b2a10dae17c57f366d91b47fd5127052ef2c0017177aee3b8d8baac05f

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

'use strict';
// test uncompressing invalid input

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

const nonStringInputs = [1, true, {a: 1}, ['a']];

console.error('Doing the non-strings');
nonStringInputs.forEach(function(input) {
  // zlib.gunzip should not throw an error when called with bad input.
  assert.doesNotThrow(function() {
    zlib.gunzip(input, function(err, buffer) {
      // zlib.gunzip should pass the error to the callback.
      assert.ok(err);
    });
  });
});

console.error('Doing the unzips');
// zlib.Unzip classes need to get valid data, or else they'll throw.
const unzips = [ zlib.Unzip(),
               zlib.Gunzip(),
               zlib.Inflate(),
               zlib.InflateRaw() ];
var hadError = [];
unzips.forEach(function(uz, i) {
  console.error('Error for ' + uz.constructor.name);
  uz.on('error', function(er) {
    console.error('Error event', er);
    hadError[i] = true;
  });

  uz.on('end', function(er) {
    throw new Error('end event should not be emitted ' + uz.constructor.name);
  });

  // this will trigger error event
  uz.write('this is not valid compressed data.');
});

process.on('exit', function() {
  assert.deepStrictEqual(hadError, [true, true, true, true], 'expect 4 errors');
});

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/test/parallel/test-zlib-invalid-input.js
node-compiler-0.9.0 vendor/node-v7.2.1/test/parallel/test-zlib-invalid-input.js
node-compiler-0.8.0 vendor/node-v7.2.0/test/parallel/test-zlib-invalid-input.js
node-compiler-0.7.0 vendor/node-v6.9.1/test/parallel/test-zlib-invalid-input.js
node-compiler-0.7.0 vendor/node-v7.1.0/test/parallel/test-zlib-invalid-input.js