Skip to content

Commit

Permalink
fix platform-specific compression test failure
Browse files Browse the repository at this point in the history
The problem is that gzip headers include a platform identifier.
Previously, zlib was incorrectly treating macOS as just a "generic
UNIX", but now it is actually using the correct header. The updated zlib
made its way in to recent versions of node and started uncovering a new
source of platform-specific assumptions that people didn't know they
were making.

To fix this, instead of hard-coding the expected gzip compression
result, we can just generate them on the testing platform.

This is an instance of nodejs/node#12244.
  • Loading branch information
rmg committed Apr 13, 2017
1 parent c135eae commit 701a188
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/invoke.policy.http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var backend = require('./support/invoke-server');
var apimServer = require('./support/mock-apim-server/apim-server');
var dsCleanup = require('./support/utils').dsCleanup;
var resetLimiterCache = require('../lib/rate-limit/util').resetLimiterCache;
var zlib = require('zlib');

describe('invokePolicy', function() {
var request;
Expand Down Expand Up @@ -287,14 +288,20 @@ describe('invokePolicy', function() {
it('compress-data', function(done) {
this.timeout(10000);

// gzip compression header includes a platform bit which means different
// platforms actually produce _slightly_ different gzip compression results
// depending on the platform.
// see https://github.com/nodejs/node/issues/12244
const gzHelloWorld = zlib.gzipSync('Hello World').toString('base64');

// when data is compressed, use the chunked encoding
request
.post('/invoke/testCompression')
.set('X-RAW-DATA', 'Hello World')
.expect(/z-content-encoding: gzip/)
.expect(/z-content-length: undefined/)
.expect(/z-transfer-encoding: chunked/)
.expect(/raw: H4sIAAAAAAAAA\/NIzcnJVwjPL8pJAQBWsRdKCwAAAA==/)
.expect(new RegExp(`raw: ${gzHelloWorld}`))
.expect(200, /body: Hello World/, done);
});

Expand Down

0 comments on commit 701a188

Please sign in to comment.