Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added test for cookie authentication

  • Loading branch information...
commit ac6113fb20237b516eaee75be88191c132266902 1 parent d99aa58
Jonathan Mahoney authored
Showing with 53 additions and 0 deletions.
  1. +17 −0 tests/fixtures/shared/cookie.json
  2. +36 −0 tests/shared/cookie.js
View
17 tests/fixtures/shared/cookie.json
@@ -0,0 +1,17 @@
+[
+ { "method" : "put"
+ , "path" : "/shared_cookie"
+ , "status" : 201
+ , "response" : "{ \"ok\": true }"
+ }
+, { "method" : "post"
+ , "status" : 201
+ , "path" : "/shared_cookie"
+ , "body" : "{\"foo\":\"bar\"}"
+ , "response" : "{\"ok\":true,\"id\":\"234\",\"rev\":\"1-333231\",\"request\":{\"headers\":{\"X-CouchDB-WWW-Authenticate\":\"Cookie\",\"cookie\":\"abc123\"}}}"
+ }
+, { "method" : "delete"
+ , "path" : "/shared_cookie"
+ , "response" : "{ \"ok\": true }"
+ }
+]
View
36 tests/shared/cookie.js
@@ -0,0 +1,36 @@
+var specify = require("specify")
+ , helpers = require("../helpers")
+ , timeout = helpers.timeout
+ , Nano = helpers.Nano
+ , nano = helpers.nano
+ , nock = helpers.nock
+ ;
+
+var mock = nock(helpers.couch, "shared/cookie")
+ ;
+
+specify("cookie:setup", timeout, function (assert) {
+ console.log()
+ nano.db.create("shared_cookie", function (err) {
+ assert.equal(err, undefined, "Failed to create database");
+ });
+});
+
+specify("cookie:test", timeout, function (assert) {
+ db = Nano({ url : "http://localhost:5984", cookie: "abc123" }).use("shared_cookie");
+ db.insert({"foo": "bar"}, null, function (error, response) {
+ assert.equal(response.request.headers['X-CouchDB-WWW-Authenticate'], "Cookie",
+ "Request header 'X-CouchDB-WWW-Authenticate' was missing");
+ assert.equal(response.request.headers['cookie'], "abc123",
+ "Cookie not sent in request headers");
+ });
+});
+
+specify("cookie:teardown", timeout, function (assert) {
+ nano.db.destroy("shared_cookie", function (err) {
+ assert.equal(err, undefined, "Failed to destroy database");
+ assert.ok(mock.isDone(), "Some mocks didn't run");
+ });
+});
+
+specify.run(process.argv.slice(2));
Please sign in to comment.
Something went wrong with that request. Please try again.