summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Smith (air) <jhs@apache.org>2012-02-29 11:08:50 +0000
committerJason Smith (air) <jhs@apache.org>2012-02-29 11:08:50 +0000
commit16271b97d2f39dd3ea49357be078e5557e0c23ac (patch)
tree059c7cc03cbee8fb54ee76c6ea30653b3ae771d3
parentc14f130f61b0d6b611e3cce8bb7b2f11e39e99f5 (diff)
parent9f90fe45bd335d9d809ac6d3107919af71490e79 (diff)
downloadcouchdb-COUCHDB-1416.tar.gz
Pull in normal vhost vs vhost-with-path testsCOUCHDB-1416
-rw-r--r--share/www/script/test/rewrite.js108
1 files changed, 60 insertions, 48 deletions
diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js
index a30cd4f1a..99acbf399 100644
--- a/share/www/script/test/rewrite.js
+++ b/share/www/script/test/rewrite.js
@@ -437,57 +437,69 @@ couchTests.rewrite = function(debug) {
var res = CouchDB.request("GET", "/test_suite_db/_design/invalid/_rewrite/foo");
TEquals(400, res.status, "should return 400");
- // test req.requested_path with rewrites with some vhosts
- var rw_ddoc = {
- _id: "_design/rwtest",
- rewrites: [
- {"from":"testShow","to":"_show/show_requested_path"}
- ],
- shows : {
- show_requested_path : stringFun(function(doc, req){
- return '/' + req.requested_path.join('/');
- })
- }
- }
- db.save(rw_ddoc);
+ // Test req.requested_path with rewrites with some vhosts
+ run_on_modified_server([{section:'httpd', key:'secure_rewrites', value:'false'}],
+ function() {
+ var rw_ddoc = {
+ _id: "_design/rwtest",
+ rewrites: [
+ {"from":"testShow", "to":"_show/show_requested_path"},
+ {"from":"path/testShow","to":"_show/show_requested_path"},
- // try accessing directly
- var res = CouchDB.request("GET", "/test_suite_db/_design/rwtest/_rewrite/testShow");
- TEquals('/test_suite_db/_design/rwtest/_rewrite/testShow', res.responseText, "requested_path should equal requested");
+ {"from":"_config/*" , "to":"../../../_config/*"},
+ {"from":"path/_config/*", "to":"../../../_config/*"},
- // test a vhost with a path as well
- run_on_modified_server(
- [{section: "vhosts",
- key: encodeURIComponent(CouchDB.host + '/path'),
- value: "/test_suite_db/_design/rwtest/_rewrite/"}
+ {"from":"one", "to":"_rewrite/two"},
+ {"from":"two", "to":"_rewrite/three"},
+ {"from":"three", "to":"_rewrite/testShow"}
],
- function(){
- var res = CouchDB.request("GET", "/path/testShow");
- TEquals('/path/testShow', res.responseText, "requested_path should equal requested");
+ shows : {
+ show_requested_path : stringFun(function(doc, req){
+ return '/' + req.requested_path.join('/');
+ })
}
- );
+ }
- // test a vhost on the root of the host
- rw_ddoc.rewrites.push({"from":"_config/*","to":"../../../_config/*"});
- T(db.save(rw_ddoc).ok);
- run_on_modified_server(
- [{section: "httpd",
- key: "secure_rewrites",
- value: "false"}
- ],
- function(){
- // we have to 'double wrap' with a run_on_modified_server
- // so that vhosts gets remove first, then the secure_rewrite
- run_on_modified_server(
- [{section: "vhosts",
- key: encodeURIComponent(CouchDB.host),
- value: "/test_suite_db/_design/rwtest/_rewrite/"}
- ],
- function() {
- var res = CouchDB.request("GET", "/testShow");
- TEquals('/testShow', res.responseText, "requested_path should equal requested");
- }
- );
- }
- );
+ T(db.save(rw_ddoc).ok);
+
+ // try accessing directly
+ var res = CouchDB.request("GET", "/test_suite_db/_design/rwtest/_rewrite/testShow");
+ TEquals('/test_suite_db/_design/rwtest/_rewrite/testShow',
+ res.responseText, "requested_path should equal requested");
+
+ res = CouchDB.request("GET", "/test_suite_db/_design/rwtest/_rewrite/path/testShow");
+ TEquals('/test_suite_db/_design/rwtest/_rewrite/path/testShow',
+ res.responseText, "requested_path should equal requested");
+
+ // Test on a typical vhost -> _rewrite setup.
+ var vhosts = {section:'vhosts',
+ key:encodeURIComponent(CouchDB.host),
+ value:"/test_suite_db/_design/rwtest/_rewrite/"};
+
+ run_on_modified_server([vhosts], function() {
+ var res = CouchDB.request("GET", "/path/testShow");
+ TEquals('/path/testShow', res.responseText, "requested_path should equal requested");
+
+ res = CouchDB.request("GET", "/testShow");
+ TEquals('/testShow', res.responseText, "requested_path should equal requested");
+
+ // Test multiple rewrites.
+ res = CouchDB.request("GET", "/one");
+ TEquals("/one", res.responseText, "requested_path works through multiple rewrites");
+ });
+
+ // Test a vhost to a path within the rewrite namespace.
+ vhosts.value = "/test_suite_db/_design/rwtest/_rewrite/path";
+ run_on_modified_server([vhosts], function() {
+ var res = CouchDB.request("GET", "/testShow");
+ TEquals('/testShow', res.responseText, "requested_path should equal requested");
+ });
+
+ // Test the controversial vost with a path.
+ vhosts.key = encodeURIComponent(CouchDB.host + '/path');
+ run_on_modified_server([vhosts], function() {
+ var res = CouchDB.request("GET", "/path/testShow");
+ TEquals('/path/testShow', res.responseText, "requested_path should equal requested");
+ });
+ });
}