Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pull in normal vhost vs vhost-with-path tests

  • Loading branch information...
commit 16271b97d2f39dd3ea49357be078e5557e0c23ac 2 parents c14f130 + 9f90fe4
Jason Smith (air) authored
Showing with 60 additions and 48 deletions.
  1. +60 −48 share/www/script/test/rewrite.js
View
108 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");
+ });
+ });
}
Please sign in to comment.
Something went wrong with that request. Please try again.