Skip to content

Commit

Permalink
Digest custom auth tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorg committed Jun 11, 2016
1 parent d210a9f commit 15e2e21
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 84 deletions.
72 changes: 0 additions & 72 deletions test-old/test-digest-nofile.coffee

This file was deleted.

6 changes: 3 additions & 3 deletions test/basic-nofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {expect} from 'chai'
// Request module.
import request from 'request'

// Source.
import auth from '../gensrc/http-auth'

// HTTP.
import http from 'http'

// Source.
import auth from '../gensrc/http-auth'

// Basic auth.
describe('basic', function () {
let server = undefined;
Expand Down
6 changes: 3 additions & 3 deletions test/basic-skipuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {expect} from 'chai'
// Request module.
import request from 'request'

// Source.
import auth from '../gensrc/http-auth'

// HTTP.
import http from 'http'

// Source.
import auth from '../gensrc/http-auth'

// Basic auth.
describe('basic', function () {
let server = undefined;
Expand Down
6 changes: 3 additions & 3 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {expect} from 'chai'
// Request module.
import request from 'request'

// Source.
import auth from '../gensrc/http-auth'

// HTTP.
import http from 'http'

// Source.
import auth from '../gensrc/http-auth'

// Basic auth.
describe('basic', function () {
let server = undefined;
Expand Down
93 changes: 93 additions & 0 deletions test/digest-nofile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"use strict";

// Expect module.
import {expect} from 'chai'

// Request module.
import request from 'request'

// HTTP.
import http from 'http'

// Source.
import auth from '../gensrc/http-auth'

// Utils.
import utils from '../gensrc/auth/utils'

// Digest auth.
describe('digest', function () {
let server = undefined;

before(function() {
// Configure authentication.
let digest = auth.digest({
realm: "Simon Area."
}, function(username, callback) {
if (username === "simon") {
return utils.md5("simon:Simon Area.:smart");
} else if (username === "gevorg") {
done(new Error("Error comes here"));
} else {
done();
}
});

// Creating new HTTP server.
server = http.createServer(digest, function (req, res) {
res.end(`Welcome to private area - ${req.user}!`);
});

// Start server.
server.listen(1337);
});

after(function() {
server.close();
});

it('error', function () {
let callback = function (error, response, body) {
expect(body).to.equal("Error comes here");
};

// Test request.
request.get('http://127.0.0.1:1337', callback).auth('gevorg', 'gpass', false);
});

it('success', function () {
let callback = function(error, response, body) {
expect(body).to.equal("Welcome to private area - simon!");
};

// Test request.
request.get('http://127.0.0.1:1337', callback).auth('simon', 'smart', false);
});

it('comma URI', function () {
let callback = function(error, response, body) {
expect(body).to.equal("Welcome to private area - simon!");
};

// Test request.
request.get('http://127.0.0.1:1337/comma,/', callback).auth('simon', 'smart', false);
});

it('wrong password', function () {
let callback = function(error, response, body) {
expect(body).to.equal("401 Unauthorized");
};

// Test request.
request.get('http://127.0.0.1:1337', callback).auth('simon', 'woolf', false);
});

it('wrong user', function () {
let callback = function(error, response, body) {
expect(body).to.equal("401 Unauthorized");
};

// Test request.
request.get('http://127.0.0.1:1337', callback).auth('virgina', 'smart', false);
});
});
6 changes: 3 additions & 3 deletions test/digest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {expect} from 'chai'
// Request module.
import request from 'request'

// Source.
import auth from '../gensrc/http-auth'

// HTTP.
import http from 'http'

// Source.
import auth from '../gensrc/http-auth'

// Digest auth.
describe('digest', function () {
let server = undefined;
Expand Down

0 comments on commit 15e2e21

Please sign in to comment.