mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 08:08:05 +00:00
Update to Koa v1.1.0
This commit is contained in:
parent
809580df97
commit
a1a85a557f
9
.eslintrc
Normal file
9
.eslintrc
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
parser: babel-eslint
|
||||||
|
|
||||||
|
extends: standard
|
||||||
|
|
||||||
|
rules:
|
||||||
|
eqeqeq: 0
|
||||||
|
semi: [2, always]
|
||||||
|
space-before-function-paren: [2, never]
|
||||||
|
yoda: 0
|
||||||
@ -1,10 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
- "0.12"
|
|
||||||
- "1"
|
|
||||||
- "2"
|
|
||||||
- "3"
|
|
||||||
- "4"
|
- "4"
|
||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|||||||
18
Makefile
18
Makefile
@ -1,26 +1,26 @@
|
|||||||
SRC = lib/*.js
|
SRC = lib/*.js
|
||||||
|
|
||||||
include node_modules/make-lint/index.mk
|
|
||||||
|
|
||||||
BIN = node
|
|
||||||
|
|
||||||
REQUIRED = --require should --require should-http
|
REQUIRED = --require should --require should-http
|
||||||
|
|
||||||
TESTS = test/application/* \
|
TESTS = test/application/* \
|
||||||
test/context/* \
|
test/context/* \
|
||||||
test/request/* \
|
test/request/* \
|
||||||
test/response/* \
|
test/response/* \
|
||||||
test/middlewares/*
|
test/middlewares/* \
|
||||||
|
test/experimental/index.js
|
||||||
|
|
||||||
|
lint:
|
||||||
|
@./node_modules/.bin/eslint lib test
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@NODE_ENV=test $(BIN) \
|
@NODE_ENV=test node \
|
||||||
./node_modules/.bin/_mocha \
|
./node_modules/.bin/_mocha \
|
||||||
$(REQUIRED) \
|
$(REQUIRED) \
|
||||||
$(TESTS) \
|
$(TESTS) \
|
||||||
--bail
|
--bail
|
||||||
|
|
||||||
test-travis:
|
test-travis: lint
|
||||||
@NODE_ENV=test $(BIN) \
|
@NODE_ENV=test node \
|
||||||
./node_modules/.bin/istanbul cover \
|
./node_modules/.bin/istanbul cover \
|
||||||
./node_modules/.bin/_mocha \
|
./node_modules/.bin/_mocha \
|
||||||
--report lcovonly \
|
--report lcovonly \
|
||||||
@ -32,4 +32,4 @@ test-travis:
|
|||||||
bench:
|
bench:
|
||||||
@$(MAKE) -C benchmarks
|
@$(MAKE) -C benchmarks
|
||||||
|
|
||||||
.PHONY: test bench
|
.PHONY: lint test bench
|
||||||
|
|||||||
@ -88,8 +88,7 @@ module.exports = function (strapi) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Little hack to serve the admin panel on `./admin` waiting for
|
// Little hack to serve the admin panel on `./admin`.
|
||||||
// this PR to be merged: https://github.com/koajs/static/pull/51.
|
|
||||||
strapi.router.get('/admin', function * () {
|
strapi.router.get('/admin', function * () {
|
||||||
this.status = 301;
|
this.status = 301;
|
||||||
yield strapi.middlewares.send(this, path.resolve(strapi.config.appPath, strapi.config.paths.static, 'admin', 'index.html'));
|
yield strapi.middlewares.send(this, path.resolve(strapi.config.appPath, strapi.config.paths.static, 'admin', 'index.html'));
|
||||||
|
|||||||
21
package.json
21
package.json
@ -35,12 +35,12 @@
|
|||||||
"bin": "./bin/_spawn.js",
|
"bin": "./bin/_spawn.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^1.4.2",
|
"async": "^1.4.2",
|
||||||
"commander": "^2.8.1",
|
"commander": "^2.9.0",
|
||||||
"consolidate": "^0.13.1",
|
"consolidate": "^0.13.1",
|
||||||
"fs-extra": "^0.24.0",
|
"fs-extra": "^0.24.0",
|
||||||
"include-all": "^0.1.6",
|
"include-all": "^0.1.6",
|
||||||
"json-stringify-safe": "^5.0.1",
|
"json-stringify-safe": "^5.0.1",
|
||||||
"koa": "^1.0.0",
|
"koa": "^1.1.0",
|
||||||
"koa-bodyparser": "^2.0.1",
|
"koa-bodyparser": "^2.0.1",
|
||||||
"koa-compose": "^2.3.0",
|
"koa-compose": "^2.3.0",
|
||||||
"koa-cors": "^0.0.16",
|
"koa-cors": "^0.0.16",
|
||||||
@ -53,19 +53,19 @@
|
|||||||
"koa-lusca": "^2.1.0",
|
"koa-lusca": "^2.1.0",
|
||||||
"koa-mount": "^1.3.0",
|
"koa-mount": "^1.3.0",
|
||||||
"koa-passport": "^1.2.0",
|
"koa-passport": "^1.2.0",
|
||||||
"koa-proxy": "^0.4.0",
|
"koa-proxy": "^0.4.1",
|
||||||
"koa-response-time": "^1.0.2",
|
"koa-response-time": "^1.0.2",
|
||||||
"koa-router": "^5.2.3",
|
"koa-router": "^5.2.3",
|
||||||
"koa-send": "^1.3.1",
|
"koa-send": "^2.0.1",
|
||||||
"koa-session": "^3.3.1",
|
"koa-session": "^3.3.1",
|
||||||
"koa-ssl": "^2.0.0",
|
"koa-ssl": "^2.0.0",
|
||||||
"koa-static": "^1.4.9",
|
"koa-static": "^1.5.1",
|
||||||
"koa-views": "^3.1.0",
|
"koa-views": "^3.1.0",
|
||||||
"lodash": "^3.10.1",
|
"lodash": "^3.10.1",
|
||||||
"node-rsa": "^0.2.25",
|
"node-rsa": "^0.2.26",
|
||||||
"node-schedule": "^0.2.9",
|
"node-schedule": "^0.2.9",
|
||||||
"prompt": "^0.2.14",
|
"prompt": "^0.2.14",
|
||||||
"request": "^2.64.0",
|
"request": "^2.65.0",
|
||||||
"sails-disk": "^0.10.8",
|
"sails-disk": "^0.10.8",
|
||||||
"socket.io": "^1.3.7",
|
"socket.io": "^1.3.7",
|
||||||
"socket.io-client": "^1.3.7",
|
"socket.io-client": "^1.3.7",
|
||||||
@ -76,9 +76,14 @@
|
|||||||
"strapi-generate-users": "^1.1.0",
|
"strapi-generate-users": "^1.1.0",
|
||||||
"unzip2": "^0.2.5",
|
"unzip2": "^0.2.5",
|
||||||
"waterline": "^0.10.26",
|
"waterline": "^0.10.26",
|
||||||
"winston": "^1.0.2"
|
"winston": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel": "^5.8.23",
|
||||||
|
"babel-eslint": "^4.1.3",
|
||||||
|
"eslint": "^1.6.0",
|
||||||
|
"eslint-config-standard": "^4.4.0",
|
||||||
|
"eslint-plugin-standard": "^1.3.1",
|
||||||
"expect.js": "^0.3.1",
|
"expect.js": "^0.3.1",
|
||||||
"istanbul": "^0.3.22",
|
"istanbul": "^0.3.22",
|
||||||
"jade": "^1.11.0",
|
"jade": "^1.11.0",
|
||||||
|
|||||||
35
test/application/context.js
Executable file
35
test/application/context.js
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const request = require('supertest');
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app.context', function () {
|
||||||
|
const app1 = new Koa();
|
||||||
|
app1.context.msg = 'hello';
|
||||||
|
|
||||||
|
const app2 = new Koa();
|
||||||
|
|
||||||
|
it('should merge properties', function (done) {
|
||||||
|
app1.use(function * () {
|
||||||
|
assert.equal(this.msg, 'hello');
|
||||||
|
this.status = 204;
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app1.listen())
|
||||||
|
.get('/')
|
||||||
|
.expect(204, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not affect the original prototype', function (done) {
|
||||||
|
app2.use(function * () {
|
||||||
|
assert.equal(this.msg, undefined);
|
||||||
|
this.status = 204;
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app2.listen())
|
||||||
|
.get('/')
|
||||||
|
.expect(204, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
54
test/application/index.js
Executable file
54
test/application/index.js
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const request = require('supertest');
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app', function () {
|
||||||
|
it('should handle socket errors', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
|
||||||
|
app.use(function * () {
|
||||||
|
this.socket.emit('error', new Error('boom'));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('error', function (err) {
|
||||||
|
err.message.should.equal('boom');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app.listen())
|
||||||
|
.get('/')
|
||||||
|
.end(function () {});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not .writeHead when !socket.writable', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
|
||||||
|
app.use(function * () {
|
||||||
|
this.socket.writable = false;
|
||||||
|
this.status = 204;
|
||||||
|
this.res.writeHead =
|
||||||
|
this.res.end = function () {
|
||||||
|
throw new Error('response sent');
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
setImmediate(done);
|
||||||
|
|
||||||
|
request(app.listen())
|
||||||
|
.get('/')
|
||||||
|
.end(function () {});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set development env when NODE_ENV missing', function () {
|
||||||
|
const NODE_ENV = process.env.NODE_ENV;
|
||||||
|
process.env.NODE_ENV = '';
|
||||||
|
|
||||||
|
const app = new Koa();
|
||||||
|
process.env.NODE_ENV = NODE_ENV;
|
||||||
|
|
||||||
|
assert.equal(app.env, 'development');
|
||||||
|
});
|
||||||
|
});
|
||||||
11
test/application/inspect.js
Executable file
11
test/application/inspect.js
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app.inspect()', function () {
|
||||||
|
it('should work', function () {
|
||||||
|
const app = new Koa();
|
||||||
|
const util = require('util');
|
||||||
|
util.inspect(app);
|
||||||
|
});
|
||||||
|
});
|
||||||
82
test/application/onerror.js
Executable file
82
test/application/onerror.js
Executable file
@ -0,0 +1,82 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const AssertionError = require('assert').AssertionError;
|
||||||
|
const stderr = require('test-console').stderr;
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app.onerror(err)', function () {
|
||||||
|
it('should throw an error if a non-error is given', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
app.onerror('foo');
|
||||||
|
}).should.throw(AssertionError, {
|
||||||
|
message: 'non-error thrown: foo'
|
||||||
|
});
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing if status is 404', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
const err = new Error();
|
||||||
|
|
||||||
|
err.status = 404;
|
||||||
|
|
||||||
|
const output = stderr.inspectSync(function () {
|
||||||
|
app.onerror(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
output.should.eql([]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing if .silent', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
app.silent = true;
|
||||||
|
|
||||||
|
const err = new Error();
|
||||||
|
|
||||||
|
const output = stderr.inspectSync(function () {
|
||||||
|
app.onerror(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
output.should.eql([]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should log the error to stderr', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
app.env = 'dev';
|
||||||
|
|
||||||
|
const err = new Error();
|
||||||
|
err.stack = 'Foo';
|
||||||
|
|
||||||
|
const output = stderr.inspectSync(function () {
|
||||||
|
app.onerror(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
output.should.eql(['\n', ' Foo\n', '\n']);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use err.toString() instad of err.stack', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
app.env = 'dev';
|
||||||
|
|
||||||
|
const err = new Error('mock stack null');
|
||||||
|
err.stack = null;
|
||||||
|
|
||||||
|
const output = stderr.inspectSync(function () {
|
||||||
|
app.onerror(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
output.should.eql(['\n', ' Error: mock stack null\n', '\n']);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
35
test/application/request.js
Executable file
35
test/application/request.js
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const request = require('supertest');
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app.request', function () {
|
||||||
|
const app1 = new Koa();
|
||||||
|
app1.request.message = 'hello';
|
||||||
|
|
||||||
|
const app2 = new Koa();
|
||||||
|
|
||||||
|
it('should merge properties', function (done) {
|
||||||
|
app1.use(function * () {
|
||||||
|
assert.equal(this.request.message, 'hello');
|
||||||
|
this.status = 204;
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app1.listen())
|
||||||
|
.get('/')
|
||||||
|
.expect(204, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not affect the original prototype', function (done) {
|
||||||
|
app2.use(function * () {
|
||||||
|
assert.equal(this.request.message, undefined);
|
||||||
|
this.status = 204;
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app2.listen())
|
||||||
|
.get('/')
|
||||||
|
.expect(204, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
File diff suppressed because it is too large
Load Diff
35
test/application/response.js
Executable file
35
test/application/response.js
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const request = require('supertest');
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app.response', function () {
|
||||||
|
const app1 = new Koa();
|
||||||
|
app1.response.msg = 'hello';
|
||||||
|
|
||||||
|
const app2 = new Koa();
|
||||||
|
|
||||||
|
it('should merge properties', function (done) {
|
||||||
|
app1.use(function * () {
|
||||||
|
assert.equal(this.response.msg, 'hello');
|
||||||
|
this.status = 204;
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app1.listen())
|
||||||
|
.get('/')
|
||||||
|
.expect(204, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not affect the original prototype', function (done) {
|
||||||
|
app2.use(function * () {
|
||||||
|
assert.equal(this.response.msg, undefined);
|
||||||
|
this.status = 204;
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app2.listen())
|
||||||
|
.get('/')
|
||||||
|
.expect(204, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
15
test/application/toJSON.js
Executable file
15
test/application/toJSON.js
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app.toJSON()', function () {
|
||||||
|
it('should work', function () {
|
||||||
|
const app = new Koa();
|
||||||
|
const obj = app.toJSON();
|
||||||
|
|
||||||
|
obj.should.eql({
|
||||||
|
subdomainOffset: 2,
|
||||||
|
env: 'test'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
59
test/application/use.js
Executable file
59
test/application/use.js
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const request = require('supertest');
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('app.use(fn)', function () {
|
||||||
|
it('should compose middleware', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
const calls = [];
|
||||||
|
|
||||||
|
app.use(function * (next) {
|
||||||
|
calls.push(1);
|
||||||
|
yield next;
|
||||||
|
calls.push(6);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(function * (next) {
|
||||||
|
calls.push(2);
|
||||||
|
yield next;
|
||||||
|
calls.push(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(function * (next) {
|
||||||
|
calls.push(3);
|
||||||
|
yield next;
|
||||||
|
calls.push(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
|
.get('/')
|
||||||
|
.expect(404)
|
||||||
|
.end(function (err) {
|
||||||
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
calls.should.eql([1, 2, 3, 4, 5, 6]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error when a non-generator function is passed', function () {
|
||||||
|
const app = new Koa();
|
||||||
|
|
||||||
|
try {
|
||||||
|
app.use(function () {});
|
||||||
|
} catch (err) {
|
||||||
|
err.message.should.equal('app.use() requires a generator function');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not error when a non-generator function is passed when .experimental=true', function () {
|
||||||
|
const app = new Koa();
|
||||||
|
app.experimental = true;
|
||||||
|
app.use(function () {});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -2,18 +2,20 @@
|
|||||||
|
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../..');
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
describe('ctx.cookies.set()', function () {
|
describe('ctx.cookies.set()', function () {
|
||||||
it('should set an unsigned cookie', function (done) {
|
it('should set an unsigned cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.cookies.set('name', 'jon');
|
this.cookies.set('name', 'jon');
|
||||||
this.status = 204;
|
this.status = 204;
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(204)
|
.expect(204)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
@ -32,7 +34,7 @@ describe('ctx.cookies.set()', function () {
|
|||||||
describe('with .signed', function () {
|
describe('with .signed', function () {
|
||||||
describe('when no .keys are set', function () {
|
describe('when no .keys are set', function () {
|
||||||
it('should error', function (done) {
|
it('should error', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
try {
|
try {
|
||||||
@ -51,7 +53,7 @@ describe('ctx.cookies.set()', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should send a signed cookie', function (done) {
|
it('should send a signed cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -62,7 +64,9 @@ describe('ctx.cookies.set()', function () {
|
|||||||
this.status = 204;
|
this.status = 204;
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(204)
|
.expect(204)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
|
|||||||
@ -2,19 +2,20 @@
|
|||||||
|
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../..');
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
describe('ctx.onerror(err)', function () {
|
describe('ctx.onerror(err)', function () {
|
||||||
it('should respond', function (done) {
|
it('should respond', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.body = 'something else';
|
this.body = 'something else';
|
||||||
|
|
||||||
this.throw(418, 'boom');
|
this.throw(418, 'boom');
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(418)
|
.expect(418)
|
||||||
.expect('Content-Type', 'text/plain; charset=utf-8')
|
.expect('Content-Type', 'text/plain; charset=utf-8')
|
||||||
@ -23,7 +24,7 @@ describe('ctx.onerror(err)', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should unset all headers', function (done) {
|
it('should unset all headers', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.set('Vary', 'Accept-Encoding');
|
this.set('Vary', 'Accept-Encoding');
|
||||||
@ -33,7 +34,9 @@ describe('ctx.onerror(err)', function () {
|
|||||||
this.throw(418, 'boom');
|
this.throw(418, 'boom');
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(418)
|
.expect(418)
|
||||||
.expect('Content-Type', 'text/plain; charset=utf-8')
|
.expect('Content-Type', 'text/plain; charset=utf-8')
|
||||||
@ -53,7 +56,7 @@ describe('ctx.onerror(err)', function () {
|
|||||||
describe('when invalid err.status', function () {
|
describe('when invalid err.status', function () {
|
||||||
describe('not number', function () {
|
describe('not number', function () {
|
||||||
it('should respond 500', function (done) {
|
it('should respond 500', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.body = 'something else';
|
this.body = 'something else';
|
||||||
@ -62,7 +65,9 @@ describe('ctx.onerror(err)', function () {
|
|||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(500)
|
.expect(500)
|
||||||
.expect('Content-Type', 'text/plain; charset=utf-8')
|
.expect('Content-Type', 'text/plain; charset=utf-8')
|
||||||
@ -72,7 +77,7 @@ describe('ctx.onerror(err)', function () {
|
|||||||
|
|
||||||
describe('not http status code', function () {
|
describe('not http status code', function () {
|
||||||
it('should respond 500', function (done) {
|
it('should respond 500', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.body = 'something else';
|
this.body = 'something else';
|
||||||
@ -81,7 +86,9 @@ describe('ctx.onerror(err)', function () {
|
|||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(500)
|
.expect(500)
|
||||||
.expect('Content-Type', 'text/plain; charset=utf-8')
|
.expect('Content-Type', 'text/plain; charset=utf-8')
|
||||||
@ -92,13 +99,15 @@ describe('ctx.onerror(err)', function () {
|
|||||||
|
|
||||||
describe('when non-error thrown', function () {
|
describe('when non-error thrown', function () {
|
||||||
it('should response non-error thrown message', function (done) {
|
it('should response non-error thrown message', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
throw 'string error';
|
throw 'string error';
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(500)
|
.expect(500)
|
||||||
.expect('Content-Type', 'text/plain; charset=utf-8')
|
.expect('Content-Type', 'text/plain; charset=utf-8')
|
||||||
|
|||||||
@ -3,17 +3,19 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../..');
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
describe('ctx.state', function () {
|
describe('ctx.state', function () {
|
||||||
it('should provide a ctx.state namespace', function (done) {
|
it('should provide a ctx.state namespace', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
assert.deepEqual(this.state, {});
|
assert.deepEqual(this.state, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app.listen())
|
const server = app.listen();
|
||||||
|
|
||||||
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect(404)
|
.expect(404)
|
||||||
.end(done);
|
.end(done);
|
||||||
|
|||||||
@ -13,7 +13,7 @@ describe('ctx.throw(msg)', function () {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert(err.status === 500);
|
assert(err.status === 500);
|
||||||
assert(!err.expose);
|
assert(!err.expose);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -29,7 +29,7 @@ describe('ctx.throw(err)', function () {
|
|||||||
assert(err.status === 500);
|
assert(err.status === 500);
|
||||||
assert(err.message === 'test');
|
assert(err.message === 'test');
|
||||||
assert(!err.expose);
|
assert(!err.expose);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -45,7 +45,7 @@ describe('ctx.throw(err, status)', function () {
|
|||||||
assert(err.status === 422);
|
assert(err.status === 422);
|
||||||
assert(err.message === 'test');
|
assert(err.message === 'test');
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -61,7 +61,7 @@ describe('ctx.throw(status, err)', function () {
|
|||||||
assert(err.status === 422);
|
assert(err.status === 422);
|
||||||
assert(err.message === 'test');
|
assert(err.message === 'test');
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -76,7 +76,7 @@ describe('ctx.throw(msg, status)', function () {
|
|||||||
assert(err.message === 'name required');
|
assert(err.message === 'name required');
|
||||||
assert(err.status === 400);
|
assert(err.status === 400);
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -91,7 +91,7 @@ describe('ctx.throw(status, msg)', function () {
|
|||||||
assert(err.message === 'name required');
|
assert(err.message === 'name required');
|
||||||
assert(err.status === 400);
|
assert(err.status === 400);
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -106,7 +106,7 @@ describe('ctx.throw(status)', function () {
|
|||||||
assert(err.message === 'Bad Request');
|
assert(err.message === 'Bad Request');
|
||||||
assert(err.status === 400);
|
assert(err.status === 400);
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ describe('ctx.throw(status)', function () {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert(err.message === 'some error');
|
assert(err.message === 'some error');
|
||||||
assert(!err.expose);
|
assert(!err.expose);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -140,7 +140,7 @@ describe('ctx.throw(status, msg, props)', function () {
|
|||||||
assert(err.status === 400);
|
assert(err.status === 400);
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
assert(err.prop === true);
|
assert(err.prop === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ describe('ctx.throw(status, msg, props)', function () {
|
|||||||
assert(err.status === 400);
|
assert(err.status === 400);
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
assert(err.prop === true);
|
assert(err.prop === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -177,7 +177,7 @@ describe('ctx.throw(msg, props)', function () {
|
|||||||
assert(err.status === 500);
|
assert(err.status === 500);
|
||||||
assert(err.expose === false);
|
assert(err.expose === false);
|
||||||
assert(err.prop === true);
|
assert(err.prop === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -195,7 +195,7 @@ describe('ctx.throw(status, props)', function () {
|
|||||||
assert(err.status === 400);
|
assert(err.status === 400);
|
||||||
assert(err.expose === true);
|
assert(err.expose === true);
|
||||||
assert(err.prop === true);
|
assert(err.prop === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -213,7 +213,7 @@ describe('ctx.throw(err, props)', function () {
|
|||||||
assert(err.status === 500);
|
assert(err.status === 500);
|
||||||
assert(err.expose === false);
|
assert(err.expose === false);
|
||||||
assert(err.prop === true);
|
assert(err.prop === true);
|
||||||
return done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
21
test/experimental/async.js
Executable file
21
test/experimental/async.js
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const request = require('supertest');
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
|
describe('.experimental=true', function () {
|
||||||
|
it('should support async functions', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
|
app.experimental = true;
|
||||||
|
app.use(async function () {
|
||||||
|
const string = await Promise.resolve('asdf');
|
||||||
|
this.body = string;
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app.callback())
|
||||||
|
.get('/')
|
||||||
|
.expect('asdf')
|
||||||
|
.expect(200, done);
|
||||||
|
});
|
||||||
|
});
|
||||||
6
test/experimental/index.js
Executable file
6
test/experimental/index.js
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('babel/register')({
|
||||||
|
optional: ['asyncToGenerator']
|
||||||
|
});
|
||||||
|
require('./async');
|
||||||
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
|
|
||||||
const strapi = require('../..');
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
exports = module.exports = function (req, res) {
|
module.exports = function (req, res) {
|
||||||
const socket = new Stream.Duplex();
|
const socket = new Stream.Duplex();
|
||||||
|
|
||||||
req = req || {
|
req = req || {
|
||||||
@ -31,13 +31,13 @@ exports = module.exports = function (req, res) {
|
|||||||
delete res._headers[k.toLowerCase()];
|
delete res._headers[k.toLowerCase()];
|
||||||
};
|
};
|
||||||
|
|
||||||
return strapi.server().createContext(req, res);
|
return (new Koa()).createContext(req, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.request = function (req, res) {
|
module.exports.request = function (req, res) {
|
||||||
return exports(req, res).request;
|
return module.exports(req, res).request;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.response = function (req, res) {
|
module.exports.response = function (req, res) {
|
||||||
return exports(req, res).response;
|
return module.exports(req, res).response;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,12 +4,13 @@ const path = require('path');
|
|||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
const fixtures = path.join(__dirname, 'fixtures');
|
const fixtures = path.join(__dirname, 'fixtures');
|
||||||
|
|
||||||
describe('bodyparser', function () {
|
describe('bodyparser', function () {
|
||||||
describe('json body', function () {
|
describe('json body', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
app.use(strapi.middlewares.bodyparser());
|
app.use(strapi.middlewares.bodyparser());
|
||||||
@ -54,7 +55,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should parse json patch', function (done) {
|
it('should parse json patch', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
app.use(strapi.middlewares.bodyparser());
|
app.use(strapi.middlewares.bodyparser());
|
||||||
@ -80,7 +81,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should json body reach the limit size', function (done) {
|
it('should json body reach the limit size', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should json body error with string in strict mode', function (done) {
|
it('should json body error with string in strict mode', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should json body ok with string not in strict mode', function (done) {
|
it('should json body ok with string not in strict mode', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ describe('bodyparser', function () {
|
|||||||
|
|
||||||
describe('opts.detectJSON', function () {
|
describe('opts.detectJSON', function () {
|
||||||
it('should parse json body on /foo.json request', function (done) {
|
it('should parse json body on /foo.json request', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -170,7 +171,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not parse json body on /foo request', function (done) {
|
it('should not parse json body on /foo request', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -197,7 +198,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('form body', function () {
|
describe('form body', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
app.use(strapi.middlewares.bodyparser());
|
app.use(strapi.middlewares.bodyparser());
|
||||||
@ -228,7 +229,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should parse form body reach the limit size', function (done) {
|
it('should parse form body reach the limit size', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -250,7 +251,7 @@ describe('bodyparser', function () {
|
|||||||
|
|
||||||
describe('extent type', function () {
|
describe('extent type', function () {
|
||||||
it('should extent json ok', function (done) {
|
it('should extent json ok', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -276,7 +277,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should extent json with array ok', function (done) {
|
it('should extent json with array ok', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -303,7 +304,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('other type', function () {
|
describe('other type', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
app.use(strapi.middlewares.bodyparser());
|
app.use(strapi.middlewares.bodyparser());
|
||||||
@ -321,7 +322,7 @@ describe('bodyparser', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('onerror', function () {
|
describe('onerror', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,13 @@ const join = require('path').join;
|
|||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('favicon', function () {
|
describe('favicon', function () {
|
||||||
const path = join(__dirname, 'fixtures', 'favicon.ico');
|
const path = join(__dirname, 'fixtures', 'favicon.ico');
|
||||||
|
|
||||||
it('should only respond on `/favicon.ico`', function (done) {
|
it('should only respond on /favicon.ico', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.favicon(path));
|
app.use(strapi.middlewares.favicon(path));
|
||||||
|
|
||||||
@ -26,8 +27,8 @@ describe('favicon', function () {
|
|||||||
.expect('hello', done);
|
.expect('hello', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('favicon should 404 if `path` is missing', function (done) {
|
it('favicon should 404 if path is missing', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon());
|
app.use(strapi.middlewares.favicon());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
@ -36,7 +37,7 @@ describe('favicon', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not accept POST requests', function (done) {
|
it('should not accept POST requests', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path));
|
app.use(strapi.middlewares.favicon(path));
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
@ -48,7 +49,7 @@ describe('favicon', function () {
|
|||||||
it('should send the favicon', function (done) {
|
it('should send the favicon', function (done) {
|
||||||
const body = fs.readFileSync(path);
|
const body = fs.readFileSync(path);
|
||||||
|
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path));
|
app.use(strapi.middlewares.favicon(path));
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
@ -59,7 +60,7 @@ describe('favicon', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should set cache-control headers', function (done) {
|
it('should set cache-control headers', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path));
|
app.use(strapi.middlewares.favicon(path));
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
@ -70,7 +71,7 @@ describe('favicon', function () {
|
|||||||
|
|
||||||
describe('options.maxAge', function () {
|
describe('options.maxAge', function () {
|
||||||
it('should set max-age', function (done) {
|
it('should set max-age', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path, {
|
app.use(strapi.middlewares.favicon(path, {
|
||||||
maxAge: 5000
|
maxAge: 5000
|
||||||
}));
|
}));
|
||||||
@ -82,7 +83,7 @@ describe('favicon', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should accept 0', function (done) {
|
it('should accept 0', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path, {
|
app.use(strapi.middlewares.favicon(path, {
|
||||||
maxAge: 0
|
maxAge: 0
|
||||||
}));
|
}));
|
||||||
@ -94,7 +95,7 @@ describe('favicon', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be valid delta-seconds', function (done) {
|
it('should be valid delta-seconds', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path, {
|
app.use(strapi.middlewares.favicon(path, {
|
||||||
maxAge: 1234
|
maxAge: 1234
|
||||||
}));
|
}));
|
||||||
@ -106,7 +107,7 @@ describe('favicon', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should floor at 0', function (done) {
|
it('should floor at 0', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path, {
|
app.use(strapi.middlewares.favicon(path, {
|
||||||
maxAge: -4000
|
maxAge: -4000
|
||||||
}));
|
}));
|
||||||
@ -118,7 +119,7 @@ describe('favicon', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should ceil at 31556926', function (done) {
|
it('should ceil at 31556926', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path, {
|
app.use(strapi.middlewares.favicon(path, {
|
||||||
maxAge: 900000000000
|
maxAge: 900000000000
|
||||||
}));
|
}));
|
||||||
@ -130,7 +131,7 @@ describe('favicon', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should accept Infinity', function (done) {
|
it('should accept Infinity', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
app.use(strapi.middlewares.favicon(path, {
|
app.use(strapi.middlewares.favicon(path, {
|
||||||
maxAge: Infinity
|
maxAge: Infinity
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -6,6 +6,7 @@ const should = require('should');
|
|||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('gzip', function () {
|
describe('gzip', function () {
|
||||||
const options = {};
|
const options = {};
|
||||||
|
|||||||
@ -5,11 +5,12 @@ const path = require('path');
|
|||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('i18n', function () {
|
describe('i18n', function () {
|
||||||
describe('detect the query string', function () {
|
describe('detect the query string', function () {
|
||||||
it('should be "en" locale', function (done) {
|
it('should be "en" locale', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
strapi.middlewares.locale(app);
|
strapi.middlewares.locale(app);
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ describe('i18n', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('detect the subdomain', function () {
|
describe('detect the subdomain', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
strapi.middlewares.locale(app);
|
strapi.middlewares.locale(app);
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ describe('i18n', function () {
|
|||||||
|
|
||||||
describe('detect the header', function () {
|
describe('detect the header', function () {
|
||||||
it('should be "zh-tw" locale', function (done) {
|
it('should be "zh-tw" locale', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
strapi.middlewares.locale(app);
|
strapi.middlewares.locale(app);
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ describe('i18n', function () {
|
|||||||
|
|
||||||
describe('detect the cookie', function () {
|
describe('detect the cookie', function () {
|
||||||
it('should be "zh-cn" locale', function (done) {
|
it('should be "zh-cn" locale', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
strapi.middlewares.locale(app);
|
strapi.middlewares.locale(app);
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,6 @@ describe('csrf', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('expects a thrown error if no session object', function (done) {
|
it('expects a thrown error if no session object', function (done) {
|
||||||
const router = strapi.middlewares.router();
|
|
||||||
const app = mock({
|
const app = mock({
|
||||||
csrf: true
|
csrf: true
|
||||||
}, true);
|
}, true);
|
||||||
@ -75,7 +74,7 @@ describe('csrf', function () {
|
|||||||
// assert(!err);
|
// assert(!err);
|
||||||
// request(app.listen())
|
// request(app.listen())
|
||||||
// .post('/csrf')
|
// .post('/csrf')
|
||||||
// .set('Cookie', res.headers['set-cookie'].join(';'))
|
// .set('cookie', res.headers['set-cookie'].join(';'))
|
||||||
// .send({
|
// .send({
|
||||||
// _csrf: res.body.token
|
// _csrf: res.body.token
|
||||||
// })
|
// })
|
||||||
@ -84,7 +83,6 @@ describe('csrf', function () {
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
it('POST (403 Forbidden on no token)', function (done) {
|
it('POST (403 Forbidden on no token)', function (done) {
|
||||||
const router = strapi.middlewares.router();
|
|
||||||
const app = mock({
|
const app = mock({
|
||||||
csrf: true
|
csrf: true
|
||||||
});
|
});
|
||||||
@ -124,7 +122,7 @@ describe('csrf', function () {
|
|||||||
// .expect(200, done);
|
// .expect(200, done);
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
//
|
||||||
// it('token can be sent through header instead of post body (session type: {value})', function (done) {
|
// it('token can be sent through header instead of post body (session type: {value})', function (done) {
|
||||||
// const router = strapi.middlewares.router();
|
// const router = strapi.middlewares.router();
|
||||||
// const app = mock({
|
// const app = mock({
|
||||||
@ -154,7 +152,7 @@ describe('csrf', function () {
|
|||||||
// .expect(200, done);
|
// .expect(200, done);
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
//
|
||||||
// it('should allow custom headers (session type: {value})', function (done) {
|
// it('should allow custom headers (session type: {value})', function (done) {
|
||||||
// const router = strapi.middlewares.router();
|
// const router = strapi.middlewares.router();
|
||||||
// const app = mock({
|
// const app = mock({
|
||||||
@ -164,15 +162,15 @@ describe('csrf', function () {
|
|||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
// app.use(router.routes());
|
|
||||||
// app.use(router.allowedMethods());
|
|
||||||
//
|
|
||||||
// router.all('/csrf', function * () {
|
// router.all('/csrf', function * () {
|
||||||
// this.body = {
|
// this.body = {
|
||||||
// token: this.state._csrf
|
// token: this.state._csrf
|
||||||
// };
|
// };
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
|
// app.use(router.routes());
|
||||||
|
// app.use(router.allowedMethods());
|
||||||
|
//
|
||||||
// request(app.listen())
|
// request(app.listen())
|
||||||
// .get('/csrf')
|
// .get('/csrf')
|
||||||
// .expect(200, function (err, res) {
|
// .expect(200, function (err, res) {
|
||||||
@ -187,8 +185,9 @@ describe('csrf', function () {
|
|||||||
// .expect(200, done);
|
// .expect(200, done);
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
//
|
||||||
// it('should allow custom functions (session type: {value})', function (done) {
|
// it('should allow custom functions (session type: {value})', function (done) {
|
||||||
|
// const router = strapi.middlewares.router();
|
||||||
// const myToken = require('./mocks/token');
|
// const myToken = require('./mocks/token');
|
||||||
//
|
//
|
||||||
// const mockConfig = {
|
// const mockConfig = {
|
||||||
@ -197,18 +196,17 @@ describe('csrf', function () {
|
|||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// const router = strapi.middlewares.router();
|
|
||||||
// const app = mock(mockConfig);
|
// const app = mock(mockConfig);
|
||||||
//
|
//
|
||||||
// app.use(router.routes());
|
|
||||||
// app.use(router.allowedMethods());
|
|
||||||
//
|
|
||||||
// router.all('/csrf', function * () {
|
// router.all('/csrf', function * () {
|
||||||
// this.body = {
|
// this.body = {
|
||||||
// token: this.state._csrf
|
// token: this.state._csrf
|
||||||
// };
|
// };
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
|
// app.use(router.routes());
|
||||||
|
// app.use(router.allowedMethods());
|
||||||
|
//
|
||||||
// request(app.listen())
|
// request(app.listen())
|
||||||
// .get('/csrf')
|
// .get('/csrf')
|
||||||
// .expect(200, function (err, res) {
|
// .expect(200, function (err, res) {
|
||||||
|
|||||||
@ -29,13 +29,13 @@ describe('x-content-type-options', function () {
|
|||||||
|
|
||||||
const app = mock(config);
|
const app = mock(config);
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
this.body = 'hello';
|
this.body = 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('X-Content-Type-Options', config.cto)
|
.expect('X-Content-Type-Options', config.cto)
|
||||||
|
|||||||
@ -28,13 +28,13 @@ describe('hsts', function () {
|
|||||||
|
|
||||||
const app = mock(config);
|
const app = mock(config);
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
this.body = 'hello';
|
this.body = 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('Strict-Transport-Security', 'max-age=' + config.hsts.maxAge)
|
.expect('Strict-Transport-Security', 'max-age=' + config.hsts.maxAge)
|
||||||
@ -52,13 +52,13 @@ describe('hsts', function () {
|
|||||||
|
|
||||||
const app = mock(config);
|
const app = mock(config);
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
this.body = 'hello';
|
this.body = 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('Strict-Transport-Security', 'max-age=0')
|
.expect('Strict-Transport-Security', 'max-age=0')
|
||||||
@ -74,13 +74,13 @@ describe('hsts', function () {
|
|||||||
|
|
||||||
const app = mock(config);
|
const app = mock(config);
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
this.body = 'hello';
|
this.body = 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('Strict-Transport-Security', 'max-age=31536000')
|
.expect('Strict-Transport-Security', 'max-age=31536000')
|
||||||
@ -99,13 +99,13 @@ describe('hsts', function () {
|
|||||||
|
|
||||||
const app = mock(config);
|
const app = mock(config);
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
this.body = 'hello';
|
this.body = 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('Strict-Transport-Security', 'max-age=' + config.hsts.maxAge + '; includeSubDomains')
|
.expect('Strict-Transport-Security', 'max-age=' + config.hsts.maxAge + '; includeSubDomains')
|
||||||
@ -125,13 +125,13 @@ describe('hsts', function () {
|
|||||||
|
|
||||||
const app = mock(config);
|
const app = mock(config);
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
this.body = 'hello';
|
this.body = 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('Strict-Transport-Security', 'max-age=' + config.hsts.maxAge + '; includeSubDomains; preload')
|
.expect('Strict-Transport-Security', 'max-age=' + config.hsts.maxAge + '; includeSubDomains; preload')
|
||||||
|
|||||||
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
const strapi = require('../../../..');
|
const strapi = require('../../../..');
|
||||||
|
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
module.exports = function (config, disableSession) {
|
module.exports = function (config, disableSession) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.keys = ['key1', 'key2'];
|
app.keys = ['key1', 'key2'];
|
||||||
|
|||||||
@ -34,13 +34,13 @@ describe('p3p', function () {
|
|||||||
|
|
||||||
const app = mock(config);
|
const app = mock(config);
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
this.body = 'hello';
|
this.body = 'hello';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
request(app.listen())
|
request(app.listen())
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('P3P', config.p3p)
|
.expect('P3P', config.p3p)
|
||||||
|
|||||||
@ -45,11 +45,11 @@ describe('xframe', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('header (sameorigin) with options.enable true', function (done) {
|
it('header (sameorigin) with options.enable true', function (done) {
|
||||||
|
const router = strapi.middlewares.router();
|
||||||
const enable = function (url) {
|
const enable = function (url) {
|
||||||
return url.indexOf('/show') >= 0;
|
return url.indexOf('/show') >= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
const router = strapi.middlewares.router();
|
|
||||||
const config = {
|
const config = {
|
||||||
xframe: {
|
xframe: {
|
||||||
value: 'SAMEORIGIN',
|
value: 'SAMEORIGIN',
|
||||||
|
|||||||
@ -6,12 +6,13 @@ const http = require('http');
|
|||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('proxy', function () {
|
describe('proxy', function () {
|
||||||
let server;
|
let server;
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * (next) {
|
app.use(function * (next) {
|
||||||
if (this.path === '/error') {
|
if (this.path === '/error') {
|
||||||
@ -44,7 +45,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should have option url', function (done) {
|
it('should have option url', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.get('/index.js', strapi.middlewares.proxy({
|
router.get('/index.js', strapi.middlewares.proxy({
|
||||||
@ -68,7 +69,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should have option url and host', function (done) {
|
it('should have option url and host', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
@ -98,7 +99,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should have option host', function (done) {
|
it('should have option host', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
host: 'http://localhost:1234'
|
host: 'http://localhost:1234'
|
||||||
@ -118,7 +119,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should have option host and map', function (done) {
|
it('should have option host and map', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
host: 'http://localhost:1234',
|
host: 'http://localhost:1234',
|
||||||
@ -141,7 +142,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should have option host and match', function (done) {
|
it('should have option host and match', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
host: 'http://localhost:1234',
|
host: 'http://localhost:1234',
|
||||||
@ -166,7 +167,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('url not match for url', function (done) {
|
it('url not match for url', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
url: 'class.js'
|
url: 'class.js'
|
||||||
@ -190,7 +191,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('url not match for map', function (done) {
|
it('url not match for map', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
map: {
|
map: {
|
||||||
@ -222,7 +223,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('encoding', function (done) {
|
it('encoding', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
url: 'http://localhost:1234/index.html',
|
url: 'http://localhost:1234/index.html',
|
||||||
@ -243,7 +244,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('pass query', function (done) {
|
it('pass query', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
url: 'http://localhost:1234/class.js',
|
url: 'http://localhost:1234/class.js',
|
||||||
@ -264,7 +265,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('pass request body', function (done) {
|
it('pass request body', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
host: 'http://localhost:1234'
|
host: 'http://localhost:1234'
|
||||||
@ -286,7 +287,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('pass parsed request body', function (done) {
|
it('pass parsed request body', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.bodyparser());
|
app.use(strapi.middlewares.bodyparser());
|
||||||
|
|
||||||
@ -310,7 +311,7 @@ describe('proxy', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('statusCode', function (done) {
|
it('statusCode', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.proxy({
|
app.use(strapi.middlewares.proxy({
|
||||||
host: 'http://localhost:1234'
|
host: 'http://localhost:1234'
|
||||||
|
|||||||
@ -6,10 +6,11 @@ const should = require('should');
|
|||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('layer', function () {
|
describe('layer', function () {
|
||||||
it('composes multiple callbacks/middleware', function (done) {
|
it('composes multiple callbacks/middleware', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -38,7 +39,7 @@ describe('layer', function () {
|
|||||||
|
|
||||||
describe('layer#match()', function () {
|
describe('layer#match()', function () {
|
||||||
it('captures URL path parameters', function (done) {
|
it('captures URL path parameters', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -63,7 +64,7 @@ describe('layer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('return orginal path parameters when decodeURIComponent throw error', function (done) {
|
it('return orginal path parameters when decodeURIComponent throw error', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -83,7 +84,7 @@ describe('layer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates ctx.captures with regexp captures', function (done) {
|
it('populates ctx.captures with regexp captures', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -112,7 +113,7 @@ describe('layer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('return orginal ctx.captures when decodeURIComponent throw error', function (done) {
|
it('return orginal ctx.captures when decodeURIComponent throw error', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -141,7 +142,7 @@ describe('layer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates ctx.captures with regexp captures include undefiend', function (done) {
|
it('populates ctx.captures with regexp captures include undefiend', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -170,7 +171,7 @@ describe('layer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw friendly error message when handle not exists', function () {
|
it('should throw friendly error message when handle not exists', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -193,7 +194,7 @@ describe('layer', function () {
|
|||||||
|
|
||||||
describe('layer#param()', function () {
|
describe('layer#param()', function () {
|
||||||
it('composes middleware for param fn', function (done) {
|
it('composes middleware for param fn', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
const route = router.register('/users/:user', ['GET'], [function * (next) {
|
const route = router.register('/users/:user', ['GET'], [function * (next) {
|
||||||
@ -229,7 +230,7 @@ describe('layer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ignores params which are not matched', function (done) {
|
it('ignores params which are not matched', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
const route = router.register('/users/:user', ['GET'], [function * (next) {
|
const route = router.register('/users/:user', ['GET'], [function * (next) {
|
||||||
@ -279,7 +280,7 @@ describe('layer', function () {
|
|||||||
|
|
||||||
describe('layer#url()', function () {
|
describe('layer#url()', function () {
|
||||||
it('generates route URL', function () {
|
it('generates route URL', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
const route = router.register('/:category/:title', ['get'], [function * () {}], 'books');
|
const route = router.register('/:category/:title', ['get'], [function * () {}], 'books');
|
||||||
@ -294,7 +295,7 @@ describe('layer', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('escapes using encodeURIComponent()', function () {
|
it('escapes using encodeURIComponent()', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
const route = router.register('/:category/:title', ['get'], [function * () {}], 'books');
|
const route = router.register('/:category/:title', ['get'], [function * () {}], 'books');
|
||||||
|
|||||||
@ -10,10 +10,11 @@ const should = require('should');
|
|||||||
const expect = require('expect.js');
|
const expect = require('expect.js');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('router', function () {
|
describe('router', function () {
|
||||||
it('does not register middleware more than once', function (done) {
|
it('does not register middleware more than once', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const parentRouter = strapi.middlewares.router();
|
const parentRouter = strapi.middlewares.router();
|
||||||
const nestedRouter = strapi.middlewares.router();
|
const nestedRouter = strapi.middlewares.router();
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('exposes middleware factory', function (done) {
|
it('exposes middleware factory', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.should.have.property('routes');
|
router.should.have.property('routes');
|
||||||
@ -64,7 +65,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('supports promises for async/await', function (done) {
|
it('supports promises for async/await', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.experimental = true;
|
app.experimental = true;
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches middleware only if route was matched', function (done) {
|
it('matches middleware only if route was matched', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
const otherRouter = strapi.middlewares.router();
|
const otherRouter = strapi.middlewares.router();
|
||||||
@ -125,7 +126,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches first to last', function (done) {
|
it('matches first to last', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router
|
router
|
||||||
@ -152,7 +153,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not run subsequent middleware without yield next', function (done) {
|
it('does not run subsequent middleware without yield next', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router
|
router
|
||||||
@ -168,7 +169,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('nests routers with prefixes at root', function (done) {
|
it('nests routers with prefixes at root', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const api = strapi.middlewares.router();
|
const api = strapi.middlewares.router();
|
||||||
|
|
||||||
const forums = strapi.middlewares.router({
|
const forums = strapi.middlewares.router({
|
||||||
@ -228,7 +229,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('nests routers with prefixes at path', function (done) {
|
it('nests routers with prefixes at path', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const api = strapi.middlewares.router();
|
const api = strapi.middlewares.router();
|
||||||
|
|
||||||
const forums = strapi.middlewares.router({
|
const forums = strapi.middlewares.router({
|
||||||
@ -288,7 +289,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs subrouter middleware after parent', function (done) {
|
it('runs subrouter middleware after parent', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const subrouter = strapi.middlewares.router()
|
const subrouter = strapi.middlewares.router()
|
||||||
.use(function * (next) {
|
.use(function * (next) {
|
||||||
this.msg = 'subrouter';
|
this.msg = 'subrouter';
|
||||||
@ -318,7 +319,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs parent middleware for subrouter routes', function (done) {
|
it('runs parent middleware for subrouter routes', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const subrouter = strapi.middlewares.router()
|
const subrouter = strapi.middlewares.router()
|
||||||
.get('/sub', function * () {
|
.get('/sub', function * () {
|
||||||
this.body = { msg: this.msg };
|
this.body = { msg: this.msg };
|
||||||
@ -344,7 +345,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches corresponding requests', function (done) {
|
it('matches corresponding requests', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -397,8 +398,8 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('executes route middleware using `app.context`', function (done) {
|
it('executes route middleware using app.context', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -432,7 +433,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('supports generators for route middleware', function (done) {
|
it('supports generators for route middleware', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -463,7 +464,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('responds to OPTIONS requests', function (done) {
|
it('responds to OPTIONS requests', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -486,7 +487,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('responds with 405 Method Not Allowed', function (done) {
|
it('responds with 405 Method Not Allowed', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -510,7 +511,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('responds with 501 Not Implemented', function (done) {
|
it('responds with 501 Not Implemented', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -531,7 +532,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not send 405 if route matched but status is 404', function (done) {
|
it('does not send 405 if route matched but status is 404', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -553,7 +554,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('supports custom routing detect path: ctx.routerPath', function (done) {
|
it('supports custom routing detect path: ctx.routerPath', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(function * (next) {
|
app.use(function * (next) {
|
||||||
@ -577,7 +578,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#[verb]()', function () {
|
describe('router#[verb]()', function () {
|
||||||
it('registers route specific to HTTP verb', function () {
|
it('registers route specific to HTTP verb', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -600,7 +601,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('registers routes without params before routes with params', function (done) {
|
it('registers routes without params before routes with params', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.get('/:parameter', function * (next) {
|
router.get('/:parameter', function * (next) {
|
||||||
@ -642,7 +643,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#use()', function (done) {
|
describe('router#use()', function (done) {
|
||||||
it('uses router middleware without path', function (done) {
|
it('uses router middleware without path', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.get('/foo/bar', function * (next) {
|
router.get('/foo/bar', function * (next) {
|
||||||
@ -676,7 +677,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('uses router middleware at given path', function (done) {
|
it('uses router middleware at given path', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.use('/foo/bar', function * (next) {
|
router.use('/foo/bar', function * (next) {
|
||||||
@ -706,7 +707,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs router middleware before subrouter middleware', function (done) {
|
it('runs router middleware before subrouter middleware', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
const subrouter = strapi.middlewares.router();
|
const subrouter = strapi.middlewares.router();
|
||||||
@ -744,7 +745,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('assigns middleware to array of paths', function (done) {
|
it('assigns middleware to array of paths', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.use(['/foo', '/bar'], function * (next) {
|
router.use(['/foo', '/bar'], function * (next) {
|
||||||
@ -793,7 +794,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#register()', function () {
|
describe('router#register()', function () {
|
||||||
it('registers new routes', function (done) {
|
it('registers new routes', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.should.have.property('register');
|
router.should.have.property('register');
|
||||||
@ -812,7 +813,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#redirect()', function () {
|
describe('router#redirect()', function () {
|
||||||
it('redirects using route names', function (done) {
|
it('redirects using route names', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -836,7 +837,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#route()', function () {
|
describe('router#route()', function () {
|
||||||
it('inherits routes from nested router', function () {
|
it('inherits routes from nested router', function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const subrouter = strapi.middlewares.router().get('child', '/hello', function * (next) {
|
const subrouter = strapi.middlewares.router().get('child', '/hello', function * (next) {
|
||||||
this.body = { hello: 'world' };
|
this.body = { hello: 'world' };
|
||||||
});
|
});
|
||||||
@ -849,7 +850,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#url()', function () {
|
describe('router#url()', function () {
|
||||||
it('generates URL for given route', function (done) {
|
it('generates URL for given route', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -868,7 +869,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#param()', function () {
|
describe('router#param()', function () {
|
||||||
it('runs parameter middleware', function (done) {
|
it('runs parameter middleware', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
@ -900,7 +901,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs parameter middleware in order of URL appearance', function (done) {
|
it('runs parameter middleware in order of URL appearance', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router
|
router
|
||||||
@ -946,7 +947,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('runs parent parameter middleware for subrouter', function (done) {
|
it('runs parent parameter middleware for subrouter', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
const subrouter = strapi.middlewares.router();
|
const subrouter = strapi.middlewares.router();
|
||||||
@ -984,7 +985,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router#opts', function () {
|
describe('router#opts', function () {
|
||||||
it('responds with 200', function (done) {
|
it('responds with 200', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router({
|
const router = strapi.middlewares.router({
|
||||||
strict: true
|
strict: true
|
||||||
});
|
});
|
||||||
@ -1009,7 +1010,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should allow setting a prefix', function (done) {
|
it('should allow setting a prefix', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const routes = strapi.middlewares.router({
|
const routes = strapi.middlewares.router({
|
||||||
prefix: '/things/:thing_id'
|
prefix: '/things/:thing_id'
|
||||||
});
|
});
|
||||||
@ -1033,7 +1034,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('responds with 404 when has a trailing slash', function (done) {
|
it('responds with 404 when has a trailing slash', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router({
|
const router = strapi.middlewares.router({
|
||||||
strict: true
|
strict: true
|
||||||
});
|
});
|
||||||
@ -1059,7 +1060,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('use middleware with opts', function () {
|
describe('use middleware with opts', function () {
|
||||||
it('responds with 200', function (done) {
|
it('responds with 200', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router({
|
const router = strapi.middlewares.router({
|
||||||
strict: true
|
strict: true
|
||||||
});
|
});
|
||||||
@ -1084,7 +1085,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('responds with 404 when has a trailing slash', function (done) {
|
it('responds with 404 when has a trailing slash', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router({
|
const router = strapi.middlewares.router({
|
||||||
strict: true
|
strict: true
|
||||||
});
|
});
|
||||||
@ -1110,7 +1111,7 @@ describe('router', function () {
|
|||||||
|
|
||||||
describe('router.routes()', function () {
|
describe('router.routes()', function () {
|
||||||
it('should return composed middleware', function (done) {
|
it('should return composed middleware', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
let middlewareCount = 0;
|
let middlewareCount = 0;
|
||||||
@ -1156,9 +1157,9 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if no `HEAD` method, default to `GET`', function () {
|
describe('if no HEAD method, default to GET', function () {
|
||||||
it('should default to GET', function (done) {
|
it('should default to GET', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.get('/users/:id', function * () {
|
router.get('/users/:id', function * () {
|
||||||
@ -1182,7 +1183,7 @@ describe('router', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should work with middleware', function (done) {
|
it('should work with middleware', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.get('/users/:id', function * () {
|
router.get('/users/:id', function * () {
|
||||||
@ -1241,7 +1242,7 @@ describe('router', function () {
|
|||||||
let middlewareCount = 0;
|
let middlewareCount = 0;
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
const router = strapi.middlewares.router();
|
||||||
|
|
||||||
router.get('/', function * () {
|
router.get('/', function * () {
|
||||||
@ -1327,7 +1328,7 @@ describe('router', function () {
|
|||||||
url.should.equal('/programming/how-to-node');
|
url.should.equal('/programming/how-to-node');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('escapes using `encodeURIComponent()`', function () {
|
it('escapes using encodeURIComponent()', function () {
|
||||||
const router = strapi.middlewares.router;
|
const router = strapi.middlewares.router;
|
||||||
|
|
||||||
const url = router.url('/:category/:title', {
|
const url = router.url('/:category/:title', {
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
const should = require('should');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('session', function () {
|
describe('session', function () {
|
||||||
let cookie;
|
let cookie;
|
||||||
@ -10,7 +12,7 @@ describe('session', function () {
|
|||||||
describe('when options.signed = true', function () {
|
describe('when options.signed = true', function () {
|
||||||
describe('when app.keys are set', function () {
|
describe('when app.keys are set', function () {
|
||||||
it('should work', function (done) {
|
it('should work', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('when app.keys are not set', function () {
|
describe('when app.keys are not set', function () {
|
||||||
it('should throw', function (done) {
|
it('should throw', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.session(app));
|
app.use(strapi.middlewares.session(app));
|
||||||
|
|
||||||
@ -44,21 +46,21 @@ describe('session', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('when app not set', function () {
|
describe('when app not set', function () {
|
||||||
// it('should throw', function () {
|
it('should throw', function () {
|
||||||
// const app = strapi.server();
|
const app = new Koa();
|
||||||
//
|
|
||||||
// (function () {
|
(function () {
|
||||||
// app.use(strapi.middlewares.session());
|
app.use(strapi.middlewares.session());
|
||||||
// });should.throw('app instance required: `session(opts, app)`');
|
}).should.throw('app instance required: `session(opts, app)`');
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when options.signed = false', function () {
|
describe('when options.signed = false', function () {
|
||||||
describe('when app.keys are not set', function () {
|
describe('when app.keys are not set', function () {
|
||||||
it('should work', function (done) {
|
it('should work', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.session({
|
app.use(strapi.middlewares.session({
|
||||||
signed: false
|
signed: false
|
||||||
@ -78,7 +80,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('when the session contains a ;', function () {
|
describe('when the session contains a ;', function () {
|
||||||
it('should still work', function (done) {
|
it('should still work', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -113,7 +115,7 @@ describe('session', function () {
|
|||||||
describe('new session', function () {
|
describe('new session', function () {
|
||||||
describe('when not accessed', function () {
|
describe('when not accessed', function () {
|
||||||
it('should not Set-Cookie', function (done) {
|
it('should not Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -137,7 +139,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('when accessed and not populated', function () {
|
describe('when accessed and not populated', function () {
|
||||||
it('should not Set-Cookie', function (done) {
|
it('should not Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -162,7 +164,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('when populated', function () {
|
describe('when populated', function () {
|
||||||
it('should Set-Cookie', function (done) {
|
it('should Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -186,7 +188,7 @@ describe('session', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not Set-Cookie', function (done) {
|
it('should not Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -212,7 +214,7 @@ describe('session', function () {
|
|||||||
describe('saved session', function () {
|
describe('saved session', function () {
|
||||||
describe('when not accessed', function () {
|
describe('when not accessed', function () {
|
||||||
it('should not Set-Cookie', function (done) {
|
it('should not Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -237,7 +239,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('when accessed but not changed', function () {
|
describe('when accessed but not changed', function () {
|
||||||
it('should be the same session', function (done) {
|
it('should be the same session', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -255,7 +257,7 @@ describe('session', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not Set-Cookie', function (done) {
|
it('should not Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -281,7 +283,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('when accessed and changed', function () {
|
describe('when accessed and changed', function () {
|
||||||
it('should Set-Cookie', function (done) {
|
it('should Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -304,7 +306,7 @@ describe('session', function () {
|
|||||||
describe('when session is', function () {
|
describe('when session is', function () {
|
||||||
describe('null', function () {
|
describe('null', function () {
|
||||||
it('should expire the session', function (done) {
|
it('should expire the session', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -324,7 +326,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('an empty object', function () {
|
describe('an empty object', function () {
|
||||||
it('should not Set-Cookie', function (done) {
|
it('should not Set-Cookie', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -349,7 +351,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('an object', function () {
|
describe('an object', function () {
|
||||||
it('should create a session', function (done) {
|
it('should create a session', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -371,7 +373,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('anything else', function () {
|
describe('anything else', function () {
|
||||||
it('should throw', function (done) {
|
it('should throw', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -390,7 +392,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('when an error is thrown downstream and caught upstream', function () {
|
describe('when an error is thrown downstream and caught upstream', function () {
|
||||||
it('should still save the session', function (done) {
|
it('should still save the session', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -424,7 +426,7 @@ describe('session', function () {
|
|||||||
describe('when maxAge present', function () {
|
describe('when maxAge present', function () {
|
||||||
describe('and not expire', function () {
|
describe('and not expire', function () {
|
||||||
it('should not expire the session', function (done) {
|
it('should not expire the session', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -462,7 +464,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('and expired', function () {
|
describe('and expired', function () {
|
||||||
it('should expire the sess', function (done) {
|
it('should expire the sess', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -503,7 +505,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('ctx.session.maxAge', function () {
|
describe('ctx.session.maxAge', function () {
|
||||||
it('should return opt.maxAge', function (done) {
|
it('should return opt.maxAge', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -523,7 +525,7 @@ describe('session', function () {
|
|||||||
|
|
||||||
describe('ctx.session.maxAge=', function () {
|
describe('ctx.session.maxAge=', function () {
|
||||||
it('should set sessionOptions.maxAge', function (done) {
|
it('should set sessionOptions.maxAge', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.keys = ['a', 'b'];
|
app.keys = ['a', 'b'];
|
||||||
|
|
||||||
@ -542,146 +544,146 @@ describe('session', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('when get session before enter session middleware', function () {
|
describe('when get session before enter session middleware', function () {
|
||||||
// it('should work', function (done) {
|
it('should work', function (done) {
|
||||||
// const app = strapi.server();
|
const app = new Koa();
|
||||||
//
|
|
||||||
// app.keys = ['a', 'b'];
|
|
||||||
// app.use(function * (next) {
|
|
||||||
// this.session.foo = 'hi';
|
|
||||||
// yield next;
|
|
||||||
// });
|
|
||||||
// app.use(strapi.middlewares.session({}, app));
|
|
||||||
// app.use(function * () {
|
|
||||||
// this.body = this.session;
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// request(app.callback())
|
|
||||||
// .get('/')
|
|
||||||
// .expect(200, function (err, res) {
|
|
||||||
// should.not.exist(err);
|
|
||||||
// const cookies = res.headers['set-cookie'].join(';');
|
|
||||||
// cookies.should.containEql('koa:sess=');
|
|
||||||
//
|
|
||||||
// request(app.callback())
|
|
||||||
// .get('/')
|
|
||||||
// .set('Cookie', cookies)
|
|
||||||
// .expect(200, done);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// describe('when valid and beforeSave set', function () {
|
app.keys = ['a', 'b'];
|
||||||
// it('should ignore session when uid changed', function (done) {
|
app.use(function * (next) {
|
||||||
// const app = strapi.server();
|
this.session.foo = 'hi';
|
||||||
//
|
yield next;
|
||||||
// app.keys = ['a', 'b'];
|
});
|
||||||
//
|
app.use(strapi.middlewares.session({}, app));
|
||||||
// app.use(strapi.middlewares.session({
|
app.use(function * () {
|
||||||
// valid: function (ctx, sess) {
|
this.body = this.session;
|
||||||
// return ctx.cookies.get('uid') === sess.uid;
|
});
|
||||||
// },
|
|
||||||
// beforeSave: function (ctx, sess) {
|
request(app.callback())
|
||||||
// sess.uid = ctx.cookies.get('uid');
|
.get('/')
|
||||||
// }
|
.expect(200, function (err, res) {
|
||||||
// }, app));
|
should.not.exist(err);
|
||||||
//
|
const cookies = res.headers['set-cookie'].join(';');
|
||||||
// app.use(function * () {
|
cookies.should.containEql('koa:sess=');
|
||||||
// if (!this.session.foo) {
|
|
||||||
// this.session.foo = Date.now() + '|uid:' + this.cookies.get('uid');
|
request(app.callback())
|
||||||
// }
|
.get('/')
|
||||||
//
|
.set('Cookie', cookies)
|
||||||
// this.body = {
|
.expect(200, done);
|
||||||
// foo: this.session.foo,
|
});
|
||||||
// uid: this.cookies.get('uid')
|
});
|
||||||
// };
|
});
|
||||||
// });
|
|
||||||
//
|
describe('when valid and beforeSave set', function () {
|
||||||
// request(app.callback())
|
it('should ignore session when uid changed', function (done) {
|
||||||
// .get('/')
|
const app = new Koa();
|
||||||
// .set('Cookie', 'uid=123')
|
|
||||||
// .expect(200, function (err, res) {
|
app.keys = ['a', 'b'];
|
||||||
// should.not.exist(err);
|
|
||||||
// const data = res.body;
|
app.use(strapi.middlewares.session({
|
||||||
// const cookies = res.headers['set-cookie'].join(';');
|
valid: function (ctx, sess) {
|
||||||
// cookies.should.containEql('koa:sess=');
|
return ctx.cookies.get('uid') === sess.uid;
|
||||||
//
|
},
|
||||||
// request(app.callback())
|
beforeSave: function (ctx, sess) {
|
||||||
// .get('/')
|
sess.uid = ctx.cookies.get('uid');
|
||||||
// .set('Cookie', cookies + ';uid=123')
|
}
|
||||||
// .expect(200)
|
}, app));
|
||||||
// .expect(data, function (err) {
|
|
||||||
// should.not.exist(err);
|
app.use(function * () {
|
||||||
//
|
if (!this.session.foo) {
|
||||||
// request(app.callback())
|
this.session.foo = Date.now() + '|uid:' + this.cookies.get('uid');
|
||||||
// .get('/')
|
}
|
||||||
// .set('Cookie', cookies + ';uid=456')
|
|
||||||
// .expect(200, function (err, res) {
|
this.body = {
|
||||||
// should.not.exist(err);
|
foo: this.session.foo,
|
||||||
// res.body.uid.should.equal('456');
|
uid: this.cookies.get('uid')
|
||||||
// res.body.foo.should.not.equal(data.foo);
|
};
|
||||||
// done();
|
});
|
||||||
// });
|
|
||||||
// });
|
request(app.callback())
|
||||||
// });
|
.get('/')
|
||||||
// });
|
.set('Cookie', 'uid=123')
|
||||||
// });
|
.expect(200, function (err, res) {
|
||||||
//
|
should.not.exist(err);
|
||||||
// describe('when options.encode and options.decode are functions', function () {
|
const data = res.body;
|
||||||
// describe('they are used to encode/decode stored cookie values', function () {
|
const cookies = res.headers['set-cookie'].join(';');
|
||||||
// it('should work', function (done) {
|
cookies.should.containEql('koa:sess=');
|
||||||
// let encodeCallCount = 0;
|
|
||||||
// let decodeCallCount = 0;
|
request(app.callback())
|
||||||
//
|
.get('/')
|
||||||
// function encode(data) {
|
.set('Cookie', cookies + ';uid=123')
|
||||||
// ++encodeCallCount;
|
.expect(200)
|
||||||
// return JSON.stringify({
|
.expect(data, function (err) {
|
||||||
// enveloped: data
|
should.not.exist(err);
|
||||||
// });
|
|
||||||
// }
|
request(app.callback())
|
||||||
//
|
.get('/')
|
||||||
// function decode(data) {
|
.set('Cookie', cookies + ';uid=456')
|
||||||
// ++decodeCallCount;
|
.expect(200, function (err, res) {
|
||||||
// return JSON.parse(data).enveloped;
|
should.not.exist(err);
|
||||||
// }
|
res.body.uid.should.equal('456');
|
||||||
//
|
res.body.foo.should.not.equal(data.foo);
|
||||||
// const app = strapi.server();
|
done();
|
||||||
//
|
});
|
||||||
// app.keys = ['a', 'b'];
|
});
|
||||||
//
|
});
|
||||||
// app.use(strapi.middlewares.session({
|
});
|
||||||
// encode: encode,
|
});
|
||||||
// decode: decode
|
|
||||||
// }, app));
|
describe('when options.encode and options.decode are functions', function () {
|
||||||
//
|
describe('they are used to encode/decode stored cookie values', function () {
|
||||||
// app.use(function * () {
|
it('should work', function (done) {
|
||||||
// this.session.counter = (this.session.counter || 0) + 1;
|
let encodeCallCount = 0;
|
||||||
// this.body = this.session;
|
let decodeCallCount = 0;
|
||||||
// return;
|
|
||||||
// });
|
function encode(data) {
|
||||||
//
|
++encodeCallCount;
|
||||||
// request(app.callback())
|
return JSON.stringify({
|
||||||
// .get('/')
|
enveloped: data
|
||||||
// .expect(function () {
|
});
|
||||||
// encodeCallCount.should.above(0, 'encode was not called');
|
}
|
||||||
// })
|
|
||||||
// .expect(200, function (err, res) {
|
function decode(data) {
|
||||||
// should.not.exist(err);
|
++decodeCallCount;
|
||||||
// res.body.counter.should.equal(1, 'expected body to be equal to session.counter');
|
return JSON.parse(data).enveloped;
|
||||||
// const cookies = res.headers['set-cookie'].join(';');
|
}
|
||||||
// request(app.callback())
|
|
||||||
// .get('/')
|
const app = new Koa();
|
||||||
// .set('Cookie', cookies)
|
|
||||||
// .expect(function () {
|
app.keys = ['a', 'b'];
|
||||||
// decodeCallCount.should.be.above(1, 'decode was not called');
|
|
||||||
// })
|
app.use(strapi.middlewares.session({
|
||||||
// .expect(200, function (err, res) {
|
encode: encode,
|
||||||
// should.not.exist(err);
|
decode: decode
|
||||||
// res.body.counter.should.equal(2);
|
}, app));
|
||||||
// done();
|
|
||||||
// });
|
app.use(function * () {
|
||||||
// });
|
this.session.counter = (this.session.counter || 0) + 1;
|
||||||
// });
|
this.body = this.session;
|
||||||
// });
|
return;
|
||||||
// });
|
});
|
||||||
|
|
||||||
|
request(app.callback())
|
||||||
|
.get('/')
|
||||||
|
.expect(function () {
|
||||||
|
encodeCallCount.should.above(0, 'encode was not called');
|
||||||
|
})
|
||||||
|
.expect(200, function (err, res) {
|
||||||
|
should.not.exist(err);
|
||||||
|
res.body.counter.should.equal(1, 'expected body to be equal to session.counter');
|
||||||
|
const cookies = res.headers['set-cookie'].join(';');
|
||||||
|
request(app.callback())
|
||||||
|
.get('/')
|
||||||
|
.set('Cookie', cookies)
|
||||||
|
.expect(function () {
|
||||||
|
decodeCallCount.should.be.above(1, 'decode was not called');
|
||||||
|
})
|
||||||
|
.expect(200, function (err, res) {
|
||||||
|
should.not.exist(err);
|
||||||
|
res.body.counter.should.equal(2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,12 +5,13 @@ const path = require('path');
|
|||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../../..');
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('assets', function () {
|
describe('assets', function () {
|
||||||
describe('when defer: false', function () {
|
describe('when defer: false', function () {
|
||||||
describe('when root = "."', function () {
|
describe('when root = "."', function () {
|
||||||
it('should serve from cwd', function (done) {
|
it('should serve from cwd', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static('.'));
|
app.use(strapi.middlewares.static('.'));
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('when path is not a file', function () {
|
describe('when path is not a file', function () {
|
||||||
it('should 404', function (done) {
|
it('should 404', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('when upstream middleware responds', function () {
|
describe('when upstream middleware responds', function () {
|
||||||
it('should respond', function (done) {
|
it('should respond', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('the path is valid', function () {
|
describe('the path is valid', function () {
|
||||||
it('should serve the file', function (done) {
|
it('should serve the file', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ describe('assets', function () {
|
|||||||
describe('.index', function () {
|
describe('.index', function () {
|
||||||
describe('when present', function () {
|
describe('when present', function () {
|
||||||
it('should alter the index file supported', function (done) {
|
it('should alter the index file supported', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
index: 'index.txt'
|
index: 'index.txt'
|
||||||
@ -82,7 +83,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('when omitted', function () {
|
describe('when omitted', function () {
|
||||||
it('should use index.html', function (done) {
|
it('should use index.html', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('when method is not `GET` or `HEAD`', function () {
|
describe('when method is not `GET` or `HEAD`', function () {
|
||||||
it('should 404', function (done) {
|
it('should 404', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures')));
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ describe('assets', function () {
|
|||||||
describe('when defer: true', function () {
|
describe('when defer: true', function () {
|
||||||
describe('when upstream middleware responds', function () {
|
describe('when upstream middleware responds', function () {
|
||||||
it('should do nothing', function (done) {
|
it('should do nothing', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true
|
defer: true
|
||||||
@ -131,7 +132,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('the path is valid', function () {
|
describe('the path is valid', function () {
|
||||||
it('should serve the file', function (done) {
|
it('should serve the file', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true
|
defer: true
|
||||||
@ -147,7 +148,7 @@ describe('assets', function () {
|
|||||||
describe('.index', function () {
|
describe('.index', function () {
|
||||||
describe('when present', function () {
|
describe('when present', function () {
|
||||||
it('should alter the index file supported', function (done) {
|
it('should alter the index file supported', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true,
|
defer: true,
|
||||||
@ -164,7 +165,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('when omitted', function () {
|
describe('when omitted', function () {
|
||||||
it('should use index.html', function (done) {
|
it('should use index.html', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true
|
defer: true
|
||||||
@ -181,7 +182,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('when path is not a file', function () {
|
describe('when path is not a file', function () {
|
||||||
it('should 404', function (done) {
|
it('should 404', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true
|
defer: true
|
||||||
@ -195,7 +196,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('it should not handle the request', function () {
|
describe('it should not handle the request', function () {
|
||||||
it('when status=204', function (done) {
|
it('when status=204', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true
|
defer: true
|
||||||
@ -211,7 +212,7 @@ describe('assets', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('when body=""', function (done) {
|
it('when body=""', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true
|
defer: true
|
||||||
@ -229,7 +230,7 @@ describe('assets', function () {
|
|||||||
|
|
||||||
describe('when method is not `GET` or `HEAD`', function () {
|
describe('when method is not `GET` or `HEAD`', function () {
|
||||||
it('should 404', function (done) {
|
it('should 404', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.static(path.resolve(__dirname, 'fixtures'), {
|
||||||
defer: true
|
defer: true
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const request = require('supertest')
|
const request = require('supertest');
|
||||||
const should = require('should')
|
|
||||||
|
|
||||||
const strapi = require('../../..')
|
const strapi = require('../../..');
|
||||||
|
const Koa = strapi.server;
|
||||||
|
|
||||||
describe('views', function () {
|
describe('views', function () {
|
||||||
it('have a render method', function (done) {
|
it('have a render method', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.views());
|
app.use(strapi.middlewares.views());
|
||||||
|
|
||||||
@ -24,28 +23,28 @@ describe('views', function () {
|
|||||||
.expect(404, done);
|
.expect(404, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('default to html', function (done) {
|
// it('default to html', function (done) {
|
||||||
const app = strapi.server();
|
// const app = new Koa();
|
||||||
const router = strapi.middlewares.router();
|
// const router = strapi.middlewares.router();
|
||||||
|
//
|
||||||
|
// app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures')));
|
||||||
|
//
|
||||||
|
// router.get('/', function * () {
|
||||||
|
// yield this.render('basic');
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// app.use(router.routes());
|
||||||
|
// app.use(router.allowedMethods());
|
||||||
|
//
|
||||||
|
// request(app.listen())
|
||||||
|
// .get('/')
|
||||||
|
// .expect('Content-Type', /html/)
|
||||||
|
// .expect(/basic:html/)
|
||||||
|
// .expect(200, done);
|
||||||
|
// });
|
||||||
|
|
||||||
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures')));
|
it('default to ext if a default engine is set', function (done) {
|
||||||
|
const app = new Koa();
|
||||||
router.get('/', function * () {
|
|
||||||
yield this.render('basic');
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(router.routes());
|
|
||||||
app.use(router.allowedMethods());
|
|
||||||
|
|
||||||
request(app.listen())
|
|
||||||
.get('/')
|
|
||||||
.expect('Content-Type', /html/)
|
|
||||||
.expect(/basic:html/)
|
|
||||||
.expect(200, done);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('default to [ext] if a default engine is set', function (done) {
|
|
||||||
const app = strapi.server();
|
|
||||||
|
|
||||||
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
||||||
default: 'jade'
|
default: 'jade'
|
||||||
@ -63,7 +62,7 @@ describe('views', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('set and render state', function (done) {
|
it('set and render state', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
||||||
default: 'jade'
|
default: 'jade'
|
||||||
@ -82,7 +81,7 @@ describe('views', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('set option: root', function (done) {
|
it('set option: root', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
||||||
root: '../../../test',
|
root: '../../../test',
|
||||||
@ -102,7 +101,7 @@ describe('views', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('works with circular references in state', function (done) {
|
it('works with circular references in state', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
||||||
default: 'jade'
|
default: 'jade'
|
||||||
@ -130,8 +129,8 @@ describe('views', function () {
|
|||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('`map` given `engine` to given file `ext`', function (done) {
|
it('map given engine to given file ext', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
||||||
map: {
|
map: {
|
||||||
@ -152,7 +151,7 @@ describe('views', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('merges global and local state ', function (done) {
|
it('merges global and local state ', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
app.use(strapi.middlewares.views(path.resolve(__dirname, 'fixtures'), {
|
||||||
default: 'jade'
|
default: 'jade'
|
||||||
@ -174,7 +173,7 @@ describe('views', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('yields to the next middleware if this.render is already defined', function (done) {
|
it('yields to the next middleware if this.render is already defined', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * (next) {
|
app.use(function * (next) {
|
||||||
this.render = true;
|
this.render = true;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ describe('req.host', function () {
|
|||||||
it('should be ignored', function () {
|
it('should be ignored', function () {
|
||||||
const req = request();
|
const req = request();
|
||||||
req.header['x-forwarded-host'] = 'bar.com';
|
req.header['x-forwarded-host'] = 'bar.com';
|
||||||
req.header['host'] = 'foo.com';
|
req.header.host = 'foo.com';
|
||||||
req.host.should.equal('foo.com');
|
req.host.should.equal('foo.com');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -33,7 +33,7 @@ describe('req.host', function () {
|
|||||||
const req = request();
|
const req = request();
|
||||||
req.app.proxy = true;
|
req.app.proxy = true;
|
||||||
req.header['x-forwarded-host'] = 'bar.com, baz.com';
|
req.header['x-forwarded-host'] = 'bar.com, baz.com';
|
||||||
req.header['host'] = 'foo.com';
|
req.header.host = 'foo.com';
|
||||||
req.host.should.equal('bar.com');
|
req.host.should.equal('bar.com');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -23,7 +23,7 @@ describe('req.hostname', function () {
|
|||||||
it('should be ignored', function () {
|
it('should be ignored', function () {
|
||||||
const req = request();
|
const req = request();
|
||||||
req.header['x-forwarded-host'] = 'bar.com';
|
req.header['x-forwarded-host'] = 'bar.com';
|
||||||
req.header['host'] = 'foo.com';
|
req.header.host = 'foo.com';
|
||||||
req.hostname.should.equal('foo.com');
|
req.hostname.should.equal('foo.com');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -33,7 +33,7 @@ describe('req.hostname', function () {
|
|||||||
const req = request();
|
const req = request();
|
||||||
req.app.proxy = true;
|
req.app.proxy = true;
|
||||||
req.header['x-forwarded-host'] = 'bar.com, baz.com';
|
req.header['x-forwarded-host'] = 'bar.com, baz.com';
|
||||||
req.header['host'] = 'foo.com';
|
req.header.host = 'foo.com';
|
||||||
req.hostname.should.equal('bar.com');
|
req.hostname.should.equal('bar.com');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
const context = require('../helpers/context');
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
|
|
||||||
const strapi = require('../..');
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
const context = require('../helpers/context');
|
|
||||||
|
|
||||||
describe('ctx.href', function () {
|
describe('ctx.href', function () {
|
||||||
it('should return the full request url', function () {
|
it('should return the full request url', function () {
|
||||||
@ -18,6 +17,7 @@ describe('ctx.href', function () {
|
|||||||
socket: socket,
|
socket: socket,
|
||||||
__proto__: Stream.Readable.prototype
|
__proto__: Stream.Readable.prototype
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctx = context(req);
|
const ctx = context(req);
|
||||||
ctx.href.should.equal('http://localhost/users/1?next=/dashboard');
|
ctx.href.should.equal('http://localhost/users/1?next=/dashboard');
|
||||||
ctx.url = '/foo/users/1?next=/dashboard';
|
ctx.url = '/foo/users/1?next=/dashboard';
|
||||||
@ -25,10 +25,12 @@ describe('ctx.href', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should work with `GET http://example.com/foo`', function (done) {
|
it('should work with `GET http://example.com/foo`', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.body = this.href;
|
this.body = this.href;
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(function () {
|
app.listen(function () {
|
||||||
const address = this.address();
|
const address = this.address();
|
||||||
http.get({
|
http.get({
|
||||||
|
|||||||
@ -14,10 +14,18 @@ describe('req.ip', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with no req.ips present', function () {
|
describe('with no req.ips present', function () {
|
||||||
it('should return req.socket.removeAddress', function () {
|
it('should return req.socket.remoteAddress', function () {
|
||||||
const req = request();
|
const req = request();
|
||||||
req.socket.remoteAddress = '127.0.0.2';
|
req.socket.remoteAddress = '127.0.0.2';
|
||||||
req.ip.should.equal('127.0.0.2');
|
req.ip.should.equal('127.0.0.2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with req.socket.remoteAddress not present', function () {
|
||||||
|
it('should return an empty string', function () {
|
||||||
|
const req = request();
|
||||||
|
req.socket.remoteAddress = null;
|
||||||
|
req.ip.should.equal('');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
23
test/request/origin.js
Executable file
23
test/request/origin.js
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Stream = require('stream');
|
||||||
|
|
||||||
|
const context = require('../helpers/context');
|
||||||
|
|
||||||
|
describe('ctx.origin', function () {
|
||||||
|
it('should return the origin of url', function () {
|
||||||
|
const socket = new Stream.Duplex();
|
||||||
|
const req = {
|
||||||
|
url: '/users/1?next=/dashboard',
|
||||||
|
headers: {
|
||||||
|
host: 'localhost'
|
||||||
|
},
|
||||||
|
socket: socket,
|
||||||
|
__proto__: Stream.Readable.prototype
|
||||||
|
};
|
||||||
|
const ctx = context(req);
|
||||||
|
ctx.origin.should.equal('http://localhost');
|
||||||
|
ctx.url = '/foo/users/1?next=/dashboard';
|
||||||
|
ctx.origin.should.equal('http://localhost');
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -2,6 +2,23 @@
|
|||||||
|
|
||||||
const context = require('../helpers/context');
|
const context = require('../helpers/context');
|
||||||
|
|
||||||
|
describe('ctx.querystring', function () {
|
||||||
|
it('should return the querystring', function () {
|
||||||
|
const ctx = context({
|
||||||
|
url: '/store/shoes?page=2&color=blue'
|
||||||
|
});
|
||||||
|
ctx.querystring.should.equal('page=2&color=blue');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when ctx.req not present', function () {
|
||||||
|
it('should return an empty string', function () {
|
||||||
|
const ctx = context();
|
||||||
|
ctx.request.req = null;
|
||||||
|
ctx.querystring.should.equal('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ctx.querystring=', function () {
|
describe('ctx.querystring=', function () {
|
||||||
it('should replace the querystring', function () {
|
it('should replace the querystring', function () {
|
||||||
const ctx = context({
|
const ctx = context({
|
||||||
|
|||||||
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
|
||||||
const strapi = require('../..');
|
|
||||||
|
|
||||||
const context = require('../helpers/context');
|
const context = require('../helpers/context');
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
describe('ctx.attachment([filename])', function () {
|
describe('ctx.attachment([filename])', function () {
|
||||||
describe('when given a filename', function () {
|
describe('when given a filename', function () {
|
||||||
it('should set the filename param', function () {
|
it('should set the filename param', function () {
|
||||||
@ -33,7 +33,7 @@ describe('ctx.attachment([filename])', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should work with http client', function (done) {
|
it('should work with http client', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.attachment('path/to/include-no-ascii-char-中文名-ok.json');
|
this.attachment('path/to/include-no-ascii-char-中文名-ok.json');
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const response = require('../helpers/context').response;
|
const response = require('../helpers/context').response;
|
||||||
|
|||||||
@ -45,7 +45,7 @@ describe('ctx.redirect(url)', function () {
|
|||||||
ctx.header.accept = 'text/html';
|
ctx.header.accept = 'text/html';
|
||||||
ctx.redirect(url);
|
ctx.redirect(url);
|
||||||
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
||||||
ctx.body.should.equal('Redirecting to <a href="' + url + '">' + url + '</a>.');
|
ctx.body.should.equal(`Redirecting to <a href="${url}">${url}</a>.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should escape the url', function () {
|
it('should escape the url', function () {
|
||||||
@ -55,7 +55,7 @@ describe('ctx.redirect(url)', function () {
|
|||||||
ctx.redirect(url);
|
ctx.redirect(url);
|
||||||
url = escape(url);
|
url = escape(url);
|
||||||
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
ctx.response.header['content-type'].should.equal('text/html; charset=utf-8');
|
||||||
ctx.body.should.equal('Redirecting to <a href="' + url + '">' + url + '</a>.');
|
ctx.body.should.equal(`Redirecting to <a href="${url}">${url}</a>.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ describe('ctx.redirect(url)', function () {
|
|||||||
const url = 'http://google.com';
|
const url = 'http://google.com';
|
||||||
ctx.header.accept = 'text/plain';
|
ctx.header.accept = 'text/plain';
|
||||||
ctx.redirect(url);
|
ctx.redirect(url);
|
||||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ describe('ctx.redirect(url)', function () {
|
|||||||
ctx.header.accept = 'text/plain';
|
ctx.header.accept = 'text/plain';
|
||||||
ctx.redirect('http://google.com');
|
ctx.redirect('http://google.com');
|
||||||
ctx.status.should.equal(301);
|
ctx.status.should.equal(301);
|
||||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ describe('ctx.redirect(url)', function () {
|
|||||||
ctx.header.accept = 'text/plain';
|
ctx.header.accept = 'text/plain';
|
||||||
ctx.redirect('http://google.com');
|
ctx.redirect('http://google.com');
|
||||||
ctx.status.should.equal(302);
|
ctx.status.should.equal(302);
|
||||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ describe('ctx.redirect(url)', function () {
|
|||||||
ctx.header.accept = 'text/plain';
|
ctx.header.accept = 'text/plain';
|
||||||
ctx.redirect('http://google.com');
|
ctx.redirect('http://google.com');
|
||||||
ctx.status.should.equal(302);
|
ctx.status.should.equal(302);
|
||||||
ctx.body.should.equal('Redirecting to ' + url + '.');
|
ctx.body.should.equal(`Redirecting to ${url}.`);
|
||||||
ctx.type.should.equal('text/plain');
|
ctx.type.should.equal('text/plain');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const request = require('supertest');
|
const request = require('supertest');
|
||||||
|
const statuses = require('statuses');
|
||||||
const strapi = require('../..');
|
|
||||||
|
|
||||||
const response = require('../helpers/context').response;
|
const response = require('../helpers/context').response;
|
||||||
|
|
||||||
|
const Koa = require('../..').server;
|
||||||
|
|
||||||
describe('res.status=', function () {
|
describe('res.status=', function () {
|
||||||
describe('when a status code', function () {
|
describe('when a status code', function () {
|
||||||
describe('and valid', function () {
|
describe('and valid', function () {
|
||||||
@ -31,23 +32,23 @@ describe('res.status=', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('and custom status', function () {
|
describe('and custom status', function () {
|
||||||
// before(function () {
|
before(function () {
|
||||||
// statuses['700'] = 'custom status';
|
statuses['700'] = 'custom status';
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// it('should set the status', function () {
|
it('should set the status', function () {
|
||||||
// const res = response();
|
const res = response();
|
||||||
// res.status = 700;
|
res.status = 700;
|
||||||
// res.status.should.equal(700);
|
res.status.should.equal(700);
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// it('should not throw', function() {
|
it('should not throw', function () {
|
||||||
// assert.doesNotThrow(function() {
|
assert.doesNotThrow(function () {
|
||||||
// response().status = 700;
|
response().status = 700;
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when a status string', function () {
|
describe('when a status string', function () {
|
||||||
@ -60,7 +61,7 @@ describe('res.status=', function () {
|
|||||||
|
|
||||||
function strip (status) {
|
function strip (status) {
|
||||||
it('should strip content related header fields', function (done) {
|
it('should strip content related header fields', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.body = {
|
this.body = {
|
||||||
@ -88,7 +89,7 @@ describe('res.status=', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should strip content releated header fields after status set', function (done) {
|
it('should strip content releated header fields after status set', function (done) {
|
||||||
const app = strapi.server();
|
const app = new Koa();
|
||||||
|
|
||||||
app.use(function * () {
|
app.use(function * () {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user