Skip to content
Myr

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

4 files+1 added−125 removed

modified:lib/request.js-24 removed
3 unmodified lines
4 */56var accepts = require('accepts');7var typeis = require('type-is');8var basicAuth = require('basic-auth');8var http = require('http');9var fresh = require('fresh');10var parseRange = require('range-parser');11var parse = require('parseurl');
291 unmodified lines
303 : [];304});305306/**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 */319320req.__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});329330/**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 two
92 unmodified lines
deleted:test/req.auth.js-100 removed
12var express = require('../')3 , request = require('supertest');45describe('req', function(){6 describe('.auth', function(){7 describe('when Authorization is missing', function(){8 it('should return undefined', function(done){9 var app = express();1011 app.get('/', function(req, res){12 res.send(req.auth || 'none');13 });1415 request(app)16 .get('/')17 .expect('none', done)18 })19 })2021 describe('when Authorization is malformed', function(){22 it('should return undefined', function(done){23 var app = express();2425 app.get('/', function(req, res){26 res.send(req.auth || 'none');27 });2829 request(app)30 .get('/')31 .set('Authorization', 'meow')32 .expect('none', done)33 })34 })3536 describe('when Authorization is not Basic', function(){37 it('should return undefined', function(done){38 var app = express();3940 app.get('/', function(req, res){41 res.send(req.auth || 'none');42 });4344 request(app)45 .get('/')46 .set('Authorization', 'Meow dG9iaTpmZXJyZXQ')47 .expect('none', done)48 })49 })5051 describe('when encoded string is malformed', function(){52 it('should return undefined', function(done){53 var app = express();5455 app.get('/', function(req, res){56 res.send(req.auth || 'none');57 });5859 request(app)60 .get('/')61 .set('Authorization', 'Basic Z21ldGh2aW4=')62 .expect('none', done)63 })64 })6566 describe('when password contains a colon', function(){67 it('should return .username and .password', function(done){68 var app = express();6970 app.get('/', function(req, res){71 res.send({72 username: req.auth.username,73 password: req.auth.password,74 });75 });7677 request(app)78 .get('/')79 .set('Authorization', 'Basic dG9iaTpmZXJyZXQ6ZmVycmV0')80 .expect('{"username":"tobi","password":"ferret:ferret"}', done)81 })82 })8384 it('should return .username and .password', function(done){85 var app = express();8687 app.get('/', function(req, res){88 res.send({89 username: req.auth.username,90 password: req.auth.password,91 });92 });9394 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 lines
7 - 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 lines
modified:package.json-1 removed