spec: add test for basic authentication
This commit is contained in:
parent
06834b723b
commit
2d190b9952
3 changed files with 42 additions and 0 deletions
|
@ -4,6 +4,7 @@ path = require 'path'
|
||||||
remote = require 'remote'
|
remote = require 'remote'
|
||||||
http = require 'http'
|
http = require 'http'
|
||||||
url = require 'url'
|
url = require 'url'
|
||||||
|
auth = require 'basic-auth'
|
||||||
|
|
||||||
BrowserWindow = remote.require 'browser-window'
|
BrowserWindow = remote.require 'browser-window'
|
||||||
|
|
||||||
|
@ -245,3 +246,26 @@ describe 'browser-window module', ->
|
||||||
w.webContents.on 'did-finish-load', ->
|
w.webContents.on 'did-finish-load', ->
|
||||||
w.close()
|
w.close()
|
||||||
w.loadUrl "file://#{fixtures}/pages/f.html"
|
w.loadUrl "file://#{fixtures}/pages/f.html"
|
||||||
|
|
||||||
|
describe 'basic auth', ->
|
||||||
|
it 'should authenticate with correct credentials', (done) ->
|
||||||
|
ipc = remote.require 'ipc'
|
||||||
|
server = http.createServer (req, res) ->
|
||||||
|
action = url.parse(req.url, true).pathname
|
||||||
|
if action == '/'
|
||||||
|
credentials = auth(req)
|
||||||
|
if credentials.name == 'test' and credentials.pass == 'test'
|
||||||
|
res.end('Authenticated')
|
||||||
|
server.close()
|
||||||
|
else if action == '/jquery.js'
|
||||||
|
js = fs.readFileSync(path.join(__dirname, 'static', 'jquery-2.0.3.min.js'))
|
||||||
|
res.writeHead(200, {'Content-Type': 'text/javascript'})
|
||||||
|
res.end(js, 'utf-8')
|
||||||
|
server.listen 62342, '127.0.0.1'
|
||||||
|
ipc.on 'console-message', (e, message) ->
|
||||||
|
ipc.removeAllListeners 'console-message'
|
||||||
|
assert.equal message, 'Authenticated'
|
||||||
|
done()
|
||||||
|
w.webContents.on 'did-finish-load', ->
|
||||||
|
w.close()
|
||||||
|
w.loadUrl "file://#{fixtures}/pages/basic-auth.html"
|
||||||
|
|
17
spec/fixtures/pages/basic-auth.html
vendored
Normal file
17
spec/fixtures/pages/basic-auth.html
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script src='http://127.0.0.1:62342/jquery.js'></script>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "http://127.0.0.1:62342",
|
||||||
|
headers: {
|
||||||
|
"Authorization": "Basic " + btoa("test:test")
|
||||||
|
},
|
||||||
|
success: function (result){
|
||||||
|
require('ipc').send('console-message', result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -4,6 +4,7 @@
|
||||||
"main": "static/main.js",
|
"main": "static/main.js",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"basic-auth": "^1.0.0",
|
||||||
"formidable": "1.0.16",
|
"formidable": "1.0.16",
|
||||||
"graceful-fs": "3.0.5",
|
"graceful-fs": "3.0.5",
|
||||||
"mocha": "2.1.0",
|
"mocha": "2.1.0",
|
||||||
|
|
Loading…
Reference in a new issue