diff options
author | John Christopher Anderson <jchris@apache.org> | 2009-01-19 22:37:48 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2009-01-19 22:37:48 +0000 |
commit | 40aa5a760553eda80fbe06e9a00dee85adc01765 (patch) | |
tree | 994f1d7a2fd67f93faab42e1b3d5dfb91f8f8b09 /share/www | |
parent | aefc36cf032684d7f6d7b040b0b13654d37f2cd6 (diff) |
also test attachment paths against db names with slashes
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@735858 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www')
-rw-r--r-- | share/www/script/couch_tests.js | 216 |
1 files changed, 109 insertions, 107 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 644538a8..de4f03db 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -1014,137 +1014,139 @@ var tests = { }, 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); - - 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); + T(db.save(binAttDoc).ok); - 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."); + 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"); - // 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); + // 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("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/baz.txt"); + T(xhr.status == 404); - binAttDoc = db.open("bin_doc"); + var xhr = CouchDB.request("GET", "/"+dbName+"/bin_doc/foo%252Fbaz.txt"); + T(xhr.status == 200); + T(xhr.responseText == "We like percent two F."); - 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); + // 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); - //// 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==" + 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; + + binAttDoc = db.open("bin_doc"); + + 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); - 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"); + T(db.save(binAttDoc).ok); - // 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); + 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"); - // 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); + // 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); - // 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); + // 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); - var xhr = CouchDB.request("GET", "/test_suite_db/_design%2Fbin_doc/foo/baz.txt"); - T(xhr.status == 404); + // 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", "/test_suite_db/_design%2Fbin_doc/foo%252Fbaz.txt"); - T(xhr.status == 200); - T(xhr.responseText == "We like percent two F."); + var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Fbin_doc/foo/baz.txt"); + T(xhr.status == 404); - // 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("GET", "/"+dbName+"/_design%2Fbin_doc/foo%252Fbaz.txt"); + T(xhr.status == 200); + T(xhr.responseText == "We like percent two F."); - 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; + // 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) { |