Skip to content

Commit

Permalink
Better document cookie addition
Browse files Browse the repository at this point in the history
Update README file and tests file to better document the cookie addition process, that is the pure cookie appending
  • Loading branch information
amine committed Mar 27, 2017
1 parent f7c331b commit 39b2be4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
22 changes: 11 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#CookieJar
# CookieJar

Simple robust cookie library

##Exports
## Exports

###CookieAccessInfo(domain,path,secure,script)
### CookieAccessInfo(domain,path,secure,script)

class to determine matching qualities of a cookie

#####Properties
##### Properties

* String domain - domain to match
* String path - path to match
* Boolean secure - access is secure (ssl generally)
* Boolean script - access is from a script


###Cookie(cookiestr_or_cookie, request_domain, request_path)
### Cookie(cookiestr_or_cookie, request_domain, request_path)

turns input into a Cookie (singleton if given a Cookie)
the `request_domain` argument is used to default the domain if it is not explicit in the cookie string
the `request_path` argument is used to set the path if it is not explicit in a cookie String.

explicit domains/paths will cascade, implied domains/paths must *exactly* match (see http://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Pat)

#####Properties
##### Properties

* String name - name of the cookie
* String value - string associated with the cookie
Expand All @@ -36,7 +36,7 @@ Simple robust cookie library
* Boolean secure - should it only be transmitted over secure means
* Number expiration_date - number of millis since 1970 at which this should be removed

#####Methods
##### Methods

* String toString() - the __set-cookie:__ string for this cookie
* String toValueString() - the __cookie:__ string for this cookie
Expand All @@ -45,13 +45,13 @@ Simple robust cookie library
* Boolean collidesWith(cookie) - returns true if the cookies cannot exist in the same space (domain and path match)


###CookieJar()
### CookieJar()

class to hold numerous cookies from multiple domains correctly

#####Methods
##### Methods

* Cookie setCookie(cookie, request_domain, request_path) - add a cookie to the jar
* Cookie[] setCookies(cookiestr_or_list, request_domain, request_path) - add a large number of cookies to the jar
* Cookie setCookie(cookie, request_domain, request_path) - modify (or add if not already-existing) a cookie to the jar
* Cookie[] setCookies(cookiestr_or_list, request_domain, request_path) - modify (or add if not already-existing) a large number of cookies to the jar
* Cookie getCookie(cookie_name,access_info) - get a cookie with the name and access_info matching
* Cookie[] getCookies(access_info) - grab all cookies matching this access_info
46 changes: 26 additions & 20 deletions tests/test.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,21 @@ assert.equal(String(test_jar.getCookies(CookieAccessInfo("test.com","/"))), "a=1
cookie=Cookie("a=1;domain=test.com;path=/;HttpOnly");
assert.ok(cookie.noscript, "HttpOnly flag parsing failed\n" + cookie.toString());

var test_jar = CookieJar();
test_jar.setCookies([
"a=1;domain=.test.com;path=/"
, "a=1;domain=.test.com;path=/"
, "a=2;domain=.test.com;path=/"
, "b=3;domain=.test.com;path=/"]);
var cookies=test_jar.getCookies(CookieAccessInfo("test.com","/"))
assert.equal(cookies.length, 2);
assert.equal(cookies[0].value, 2);
var test_jar2 = CookieJar();
test_jar2.setCookies([
"a=1;domain=.test.com;path=/"
, "a=1;domain=.test.com;path=/"
, "a=2;domain=.test.com;path=/"
, "b=3;domain=.test.com;path=/"]);
var cookies2=test_jar2.getCookies(CookieAccessInfo("test.com","/"))
assert.equal(cookies2.length, 2);
assert.equal(cookies2[0].value, 2);

// Test pure appending
test_jar2.setCookie("d=4;domain=.test.com;path=/");
cookies2=test_jar2.getCookies(CookieAccessInfo("test.com","/"))
assert.equal(cookies2.length, 3);
assert.equal(cookies2[2].value, 4);

// Test Ignore Trailing Semicolons (Github Issue #6)
var cookie = new Cookie("a=1;domain=.test.com;path=/;;;;");
Expand All @@ -62,26 +68,26 @@ assert.equal(cookie.path, "/");
assert.deepEqual(cookie, new Cookie("a=1;domain=.test.com;path=/"));

// Test request_path and request_domain
test_jar.setCookie(new Cookie("sub=4;path=/", "test.com"));
var cookie = test_jar.getCookie("sub", CookieAccessInfo("sub.test.com", "/"));
test_jar2.setCookie(new Cookie("sub=4;path=/", "test.com"));
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("sub.test.com", "/"));
assert.equal(cookie, undefined);

var cookie = test_jar.getCookie("sub", CookieAccessInfo("test.com", "/"));
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("test.com", "/"));
assert.equal(cookie.name, "sub");
assert.equal(cookie.domain, "test.com");

test_jar.setCookie(new Cookie("sub=4;path=/accounts", "test.com", "/accounts"));
var cookie = test_jar.getCookie("sub", CookieAccessInfo("test.com", "/foo"));
test_jar2.setCookie(new Cookie("sub=4;path=/accounts", "test.com", "/accounts"));
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("test.com", "/foo"));
assert.equal(cookie, undefined);

var cookie = test_jar.getCookie("sub", CookieAccessInfo("test.com", "/accounts"));
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("test.com", "/accounts"));
assert.equal(cookie.path, "/accounts");

test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
var cookies = test_jar.getCookies(CookieAccessInfo("test.com"));
assert.equal(cookies.length, 3);
test_jar2.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
var cookies = test_jar2.getCookies(CookieAccessInfo("test.com"));
assert.equal(cookies.length, 4);

test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
var cookie = test_jar.getCookie('sub', CookieAccessInfo.All);
test_jar2.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
var cookie = test_jar2.getCookie('sub', CookieAccessInfo.All);
assert(cookie);
assert.equal(cookie.name, 'sub');

0 comments on commit 39b2be4

Please sign in to comment.