You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jh...@apache.org on 2012/02/29 12:09:59 UTC
[9/9] git commit: Testing requested_path for various combinations of
rewrites and vhost
Testing requested_path for various combinations of rewrites and vhost
Three test that show the requested_path in various conditions:
1. Accessing a show with no vhost
2. Access the show with a vhost that contains a path
3. Access the show with a vhost with no path
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/1451ee57
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/1451ee57
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/1451ee57
Branch: refs/heads/COUCHDB-1416
Commit: 1451ee57f2afdade5b24c3fb4ae37efadf9ef1ed
Parents: 766d461
Author: Ryan Ramage <ry...@gmail.com>
Authored: Wed Feb 22 10:38:21 2012 -0700
Committer: Jason Smith (air) <jh...@apache.org>
Committed: Wed Feb 29 03:34:51 2012 +0000
----------------------------------------------------------------------
share/www/script/test/rewrite.js | 56 +++++++++++++++++++++++++++++++++
1 files changed, 56 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/1451ee57/share/www/script/test/rewrite.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js
index 8454292..5b8c74f 100644
--- a/share/www/script/test/rewrite.js
+++ b/share/www/script/test/rewrite.js
@@ -437,4 +437,60 @@ 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);
+
+ // 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");
+
+ var host = 'localhost:5984';
+ if (window) host = window.location.host;
+
+ // test a vhost with a path as well
+ run_on_modified_server(
+ [{section: "vhosts",
+ key: encodeURIComponent(host + '/path'),
+ value: "/test_suite_db/_design/rwtest/_rewrite/"}
+ ],
+ function(){
+ var res = CouchDB.request("GET", "/path/testShow");
+ TEquals('/path/testShow', res.responseText, "requested_path should equal requested");
+ }
+ );
+
+ // 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(host),
+ value: "/test_suite_db/_design/rwtest/_rewrite/"}
+ ],
+ function() {
+ var res = CouchDB.request("GET", "/testShow");
+ TEquals('/testShow', res.responseText, "requested_path should equal requested");
+ }
+ );
+ }
+ );
}
Re: [9/9] git commit: Testing requested_path for various combinations
of rewrites and vhost
Posted by Jason Smith <jh...@apache.org>.
On Thu, Mar 1, 2012 at 3:17 AM, Randall Leeds <ra...@gmail.com> wrote:
> I made a change to requested_path recently on master and 1.2 but
> didn't get much feedback about it.
> It seemed like it was obviously broken to me but maybe I misunderstood
> the intention.
> Is it working the way you expect?
>
> Relevant commit: 879a1bc19b145e126b9386aed2023f9cd1df8b31
The JIRA ticket indicates a bug when "hostname/path" was used as a
vhost. Ryan showed that the "/path" part is forgotten by the time
req.requested_path arrives in a _show function.
Jan said it's not a bug because paths in vhost keys are invalid. Or at
least, they *oughtn't* be valid. I thought the bug occurred even with
normal vhosts (no path) but several unit tests later, I realized that
is false. The only bug is when vhosts include a path component.
And so the *real* bug will probably be that CouchDB should reject non
well-formed vhost keys. The only remaining question is whether Ryan
used that feature because there was no possible alternative.
Re: [9/9] git commit: Testing requested_path for various combinations
of rewrites and vhost
Posted by Randall Leeds <ra...@gmail.com>.
I made a change to requested_path recently on master and 1.2 but
didn't get much feedback about it.
It seemed like it was obviously broken to me but maybe I misunderstood
the intention.
Is it working the way you expect?
Relevant commit: 879a1bc19b145e126b9386aed2023f9cd1df8b31
On Wed, Feb 29, 2012 at 03:09, <jh...@apache.org> wrote:
> Testing requested_path for various combinations of rewrites and vhost
>
> Three test that show the requested_path in various conditions:
>
> 1. Accessing a show with no vhost
> 2. Access the show with a vhost that contains a path
> 3. Access the show with a vhost with no path
>
>
> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/1451ee57
> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/1451ee57
> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/1451ee57
>
> Branch: refs/heads/COUCHDB-1416
> Commit: 1451ee57f2afdade5b24c3fb4ae37efadf9ef1ed
> Parents: 766d461
> Author: Ryan Ramage <ry...@gmail.com>
> Authored: Wed Feb 22 10:38:21 2012 -0700
> Committer: Jason Smith (air) <jh...@apache.org>
> Committed: Wed Feb 29 03:34:51 2012 +0000
>
> ----------------------------------------------------------------------
> share/www/script/test/rewrite.js | 56 +++++++++++++++++++++++++++++++++
> 1 files changed, 56 insertions(+), 0 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1451ee57/share/www/script/test/rewrite.js
> ----------------------------------------------------------------------
> diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js
> index 8454292..5b8c74f 100644
> --- a/share/www/script/test/rewrite.js
> +++ b/share/www/script/test/rewrite.js
> @@ -437,4 +437,60 @@ 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);
> +
> + // 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");
> +
> + var host = 'localhost:5984';
> + if (window) host = window.location.host;
> +
> + // test a vhost with a path as well
> + run_on_modified_server(
> + [{section: "vhosts",
> + key: encodeURIComponent(host + '/path'),
> + value: "/test_suite_db/_design/rwtest/_rewrite/"}
> + ],
> + function(){
> + var res = CouchDB.request("GET", "/path/testShow");
> + TEquals('/path/testShow', res.responseText, "requested_path should equal requested");
> + }
> + );
> +
> + // 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(host),
> + value: "/test_suite_db/_design/rwtest/_rewrite/"}
> + ],
> + function() {
> + var res = CouchDB.request("GET", "/testShow");
> + TEquals('/testShow', res.responseText, "requested_path should equal requested");
> + }
> + );
> + }
> + );
> }
>