2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2017-08-04 23:30:46 +08:00
|
|
|
var assert = require('assert');
|
2019-10-07 17:29:07 +08:00
|
|
|
var testHelper = require('../support/test-helper');
|
2017-08-04 23:30:46 +08:00
|
|
|
|
2019-10-07 17:29:07 +08:00
|
|
|
var lzmaMiddleware = require('../../lib/api/middlewares/lzma');
|
2017-08-04 23:30:46 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('lzma-middleware', function () {
|
|
|
|
it('it should extend params with decoded lzma', function (done) {
|
2017-08-04 23:30:46 +08:00
|
|
|
var qo = {
|
|
|
|
config: {
|
|
|
|
version: '1.3.0'
|
|
|
|
}
|
|
|
|
};
|
2019-10-22 01:07:24 +08:00
|
|
|
testHelper.lzma_compress_to_base64(JSON.stringify(qo), 1, function (err, data) {
|
2019-10-25 00:38:37 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2018-03-02 01:45:04 +08:00
|
|
|
const lzma = lzmaMiddleware();
|
2017-08-04 23:30:46 +08:00
|
|
|
var req = {
|
|
|
|
headers: {
|
2019-10-22 01:07:24 +08:00
|
|
|
host: 'localhost'
|
2017-08-04 23:30:46 +08:00
|
|
|
},
|
|
|
|
query: {
|
|
|
|
api_key: 'test',
|
|
|
|
lzma: data
|
2018-03-02 18:16:46 +08:00
|
|
|
},
|
|
|
|
profiler: {
|
|
|
|
done: function () {}
|
2017-08-04 23:30:46 +08:00
|
|
|
}
|
|
|
|
};
|
2018-03-02 01:45:04 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
lzma(req, {}, function (err) {
|
|
|
|
if (err) {
|
2017-08-04 23:30:46 +08:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var query = req.query;
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(qo.config, query.config);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual('test', query.api_key);
|
2017-08-04 23:30:46 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|