Skip to content

Commit

Permalink
added test for stream validation bug apigee-127#463
Browse files Browse the repository at this point in the history
  • Loading branch information
smoebody committed Dec 20, 2016
1 parent 6851b2a commit 7f9cb81
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/2.0/test-middleware-swagger-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var async = require('async');
var helpers = require('../helpers');
var request = require('supertest');
var stream = require('stream');
var fs = require('fs');
var crypto = require('crypto');

var petStoreJson = _.cloneDeep(require('../../samples/2.0/petstore.json'));

Expand Down Expand Up @@ -1575,6 +1577,55 @@ describe('Swagger Validator Middleware v2.0', function () {
});
});

it('should validate file and return it (issue #463)', function (done) {
var cPetStore = _.cloneDeep(petStoreJson);

cPetStore.paths['/image'] = {
get: {
summary: 'Get image',
description: 'Retrieves image.',
operationId: 'getImage',
produces: ['image/png'],
responses: {
'200': {
description: 'OK',
schema: {
type: 'file'
}
}
}
}
};

helpers.createServer([cPetStore], {
swaggerRouterOptions: {
controllers: {
getImage: function (req, res) {
res.setHeader('Content-type', 'image/png');
return fs.createReadStream('test/image.png').pipe(res);
}
}
},
swaggerValidatorOptions: {
validateResponse: true
}
}, function (app) {
try {
request(app)
.get('/api/image')
.end(function(err, res) {
assert.strictEqual(
crypto.createHash('sha256').update(fs.readFileSync('test/image.png')).digest('hex'), //expected
crypto.createHash('sha256').update(res.body).digest('hex') //actual
);
done(err);
});
} catch (err) {
done();
}
});
});

it('should not throw an error for empty responses that validate void (new issue)', function (done) {
var cPetStoreJson = _.cloneDeep(petStoreJson);

Expand Down
Binary file added test/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7f9cb81

Please sign in to comment.