Skip to content

Commit

Permalink
Test credentials options
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jan 6, 2015
1 parent 9b1ddc9 commit 68d86d0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
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) {

This comment has been minimized.

Copy link
@nikhilm

nikhilm Jan 15, 2015

Contributor

did you mean this to be |params.name && params.value|?

This comment has been minimized.

Copy link
@josh

josh Jan 15, 2015

Author Contributor

heh, yeah

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

0 comments on commit 68d86d0

Please sign in to comment.