You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2009/01/19 23:37:48 UTC
svn commit: r735858 - /couchdb/trunk/share/www/script/couch_tests.js
Author: jchris
Date: Mon Jan 19 14:37:48 2009
New Revision: 735858
URL: http://svn.apache.org/viewvc?rev=735858&view=rev
Log:
also test attachment paths against db names with slashes
Modified:
couchdb/trunk/share/www/script/couch_tests.js
Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=735858&r1=735857&r2=735858&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Mon Jan 19 14:37:48 2009
@@ -1014,137 +1014,139 @@
},
attachment_paths : function(debug) {
- var db = new CouchDB("test_suite_db");
- db.deleteDb();
- db.createDb();
if (debug) debugger;
+ var dbNames = ["test_suite_db", "test_suite_db/with_slashes"];
+ for (var i=0; i < dbNames.length; i++) {
+ var db = new CouchDB(dbNames[i]);
+ var dbName = encodeURIComponent(dbNames[i]);
+ db.deleteDb();
+ db.createDb();
-
- // first just save a regular doc with an attachment that has a slash in the url.
- // (also gonna run an encoding check case)
- var binAttDoc = {
- _id: "bin_doc",
- _attachments:{
- "foo/bar.txt": {
- content_type:"text/plain",
- data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
- },
- "foo%2Fbaz.txt": {
- content_type:"text/plain",
- data: "V2UgbGlrZSBwZXJjZW50IHR3byBGLg=="
+ // first just save a regular doc with an attachment that has a slash in the url.
+ // (also gonna run an encoding check case)
+ var binAttDoc = {
+ _id: "bin_doc",
+ _attachments:{
+ "foo/bar.txt": {
+ content_type:"text/plain",
+ data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+ },
+ "foo%2Fbaz.txt": {
+ content_type:"text/plain",
+ data: "V2UgbGlrZSBwZXJjZW50IHR3byBGLg=="
+ }
}
}
- }
- T(db.save(binAttDoc).ok);
+ T(db.save(binAttDoc).ok);
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo/bar.txt");
- T(xhr.responseText == "This is a base64 encoded text");
- T(xhr.getResponseHeader("Content-Type") == "text/plain");
-
- // lets try it with an escaped attachment id...
- // weird that it's at two urls
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo%2Fbar.txt");
- T(xhr.status == 200);
- // xhr.responseText == "This is a base64 encoded text"
-
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo/baz.txt");
- T(xhr.status == 404);
-
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo%252Fbaz.txt");
- T(xhr.status == 200);
- T(xhr.responseText == "We like percent two F.");
-
- // require a _rev to PUT
- var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc/foo/attachment.txt", {
- headers:{"Content-Type":"text/plain;charset=utf-8"},
- body:"Just some text"
- });
- T(xhr.status == 412);
-
- var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc/foo/bar2.txt?rev=" + binAttDoc._rev, {
- body:"This is no base64 encoded text",
- headers:{"Content-Type": "text/plain;charset=utf-8"}
- });
- T(xhr.status == 201);
- var rev = JSON.parse(xhr.responseText).rev;
+ var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo/bar.txt");
+ T(xhr.responseText == "This is a base64 encoded text");
+ T(xhr.getResponseHeader("Content-Type") == "text/plain");
+
+ // lets try it with an escaped attachment id...
+ // weird that it's at two urls
+ var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo%2Fbar.txt");
+ T(xhr.status == 200);
+ // xhr.responseText == "This is a base64 encoded text"
+
+ var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo/baz.txt");
+ T(xhr.status == 404);
+
+ var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo%252Fbaz.txt");
+ T(xhr.status == 200);
+ T(xhr.responseText == "We like percent two F.");
+
+ // require a _rev to PUT
+ var xhr = CouchDB.request("PUT", "/"+dbName+"/bin_doc/foo/attachment.txt", {
+ headers:{"Content-Type":"text/plain;charset=utf-8"},
+ body:"Just some text"
+ });
+ T(xhr.status == 412);
- binAttDoc = db.open("bin_doc");
+ var xhr = CouchDB.request("PUT", "/"+dbName+"/bin_doc/foo/bar2.txt?rev=" + binAttDoc._rev, {
+ body:"This is no base64 encoded text",
+ headers:{"Content-Type": "text/plain;charset=utf-8"}
+ });
+ T(xhr.status == 201);
+ var rev = JSON.parse(xhr.responseText).rev;
- T(binAttDoc._attachments["foo/bar.txt"] !== undefined);
- T(binAttDoc._attachments["foo%2Fbaz.txt"] !== undefined);
- T(binAttDoc._attachments["foo/bar2.txt"] !== undefined);
- T(binAttDoc._attachments["foo/bar2.txt"].content_type == "text/plain;charset=utf-8");
- T(binAttDoc._attachments["foo/bar2.txt"].length == 30);
+ binAttDoc = db.open("bin_doc");
- //// now repeat the while thing with a design doc
-
- // first just save a regular doc with an attachment that has a slash in the url.
- // (also gonna run an encoding check case)
- var binAttDoc = {
- _id: "_design/bin_doc",
- _attachments:{
- "foo/bar.txt": {
- content_type:"text/plain",
- data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
- },
- "foo%2Fbaz.txt": {
- content_type:"text/plain",
- data: "V2UgbGlrZSBwZXJjZW50IHR3byBGLg=="
+ T(binAttDoc._attachments["foo/bar.txt"] !== undefined);
+ T(binAttDoc._attachments["foo%2Fbaz.txt"] !== undefined);
+ T(binAttDoc._attachments["foo/bar2.txt"] !== undefined);
+ T(binAttDoc._attachments["foo/bar2.txt"].content_type == "text/plain;charset=utf-8");
+ T(binAttDoc._attachments["foo/bar2.txt"].length == 30);
+
+ //// now repeat the while thing with a design doc
+
+ // first just save a regular doc with an attachment that has a slash in the url.
+ // (also gonna run an encoding check case)
+ var binAttDoc = {
+ _id: "_design/bin_doc",
+ _attachments:{
+ "foo/bar.txt": {
+ content_type:"text/plain",
+ data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ="
+ },
+ "foo%2Fbaz.txt": {
+ content_type:"text/plain",
+ data: "V2UgbGlrZSBwZXJjZW50IHR3byBGLg=="
+ }
}
}
- }
- T(db.save(binAttDoc).ok);
+ T(db.save(binAttDoc).ok);
- var xhr = CouchDB.request("GET", "/test_suite_db/_design%2Fbin_doc/foo/bar.txt");
- T(xhr.responseText == "This is a base64 encoded text");
- T(xhr.getResponseHeader("Content-Type") == "text/plain");
-
- // lets try it with an escaped attachment id...
- // weird that it's at two urls
- var xhr = CouchDB.request("GET", "/test_suite_db/_design%2Fbin_doc/foo%2Fbar.txt");
- T(xhr.responseText == "This is a base64 encoded text");
- T(xhr.status == 200);
-
- // err, 3 urls
- var xhr = CouchDB.request("GET", "/test_suite_db/_design/bin_doc/foo%2Fbar.txt");
- T(xhr.responseText == "This is a base64 encoded text");
- T(xhr.status == 200);
-
- // I mean um, 4 urls
- var xhr = CouchDB.request("GET", "/test_suite_db/_design/bin_doc/foo/bar.txt");
- T(xhr.responseText == "This is a base64 encoded text");
- T(xhr.status == 200);
-
- var xhr = CouchDB.request("GET", "/test_suite_db/_design%2Fbin_doc/foo/baz.txt");
- T(xhr.status == 404);
-
- var xhr = CouchDB.request("GET", "/test_suite_db/_design%2Fbin_doc/foo%252Fbaz.txt");
- T(xhr.status == 200);
- T(xhr.responseText == "We like percent two F.");
-
- // require a _rev to PUT
- var xhr = CouchDB.request("PUT", "/test_suite_db/_design%2Fbin_doc/foo/attachment.txt", {
- headers:{"Content-Type":"text/plain;charset=utf-8"},
- body:"Just some text"
- });
- T(xhr.status == 412);
-
- var xhr = CouchDB.request("PUT", "/test_suite_db/_design%2Fbin_doc/foo/bar2.txt?rev=" + binAttDoc._rev, {
- body:"This is no base64 encoded text",
- headers:{"Content-Type": "text/plain;charset=utf-8"}
- });
- T(xhr.status == 201);
- var rev = JSON.parse(xhr.responseText).rev;
+ var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Fbin_doc/foo/bar.txt");
+ T(xhr.responseText == "This is a base64 encoded text");
+ T(xhr.getResponseHeader("Content-Type") == "text/plain");
+
+ // lets try it with an escaped attachment id...
+ // weird that it's at two urls
+ var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Fbin_doc/foo%2Fbar.txt");
+ T(xhr.responseText == "This is a base64 encoded text");
+ T(xhr.status == 200);
+
+ // err, 3 urls
+ var xhr = CouchDB.request("GET", "/"+dbName+"/_design/bin_doc/foo%2Fbar.txt");
+ T(xhr.responseText == "This is a base64 encoded text");
+ T(xhr.status == 200);
+
+ // I mean um, 4 urls
+ var xhr = CouchDB.request("GET", "/"+dbName+"/_design/bin_doc/foo/bar.txt");
+ T(xhr.responseText == "This is a base64 encoded text");
+ T(xhr.status == 200);
+
+ var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Fbin_doc/foo/baz.txt");
+ T(xhr.status == 404);
+
+ var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Fbin_doc/foo%252Fbaz.txt");
+ T(xhr.status == 200);
+ T(xhr.responseText == "We like percent two F.");
+
+ // require a _rev to PUT
+ var xhr = CouchDB.request("PUT", "/"+dbName+"/_design%2Fbin_doc/foo/attachment.txt", {
+ headers:{"Content-Type":"text/plain;charset=utf-8"},
+ body:"Just some text"
+ });
+ T(xhr.status == 412);
- binAttDoc = db.open("_design/bin_doc");
+ var xhr = CouchDB.request("PUT", "/"+dbName+"/_design%2Fbin_doc/foo/bar2.txt?rev=" + binAttDoc._rev, {
+ body:"This is no base64 encoded text",
+ headers:{"Content-Type": "text/plain;charset=utf-8"}
+ });
+ T(xhr.status == 201);
+ var rev = JSON.parse(xhr.responseText).rev;
- T(binAttDoc._attachments["foo/bar.txt"] !== undefined);
- T(binAttDoc._attachments["foo/bar2.txt"] !== undefined);
- T(binAttDoc._attachments["foo/bar2.txt"].content_type == "text/plain;charset=utf-8");
- T(binAttDoc._attachments["foo/bar2.txt"].length == 30);
+ binAttDoc = db.open("_design/bin_doc");
+ T(binAttDoc._attachments["foo/bar.txt"] !== undefined);
+ T(binAttDoc._attachments["foo/bar2.txt"] !== undefined);
+ T(binAttDoc._attachments["foo/bar2.txt"].content_type == "text/plain;charset=utf-8");
+ T(binAttDoc._attachments["foo/bar2.txt"].length == 30);
+ }
},
attachment_views: function(debug) {