auth.js — express Source File
Architecture documentation for auth.js, a javascript file in the express codebase.
Entity Profile
Relationship Graph
Source Code
var app = require('../../examples/auth')
var request = require('supertest')
function getCookie(res) {
return res.headers['set-cookie'][0].split(';')[0];
}
describe('auth', function(){
describe('GET /',function(){
it('should redirect to /login', function(done){
request(app)
.get('/')
.expect('Location', '/login')
.expect(302, done)
})
})
describe('GET /login',function(){
it('should render login form', function(done){
request(app)
.get('/login')
.expect(200, /<form/, done)
})
it('should display login error for bad user', function (done) {
request(app)
.post('/login')
.type('urlencoded')
.send('username=not-tj&password=foobar')
.expect('Location', '/login')
.expect(302, function(err, res){
if (err) return done(err)
request(app)
.get('/login')
.set('Cookie', getCookie(res))
.expect(200, /Authentication failed/, done)
})
})
it('should display login error for bad password', function (done) {
request(app)
.post('/login')
.type('urlencoded')
.send('username=tj&password=nogood')
.expect('Location', '/login')
.expect(302, function (err, res) {
if (err) return done(err)
request(app)
.get('/login')
.set('Cookie', getCookie(res))
.expect(200, /Authentication failed/, done)
})
})
})
describe('GET /logout',function(){
it('should redirect to /', function(done){
request(app)
.get('/logout')
.expect('Location', '/')
.expect(302, done)
})
})
describe('GET /restricted',function(){
it('should redirect to /login without cookie', function(done){
request(app)
.get('/restricted')
.expect('Location', '/login')
.expect(302, done)
})
it('should succeed with proper cookie', function(done){
request(app)
.post('/login')
.type('urlencoded')
.send('username=tj&password=foobar')
.expect('Location', '/')
.expect(302, function(err, res){
if (err) return done(err)
request(app)
.get('/restricted')
.set('Cookie', getCookie(res))
.expect(200, done)
})
})
})
describe('POST /login', function(){
it('should fail without proper username', function(done){
request(app)
.post('/login')
.type('urlencoded')
.send('username=not-tj&password=foobar')
.expect('Location', '/login')
.expect(302, done)
})
it('should fail without proper password', function(done){
request(app)
.post('/login')
.type('urlencoded')
.send('username=tj&password=baz')
.expect('Location', '/login')
.expect(302, done)
})
it('should succeed with proper credentials', function(done){
request(app)
.post('/login')
.type('urlencoded')
.send('username=tj&password=foobar')
.expect('Location', '/')
.expect(302, done)
})
})
})
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does auth.js do?
auth.js is a source file in the express codebase, written in javascript. It belongs to the ExpressCore domain, ApplicationInit subdomain.
What functions are defined in auth.js?
auth.js defines 1 function(s): getCookie.
Where is auth.js in the architecture?
auth.js is located at test/acceptance/auth.js (domain: ExpressCore, subdomain: ApplicationInit, directory: test/acceptance).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free