Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support credentials #56

Merged
merged 4 commits into from
Jan 11, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down
40 changes: 40 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,43 @@ promiseTest('supports HTTP DELETE', 2, function() {
equal(request.data, '')
})
})

promiseTest('doesnt send cookies with implicit omit credentials', 1, function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"does not"

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')
})
})