Skip to content

Commit

Permalink
HTTPS and passport.
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorg committed Jun 11, 2016
1 parent 74e2623 commit b988de9
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 272 deletions.
62 changes: 0 additions & 62 deletions test-old/test-https-exception.coffee

This file was deleted.

74 changes: 0 additions & 74 deletions test-old/test-https.coffee

This file was deleted.

70 changes: 0 additions & 70 deletions test-old/test-passport-exception.coffee

This file was deleted.

66 changes: 0 additions & 66 deletions test-old/test-passport.coffee

This file was deleted.

103 changes: 103 additions & 0 deletions test/https.js
@@ -0,0 +1,103 @@
"use strict";

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

// Request module.
import request from 'request'

// HTTPS library.
import https from 'https'

// FS.
import fs from 'fs'

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

// HTTPS.
describe('https', function () {
let server = undefined;

before(function() {
// Configure authentication.
let basic = auth.basic({
realm: "Private Area."
}, function (username, password, done) {
if (username === 'gevorg') {
done(new Error("Error comes here"));
} else if (username === "mia" && password === "supergirl") {
done(true);
} else if (username === "ColonUser" && password === "apasswordwith:acolon") {
done(true);
} else {
done(false);
}
});

// HTTPS server options.
let options = {
key: fs.readFileSync(__dirname + "/../data/server.key"),
cert: fs.readFileSync(__dirname + "/../data/server.crt")
};


// Creating new HTTPS server.
server = https.createServer(basic, options, 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({uri: 'https://127.0.0.1:1337', strictSSL: false}, callback).auth('gevorg', 'gpass');
});

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

// Test request.
request.get({uri: 'https://127.0.0.1:1337', strictSSL: false}, callback).auth('mia', 'supergirl');
});

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

// Test request.
request.get({uri: 'https://127.0.0.1:1337', strictSSL: false}, callback).auth('mia', 'cute');
});

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

// Test request.
request.get({uri: 'https://127.0.0.1:1337', strictSSL: false}, callback).auth('Tina', 'supergirl');
});

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

// Test request.
request.get({uri: 'https://127.0.0.1:1337', strictSSL: false}, callback).auth(
'ColonUser', 'apasswordwith:acolon');
});
});

0 comments on commit b988de9

Please sign in to comment.