diff --git a/.travis.yml b/.travis.yml index f7c965e..4c10714 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,10 @@ -node_js: - - "0.11" - - "0.12" - - "iojs-1" - - "iojs-2" +sudo: false language: node_js -script: "npm run test-travis" -after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" +node_js: + - '5' + - '4' + - '0.12' +script: + - "npm run test-cov" +after_script: + - "npm i codecov.io && cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js" diff --git a/Readme.md b/Readme.md index 0ede205..931f121 100644 --- a/Readme.md +++ b/Readme.md @@ -2,31 +2,22 @@ [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] -[![Test coverage][coveralls-image]][coveralls-url] -[![Gittip][gittip-image]][gittip-url] +[![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] -[![iojs version][iojs-image]][iojs-url] -[![node version][node-image]][node-url] [![npm download][download-image]][download-url] [npm-image]: https://img.shields.io/npm/v/koa-session.svg?style=flat-square [npm-url]: https://npmjs.org/package/koa-session [travis-image]: https://img.shields.io/travis/koajs/session.svg?style=flat-square [travis-url]: https://travis-ci.org/koajs/session -[coveralls-image]: https://img.shields.io/coveralls/koajs/session.svg?style=flat-square -[coveralls-url]: https://coveralls.io/r/koajs/session?branch=master -[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat-square -[gittip-url]: https://www.gittip.com/fengmk2/ +[codecov-image]: https://codecov.io/github/koajs/session/coverage.svg?branch=master +[codecov-url]: https://codecov.io/github/koajs/session?branch=master [david-image]: https://img.shields.io/david/koajs/session.svg?style=flat-square [david-url]: https://david-dm.org/koajs/session -[iojs-image]: https://img.shields.io/badge/io.js-%3E=_1.0-yellow.svg?style=flat-square -[iojs-url]: http://iojs.org/ -[node-image]: https://img.shields.io/badge/node.js-%3E=_0.12-green.svg?style=flat-square -[node-url]: http://nodejs.org/download/ [download-image]: https://img.shields.io/npm/dm/koa-session.svg?style=flat-square [download-url]: https://npmjs.org/package/koa-session - Simple cookie-based session middleware for Koa. +Simple cookie-based session middleware for Koa. ## Installation @@ -36,7 +27,7 @@ $ npm install koa-session ## Example - View counter example: +View counter example: ```js var session = require('koa-session'); diff --git a/index.js b/index.js index 0b4a6e9..6f7c230 100644 --- a/index.js +++ b/index.js @@ -130,6 +130,10 @@ function initSessionOptions(ctx, opts) { for (var key in opts) { ctx.sessionOptions[key] = opts[key]; } + if (!ctx.sessionOptions.hasOwnProperty('secure')) { + // auto set secure on https request + ctx.sessionOptions.secure = ctx.secure; + } } /** diff --git a/package.json b/package.json index eb9f542..d75e37a 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "index.js" ], "devDependencies": { - "istanbul-harmony": "0", - "koa": "0", + "istanbul": "^0.4.1", + "koa": "1", "mocha": "2", "should": "6", "supertest": "1" @@ -25,8 +25,7 @@ "deep-equal": "~1.0.0" }, "scripts": { - "test": "NODE_ENV=test mocha --harmony --require should --reporter spec", - "test-cov": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require should", - "test-travis": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require should" + "test": "mocha --harmony -r should --reporter spec", + "test-cov": "node --harmony ./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -r should" } } diff --git a/test/test.js b/test/test.js index 4290409..c998404 100644 --- a/test/test.js +++ b/test/test.js @@ -6,6 +6,50 @@ var session = require('..'); describe('Koa Session', function(){ var cookie; + describe('options.secure', function(){ + it('should auto detect secure or not on ctx', function(done){ + var app = koa(); + + app.keys = ['a', 'b']; + app.use(session({}, app)); + + app.use(function *(){ + this.session.message = 'hi'; + this.session.secure = this.sessionOptions.secure; + this.body = this.session; + }); + + request(app.callback()) + .get('/') + .expect({ + message: 'hi', + secure: false, + }) + .expect(200, done); + }); + + it('should use options.secure', function(done){ + var app = koa(); + + app.keys = ['a', 'b']; + app.use(session({ secure: false }, app)); + + app.use(function *(){ + this.session.message = 'hi'; + this.session.secure = this.sessionOptions.secure; + this.body = this.session; + }); + + request(app.callback()) + .get('/') + .expect({ + message: 'hi', + secure: false, + }) + .expect(200, done); + }); + }); + describe('when options.signed = true', function(){ describe('when app.keys are set', function(){ it('should work', function(done){