spec: Make the basic-auth spec stronger
This commit is contained in:
parent
9ec60cd585
commit
1a93b1db52
3 changed files with 31 additions and 29 deletions
|
@ -4,7 +4,6 @@ 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'
|
||||||
|
|
||||||
|
@ -280,26 +279,3 @@ 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"
|
|
||||||
|
|
15
spec/fixtures/pages/basic-auth.html
vendored
15
spec/fixtures/pages/basic-auth.html
vendored
|
@ -1,16 +1,21 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script src='http://127.0.0.1:62342/jquery.js'></script>
|
<script src="../../static/jquery-2.0.3.min.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
var ipc = require('ipc');
|
||||||
|
var port = location.search.substr("?port=".length);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: "http://127.0.0.1:62342",
|
url: "http://127.0.0.1:" + port,
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": "Basic " + btoa("test:test")
|
"Authorization": "Basic " + btoa("test:test")
|
||||||
},
|
},
|
||||||
success: function (result){
|
success: function(result) {
|
||||||
require('ipc').send('console-message', result);
|
ipc.sendToHost(result);
|
||||||
}
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
ipc.sendToHost(error);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -228,3 +228,24 @@ describe '<webview> tag', ->
|
||||||
webview.setAttribute 'nodeintegration', 'on'
|
webview.setAttribute 'nodeintegration', 'on'
|
||||||
webview.src = "file://#{fixtures}/pages/history.html"
|
webview.src = "file://#{fixtures}/pages/history.html"
|
||||||
document.body.appendChild webview
|
document.body.appendChild webview
|
||||||
|
|
||||||
|
describe 'basic auth', ->
|
||||||
|
auth = require 'basic-auth'
|
||||||
|
|
||||||
|
it 'should authenticate with correct credentials', (done) ->
|
||||||
|
message = 'Authenticated'
|
||||||
|
server = require('http').createServer (req, res) ->
|
||||||
|
credentials = auth(req)
|
||||||
|
if credentials.name == 'test' and credentials.pass == 'test'
|
||||||
|
res.end(message)
|
||||||
|
else
|
||||||
|
res.end('failed')
|
||||||
|
server.close()
|
||||||
|
server.listen 0, '127.0.0.1', ->
|
||||||
|
{port} = server.address()
|
||||||
|
webview.addEventListener 'ipc-message', (e) ->
|
||||||
|
assert.equal e.channel, message
|
||||||
|
done()
|
||||||
|
webview.src = "file://#{fixtures}/pages/basic-auth.html?port=#{port}"
|
||||||
|
webview.setAttribute 'nodeintegration', 'on'
|
||||||
|
document.body.appendChild webview
|
||||||
|
|
Loading…
Reference in a new issue