提交 68d86d05 编写于 作者: J Joshua Peek

Test credentials options

上级 9b1ddc9e
......@@ -5,6 +5,7 @@ var port = Number(process.argv[2] || 3000)
var fs = require('fs')
var http = require('http');
var url = require('url');
var querystring = require('querystring');
var routes = {
'/request': function(res, req) {
......@@ -47,6 +48,17 @@ var routes = {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end('not json {');
},
'/cookie': function(res, req) {
var params = querystring.parse(url.parse(req.url).query);
if (params.value && params.value) {
var setCookie = [params.name, params.value].join('=');
}
if (params.name) {
var cookie = querystring.parse(req.headers['cookie'], '; ')[params.name];
}
res.writeHead(200, {'Content-Type': 'text/plain', 'Set-Cookie': setCookie});
res.end(cookie);
},
'/headers': function(res) {
res.writeHead(200, {
'Date': 'Mon, 13 Oct 2014 21:02:27 GMT',
......
......@@ -196,3 +196,43 @@ promiseTest('supports HTTP DELETE', 2, function() {
equal(request.data, '')
})
})
promiseTest('doesnt send cookies with implicit omit credentials', 1, function() {
return fetch('/cookie?name=foo&value=bar').then(function(response) {
return fetch('/cookie?name=foo');
}).then(function(response) {
return response.text()
}).then(function(data) {
equal(data, '')
})
})
promiseTest('doesnt send cookies with omit credentials', 1, function() {
return fetch('/cookie?name=foo&value=bar').then(function(response) {
return fetch('/cookie?name=foo', {credentials: 'omit'})
}).then(function(response) {
return response.text()
}).then(function(data) {
equal(data, '')
})
})
promiseTest('send cookies with same-origin credentials', 1, function() {
return fetch('/cookie?name=foo&value=bar').then(function(response) {
return fetch('/cookie?name=foo', {credentials: 'same-origin'})
}).then(function(response) {
return response.text()
}).then(function(data) {
equal(data, 'bar')
})
})
promiseTest('send cookies with include credentials', 1, function() {
return fetch('/cookie?name=foo&value=bar').then(function(response) {
return fetch('/cookie?name=foo', {credentials: 'include'})
}).then(function(response) {
return response.text()
}).then(function(data) {
equal(data, 'bar')
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册