This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cookies] cookie monster lands in master
- Loading branch information
Showing
7 changed files
with
152 additions
and
8 deletions.
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
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
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
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,4 @@ | ||
{ "timeout" : 20000 | ||
, "couch" : "http://localhost:5984" | ||
, "admin" : "http://admin:password@localhost:5984" | ||
} |
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,33 @@ | ||
[ | ||
{ "method" : "put" | ||
, "path" : "/shared_cookie" | ||
, "status" : 201 | ||
, "response" : "{ \"ok\": true }" | ||
} | ||
, { "path" : "/_config/admins/admin" | ||
, "method" : "put" | ||
, "body" : "*" | ||
, "response" : "{\"ok\": true}" | ||
} | ||
, { "method" : "post" | ||
, "path" : "/_session" | ||
, "body" : "name=admin&password=password" | ||
, "headers" : {"set-cookie" : ["AuthSession=YWRtaW46NEZCMzFERDk6BJyusEcy3SgfI9xD4Mptl0N0gh0;Version=1;Path=/;HttpOnly"]} | ||
, "status" : 201 | ||
, "response" : "{ \"ok\": true,\"name\": null,\"roles\": [ \"_admin\" ] }" | ||
} | ||
, { "method" : "post" | ||
, "status" : 201 | ||
, "path" : "/shared_cookie" | ||
, "body" : "{\"foo\":\"baz\"}" | ||
, "response" : "{\"ok\":true,\"id\":\"234\",\"rev\":\"1-333231\"}" | ||
} | ||
, { "path" : "/_config/admins/admin" | ||
, "method" : "delete" | ||
, "response" : "{\"ok\": true}" | ||
} | ||
, { "method" : "delete" | ||
, "path" : "/shared_cookie" | ||
, "response" : "{ \"ok\": 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
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,67 @@ | ||
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") | ||
, admin = Nano(helpers.admin) | ||
, cookie | ||
, cookie_nano | ||
; | ||
|
||
specify("shared_cookie:setup", timeout, function (assert) { | ||
// creates a db in admin party mode | ||
nano.db.create("shared_cookie", function (err, response) { | ||
assert.equal(err, undefined, "Failed to create database"); | ||
// creates a admin user, leaves admin party mode | ||
nano.relax( | ||
{ method : "PUT" | ||
, path : "_config/admins/" + helpers.username | ||
, body : helpers.password | ||
}, function (err, response, headers) { | ||
assert.equal(err, undefined, "Failed to create admin user"); | ||
// authenticate | ||
nano.relax( | ||
{ method : "POST" | ||
, db : "_session" | ||
, form : { "name" : "admin", "password" : "password" } | ||
, content_type : "application/x-www-form-urlencoded; charset=utf-8" | ||
}, function (err, response, headers) { | ||
assert.equal(err, undefined, "Should have logged in successfully"); | ||
assert.ok(headers['set-cookie'], | ||
"Response should have a set-cookie header"); | ||
cookie = headers['set-cookie']; | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
specify("shared_cookie:test", timeout, function (assert) { | ||
var server = Nano({ url : helpers.couch, cookie: cookie }); | ||
var db = server.use("shared_cookie"); | ||
// insert with a shared cookie | ||
db.insert({"foo": "baz"}, null, function (error, response) { | ||
assert.equal(error, undefined, "Should have stored value"); | ||
assert.equal(response.ok, true, "Response should be ok"); | ||
assert.ok(response.rev, "Response should have rev"); | ||
}); | ||
}); | ||
|
||
specify("shared_cookie:teardown", timeout, function (assert) { | ||
// back to admin party mode | ||
admin.relax( | ||
{ method : "DELETE" | ||
, path : "_config/admins/" + helpers.username | ||
}, function (err, response, headers) { | ||
// delete the database that we created | ||
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)); |