remove req.auth
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jonathan Ong · committed by Jonathan Ong · parent 5e12bab · Browse files · 4 files·+1 added−125 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+1 added−125 removed
- tests:+0 added−100 removed
- other:+1 added−25 removed
Provenance
- Commit
68996d7- Tree
81a2e9d- Author
Jonathan Ong <jonathanrichardong@gmail.com>- Committer
Jonathan Ong <jonathanrichardong@gmail.com>- Parent
5e12bab
4 files changed+1 added−125 removed
modified:lib/request.js-24 removed
3 unmodified lines4 */5 6 var accepts = require('accepts');7 var typeis = require('type-is');8-var basicAuth = require('basic-auth');8 var http = require('http');9 var fresh = require('fresh');10 var parseRange = require('range-parser');11 var parse = require('parseurl');291 unmodified lines303 : [];304 });305 306 /**308- * Return basic auth credentials.309- *310- * Examples:311- *312- * // http://tobi:hello@example.com313- * req.auth314- * // => { username: 'tobi', password: 'hello' }315- *316- * @return {Object} or undefined317- * @api public318- */319-320-req.__defineGetter__('auth', function(){321- var auth = basicAuth(this);322- if (auth) {323- // aliases for backwards compatibilty324- auth.username = auth.name;325- auth.password = auth.pass;326- }327- return auth;328-});329-330-/**307 * Return subdomains as an array.308 *309 * Subdomains are the dot-separated parts of the host before the main domain of310 * the app. By default, the domain of the app is assumed to be the last two92 unmodified linesdeleted:test/req.auth.js-100 removed
1-2-var express = require('../')3- , request = require('supertest');4-5-describe('req', function(){6- describe('.auth', function(){7- describe('when Authorization is missing', function(){8- it('should return undefined', function(done){9- var app = express();10-11- app.get('/', function(req, res){12- res.send(req.auth || 'none');13- });14-15- request(app)16- .get('/')17- .expect('none', done)18- })19- })20-21- describe('when Authorization is malformed', function(){22- it('should return undefined', function(done){23- var app = express();24-25- app.get('/', function(req, res){26- res.send(req.auth || 'none');27- });28-29- request(app)30- .get('/')31- .set('Authorization', 'meow')32- .expect('none', done)33- })34- })35-36- describe('when Authorization is not Basic', function(){37- it('should return undefined', function(done){38- var app = express();39-40- app.get('/', function(req, res){41- res.send(req.auth || 'none');42- });43-44- request(app)45- .get('/')46- .set('Authorization', 'Meow dG9iaTpmZXJyZXQ')47- .expect('none', done)48- })49- })50-51- describe('when encoded string is malformed', function(){52- it('should return undefined', function(done){53- var app = express();54-55- app.get('/', function(req, res){56- res.send(req.auth || 'none');57- });58-59- request(app)60- .get('/')61- .set('Authorization', 'Basic Z21ldGh2aW4=')62- .expect('none', done)63- })64- })65-66- describe('when password contains a colon', function(){67- it('should return .username and .password', function(done){68- var app = express();69-70- app.get('/', function(req, res){71- res.send({72- username: req.auth.username,73- password: req.auth.password,74- });75- });76-77- request(app)78- .get('/')79- .set('Authorization', 'Basic dG9iaTpmZXJyZXQ6ZmVycmV0')80- .expect('{"username":"tobi","password":"ferret:ferret"}', done)81- })82- })83-84- it('should return .username and .password', function(done){85- var app = express();86-87- app.get('/', function(req, res){88- res.send({89- username: req.auth.username,90- password: req.auth.password,91- });92- });93-94- request(app)95- .get('/')96- .set('Authorization', 'Basic dG9iaTpmZXJyZXQ=')97- .expect('{"username":"tobi","password":"ferret"}', done)98- })99- })100-})modified:History.md+1 added
6 unmodified lines7 - express(1) - moved to [express-generator](https://github.com/expressjs/generator)8 - `express.createServer()` - it has been deprecated for a long time. Use `express()`9 - `app.configure` - use logic in your own app code10 - `app.router` - is removed11+ - `req.auth` - use `basic-auth` instead12 - `req.accepted*` - use `req.accepts*()` instead13 - `res.location` - relative URL resolution is removed14 - `res.charset` - include the charset in the content type when using `res.set()`15 - all bundled middleware except `static`1280 unmodified linesmodified:package.json-1 removed
21 unmodified lines22232425262627282951 unmodified lines21 unmodified lines } ], "dependencies": { "parseurl": "1.0.1", "basic-auth": "0.0.1", "accepts": "1.0.0", "type-is": "1.0.0", "range-parser": "1.0.0", "cookie": "0.1.0",51 unmodified lines