-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters