-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#6814) - Add support to store cookies on Node.js
* (#6814) - Add support to store cookies on Node.js On Node.js, PouchDB does not hold a cookie jar for cookies received from server during authentication. It uses the request Node.js module to make HTTP requests but it does not configure it correctly to hold a cookie jar. This adds the minimal required configuration for the request module. * (#6814) - Add a test for support for cookies on Node.js * (#6814) - Fix and move test for support for cookies on Node.js
- Loading branch information
1 parent
200cc2f
commit 17db84f
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// May seem redundant, but this is to allow switching with | ||
// request-browser.js. | ||
export default require('request'); | ||
export default require('request').defaults({ | ||
jar: true | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var http = require('http'); | ||
var PouchDB = require('../../packages/node_modules/pouchdb-for-coverage'); | ||
var should = require("chai").should(); | ||
|
||
describe('test.ajax.js', function () { | ||
|
||
it('#6815 ajax uses cookies', function (done) { | ||
var server = http.createServer(function (req, res) { | ||
if (req.url === '/install-cookie') { | ||
res.writeHead(200, {'Set-Cookie': 'Test=test; Version=1; Path=/; HttpOnly'}); | ||
res.end(JSON.stringify({ok: true})); | ||
} else if (req.url === '/check-cookie') { | ||
res.end(JSON.stringify({ok: req.headers.cookie === 'Test=test'})); | ||
} | ||
}); | ||
server.listen(6000, function () { | ||
PouchDB.ajax({ | ||
method: 'GET', | ||
url: 'http://127.0.0.1:6000/install-cookie', | ||
timeout: 10 | ||
}, function (err, res) { | ||
should.equal(res.ok, true, "Server not responding"); | ||
|
||
PouchDB.ajax({ | ||
method: 'GET', | ||
url: 'http://127.0.0.1:6000/check-cookie', | ||
timeout: 10 | ||
}, function (err, res) { | ||
server.close(); | ||
|
||
should.equal(res.ok, true, "Cookie not set"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |