[Jifty-commit] jifty branch, jifty_client, updated. 6a05c29ec46d206917da65159d40aa58fde626fe

Jifty commits jifty-commit at lists.jifty.org
Mon May 24 08:22:54 EDT 2010


The branch, jifty_client has been updated
       via  6a05c29ec46d206917da65159d40aa58fde626fe (commit)
       via  89731cdb9210dc18c91165e7b9a53c0c1e513b10 (commit)
       via  2826d95c441ef6328db3d8225cf38ecf3c85a3c2 (commit)
       via  ac5284fc9568583442aaf04da7fb91f345b965fb (commit)
       via  aa5f694c048c10296d277605ce8f5e38e94cf5ce (commit)
       via  54665315f79a99fe1a9d807cfac1e322d29553ae (commit)
       via  64f990b70bcec7d30795547751ecee411fa35c01 (commit)
       via  c63843bae8d95e815c0105d0a82c7f2ba6003f10 (commit)
       via  23f36ebe4b8153edaa34f8266b0c8d2cac4e0f26 (commit)
       via  3aa3f6e8d2bfdf5aab9483a02b26780c356b9eab (commit)
       via  200a13bc352374ea1fc374774f7efff9e1bcae2a (commit)
       via  1c5144b8d723e511095006aa807b187be64d80ee (commit)
       via  4daf8b46ab4018160c6cbe1e6227e2fc5c0e09f6 (commit)
       via  90666847469c97ec5d692f94a52c40a66892badd (commit)
       via  0ffc280aee6c538f3aa9494d6650b0c2b71ac450 (commit)
       via  173f439f4229e46a772e4dbe14a72366a8c5f265 (commit)
       via  22db8ba6a094d791a7285822716fbd09996b5d36 (commit)
       via  29326331c90d064f3f6040678d7a0b12aec22634 (commit)
      from  9be1c08a5c4f765221dd74445bd35eb49cc9b58f (commit)

Summary of changes:
 lib/Jifty/Continuation.pm                          |   29 +++++----
 lib/Jifty/Plugin/ErrorTemplates/View.pm            |    2 +-
 lib/Jifty/Plugin/RequestInspector.pm               |    6 +-
 lib/Jifty/Request.pm                               |   28 ++++++--
 lib/Jifty/Test.pm                                  |    3 +
 lib/Jifty/Web.pm                                   |   14 ++--
 lib/Jifty/Web/Session.pm                           |   10 +++
 lib/Jifty/Web/Session/ApacheSession.pm             |   20 +++++-
 lib/Jifty/Web/Session/ClientSide.pm                |   33 ++++++++--
 lib/Jifty/Web/Session/JDBI.pm                      |   14 ++++-
 lib/Jifty/Web/Session/None.pm                      |    8 ++
 share/web/static/js/jifty.js                       |   69 +++++++++++++------
 t/TestApp-Dispatcher/t/00-basic.t                  |    2 +-
 .../t/02-dispatch-show-rule-in-wrong-ruleset.t     |    6 +-
 t/TestApp/t/07-sandboxing.t                        |   65 ++++++++-----------
 t/TestApp/t/20-error-pages.t                       |    2 -
 t/TestApp/t/regex_meta_in_path_info.t              |    3 +-
 17 files changed, 204 insertions(+), 110 deletions(-)

- Log -----------------------------------------------------------------
commit 29326331c90d064f3f6040678d7a0b12aec22634
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu May 20 16:01:36 2010 -0400

    Add a way to create a new session, explicitly

diff --git a/lib/Jifty/Web/Session.pm b/lib/Jifty/Web/Session.pm
index 0a1668e..3fa583f 100644
--- a/lib/Jifty/Web/Session.pm
+++ b/lib/Jifty/Web/Session.pm
@@ -43,6 +43,16 @@ sub id {
     die "Subclass must implement 'id'";
 }
 
+=head2 create
+
+Assign a new ID, and store it server-side if necessary.
+
+=cut
+
+sub create {
+    die "Subclass must implement 'create'";
+}
+
 =head2 load [ID]
 
 Load up the current session from the given C<ID>, or the appropriate
diff --git a/lib/Jifty/Web/Session/ApacheSession.pm b/lib/Jifty/Web/Session/ApacheSession.pm
index 15c3646..d397555 100644
--- a/lib/Jifty/Web/Session/ApacheSession.pm
+++ b/lib/Jifty/Web/Session/ApacheSession.pm
@@ -59,6 +59,20 @@ sub id {
     return $self->loaded ? $self->_session->{_session_id} : undef;
 }
 
+=head2 create
+
+Creates a new session.
+
+=cut
+
+sub create {
+    my $self = shift;
+    my %session;
+    my $options = Jifty->config->framework('Web')->{'SessionOptions'};
+    tie %session => $self->{_backend_class}, undef, $options;
+    $self->{_session} = \%session;
+}
+
 =head2 load [ID]
 
 Load up the current session from the given C<ID>, or the appropriate
diff --git a/lib/Jifty/Web/Session/ClientSide.pm b/lib/Jifty/Web/Session/ClientSide.pm
index dc6d986..ff46c0b 100644
--- a/lib/Jifty/Web/Session/ClientSide.pm
+++ b/lib/Jifty/Web/Session/ClientSide.pm
@@ -71,6 +71,23 @@ sub id {
     return $self->loaded ? $self->_session->{session_id} : undef;
 }
 
+=head2 create
+
+Since there is no server-side storage, this simply clears the object's
+local state.
+
+=cut
+
+sub create {
+    my $self = shift;
+    $self->_session({
+        session_id   => Jifty::Model::Session->new_session_id,
+        continuation => {},
+        metadata     => {},
+        key          => {},
+    });
+}
+
 =head2 load [ID]
 
 Load up the current session from the given C<ID>, or the appropriate
diff --git a/lib/Jifty/Web/Session/JDBI.pm b/lib/Jifty/Web/Session/JDBI.pm
index f07d432..3c3b374 100644
--- a/lib/Jifty/Web/Session/JDBI.pm
+++ b/lib/Jifty/Web/Session/JDBI.pm
@@ -45,6 +45,19 @@ sub id {
     return $self->loaded ? $self->_session->session_id : undef;
 }
 
+=head2 create
+
+Creates a new row in the L<Jifty::Model::Session> table.
+
+=cut
+
+sub create {
+    my $self = shift;
+    my $session = Jifty::Model::Session->new;
+    $session->create( key_type => "session" );
+    $self->_session($session);
+}
+
 =head2 load [ID]
 
 Load up the current session from the given C<ID>, or the appropriate
diff --git a/lib/Jifty/Web/Session/None.pm b/lib/Jifty/Web/Session/None.pm
index ed323b1..58e1c53 100644
--- a/lib/Jifty/Web/Session/None.pm
+++ b/lib/Jifty/Web/Session/None.pm
@@ -56,6 +56,14 @@ Returns false.
 
 sub id {return undef }
 
+=head2 create
+
+Returns true.
+
+=cut
+
+sub create { return 1}
+
 =head2 load
 
 Returns true.

commit 22db8ba6a094d791a7285822716fbd09996b5d36
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri May 21 17:19:22 2010 -0400

    Keep the current plack env when restoring from a continuation
    
    This avoids having to specifically swap in various psgi and plack
    variables, as we were doing manually.  It also means that the
    request's ->referer, ->remote_host, etc are correct for the _current_
    request, rather than being empty (if the request was hand-constructed)
    or being from the stored request.
    
    It is slightly overzealous in that ->parameters will disagree with
    ->env->{QUERY_STRING}, for instance, but ->parameters is correctly
    inherited from the request in the continuation.

diff --git a/lib/Jifty/Continuation.pm b/lib/Jifty/Continuation.pm
index 25606e2..6b87bf9 100644
--- a/lib/Jifty/Continuation.pm
+++ b/lib/Jifty/Continuation.pm
@@ -135,10 +135,7 @@ sub new {
     # from plack so we don't have plack-specified fields to hide here.
 
     # Make sure we don't store any of the connection information
-    local $self->request->{env}{"psgi.input"};
-    local $self->request->{env}{"psgi.errors"};
-    local $self->request->{env}{"psgix.io"};
-    local $self->request->{env}{"plack.request.tempfh"};
+    local $self->request->{env};
     local $self->request->{_body_parser}{input_handle} if defined $self->request->{_body_parser};
 
     # Save it into the session
@@ -254,14 +251,16 @@ sub return {
     $self->code->(Jifty->web->request)
       if $self->code;
 
-    # Set the current request to the one in the continuation
-    my $input  = Jifty->web->request->env->{"psgi.input"};
-    my $errors = Jifty->web->request->env->{"psgi.errors"};
+    # We want to preserve the current actual request environment
+    # (headers, etc)
+    my $env = Jifty->web->request->env;
 
+    # Set the current request to the one in the continuation
     Jifty->web->request($self->request->clone);
 
-    Jifty->web->request->env->{"psgi.input"}  = $input;
-    Jifty->web->request->env->{"psgi.errors"} = $errors;
+    # Restore the environment we came in with
+    Jifty->web->request->{env} = $env;
+
     return Jifty->web->request;
 }
 

commit 173f439f4229e46a772e4dbe14a72366a8c5f265
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri May 21 18:05:39 2010 -0400

    Move from CGI::Cookie, which looks at ENV, to plack's way of cookie handling

diff --git a/lib/Jifty/Plugin/RequestInspector.pm b/lib/Jifty/Plugin/RequestInspector.pm
index 92f5f42..a18dfd1 100644
--- a/lib/Jifty/Plugin/RequestInspector.pm
+++ b/lib/Jifty/Plugin/RequestInspector.pm
@@ -132,8 +132,7 @@ sub new_request_inspection {
     };
 
     if (my $cookie_name = $self->on_cookie) {
-        my %cookies     = CGI::Cookie->fetch();
-        $ret->{cookie} = $cookies{$cookie_name}->value;
+        $ret->{cookie} = $req->cookies->{$cookie_name};
     }
     return $ret;
 }
@@ -195,8 +194,7 @@ sub should_handle_request {
     return unless $url =~ $self->url_filter;
 
     if (my $cookie_name = $self->on_cookie) {
-        my %cookies     = CGI::Cookie->fetch();
-        return unless $cookies{$cookie_name};
+        return unless $req->cookies->{$cookie_name};
     }
 
     return 1;
diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index b6fac8b..b4f467f 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -9,7 +9,6 @@ Jifty::Web - Web framework for a Jifty application
 
 =cut
 
-use CGI::Cookie;
 use XML::Writer;
 use CSS::Squish;
 use Digest::MD5 qw(md5_hex);
diff --git a/lib/Jifty/Web/Session/ApacheSession.pm b/lib/Jifty/Web/Session/ApacheSession.pm
index d397555..442542f 100644
--- a/lib/Jifty/Web/Session/ApacheSession.pm
+++ b/lib/Jifty/Web/Session/ApacheSession.pm
@@ -85,13 +85,11 @@ If both of those fail, creates a session in memory.
 sub load {
     my $self       = shift;
     my $session_id = shift;
-    my %cookies    = CGI::Cookie->fetch();
 
     unless ($session_id) {
         my $cookie_name = $self->cookie_name;
-        $session_id = $cookies{$cookie_name}
-            ? $cookies{$cookie_name}->value()
-            : Jifty::Model::Session->new_session_id,
+        $session_id = Jifty->web->request->cookies->{$cookie_name}
+            || Jifty::Model::Session->new_session_id,
     }
 
     my $options = Jifty->config->framework('Web')->{'SessionOptions'};
diff --git a/lib/Jifty/Web/Session/ClientSide.pm b/lib/Jifty/Web/Session/ClientSide.pm
index ff46c0b..b2eda81 100644
--- a/lib/Jifty/Web/Session/ClientSide.pm
+++ b/lib/Jifty/Web/Session/ClientSide.pm
@@ -23,6 +23,7 @@ use Storable ();
 use Compress::Zlib ();
 use Crypt::CBC ();
 use Crypt::Rijndael ();
+use CGI::Cookie;
 use CGI::Cookie::Splitter ();
 use MIME::Base64;
 
@@ -100,11 +101,11 @@ If both of those fail, creates a session in memory.
 sub load {
     my $self       = shift;
     my $session_id = shift;
-    my %cookies    = CGI::Cookie->fetch();
+    my %cookies    = %{ Jifty->web->request->cookies };
 
     unless ($session_id) {
         my $cookie_name = $self->cookie_name;
-        $session_id = $cookies{$cookie_name}->value() if $cookies{$cookie_name};
+        $session_id = $cookies{$cookie_name} if $cookies{$cookie_name};
         $session_id ||= Jifty::Model::Session->new_session_id;
     }
 
@@ -114,12 +115,17 @@ sub load {
     {
         local $@;
         eval {
-            ($data) = grep {
-                $_->name eq "JIFTY_DAT_$session_id"
-            } $splitter->join(values %cookies);
+            ($data)
+                = grep { $_->name eq "JIFTY_DAT_$session_id" }
+                $splitter->join(
+                map {
+                    CGI::Cookie->new( -name => $_, -value => $cookies{$_} )
+                    } keys %cookies
+                );
         };
 
         if ($@) {
+
             # Reassembly of cookie failed -- start a new session
             $session_id = Jifty::Model::Session->new_session_id;
             warn $@;
diff --git a/lib/Jifty/Web/Session/JDBI.pm b/lib/Jifty/Web/Session/JDBI.pm
index 3c3b374..d919ef7 100644
--- a/lib/Jifty/Web/Session/JDBI.pm
+++ b/lib/Jifty/Web/Session/JDBI.pm
@@ -3,7 +3,6 @@ use strict;
 
 package Jifty::Web::Session::JDBI;
 use base qw/Jifty::Web::Session/;
-use CGI::Cookie ();
 use DateTime    ();
 use Storable    ();
 $Storable::Deparse    = 1;

commit 0ffc280aee6c538f3aa9494d6650b0c2b71ac450
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri May 21 21:34:41 2010 -0400

    Minor whitespace fixups

diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index b4f467f..f1371db 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -224,17 +224,16 @@ sub current_user {
     }
 
     my $object;
-
     if ( defined $self->temporary_current_user ) {
         return $self->temporary_current_user;
     } elsif ( defined $self->{current_user} ) {
         return $self->{current_user};
     } elsif ( my $id = $self->session->get('user_id') ) {
-         $object = Jifty->app_class({require => 0}, "CurrentUser")->new( id => $id );
+        $object = Jifty->app_class({require => 0}, "CurrentUser")->new( id => $id );
     } elsif ( Jifty->admin_mode ) {
-         $object = Jifty->app_class({require => 0}, "CurrentUser")->superuser;
+        $object = Jifty->app_class({require => 0}, "CurrentUser")->superuser;
     } else {
-         $object = Jifty->app_class({require => 0}, "CurrentUser")->new;
+        $object = Jifty->app_class({require => 0}, "CurrentUser")->new;
     }
     
     $self->{current_user} = $object;

commit 90666847469c97ec5d692f94a52c40a66892badd
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri May 21 21:34:47 2010 -0400

    Only cache the current_user object if the session is loaded
    
    This prevents negative lookups (due to the session not having been
    loaded yet) from being cached indefinitely.  Plugins which do things
    early (in ->new_request, or the 'have_request' callback) will still
    get an empty current_user, but this will no longer be incorrectly
    cached for the duration of the request.

diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index f1371db..a770975 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -235,8 +235,10 @@ sub current_user {
     } else {
         $object = Jifty->app_class({require => 0}, "CurrentUser")->new;
     }
-    
-    $self->{current_user} = $object;
+
+    # Don't cache the result unless the session had actually been
+    # loaded already.
+    $self->{current_user} = $object if $self->session->loaded;
     return $object;
 }
 

commit 4daf8b46ab4018160c6cbe1e6227e2fc5c0e09f6
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri May 21 23:58:15 2010 -0400

    In tests, remember to actually stop the testserver, if we started one
    
    This allows us to drop the database cleanly

diff --git a/lib/Jifty/Test.pm b/lib/Jifty/Test.pm
index 2ba5b00..7125c5d 100644
--- a/lib/Jifty/Test.pm
+++ b/lib/Jifty/Test.pm
@@ -678,6 +678,9 @@ sub _ending {
         }
     }
 
+    # Turn off the server
+    undef $Jifty::SERVER;
+
     # If all tests passed..
     if (Jifty::Test->is_passing && Jifty::Test->is_done) {
         # Clean up mailbox

commit 1c5144b8d723e511095006aa807b187be64d80ee
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 01:19:08 2010 -0400

    Merge good and bad tests into one structure

diff --git a/t/TestApp/t/07-sandboxing.t b/t/TestApp/t/07-sandboxing.t
index e8cd1ad..c14177a 100644
--- a/t/TestApp/t/07-sandboxing.t
+++ b/t/TestApp/t/07-sandboxing.t
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 125, actual_server => 1;
+use Jifty::Test::Dist tests => 126, actual_server => 1;
 use Jifty::Test::WWW::Mechanize;
 use Net::HTTP;
 use URI;
@@ -14,46 +14,41 @@ isa_ok($server, 'Jifty::TestServer');
 my $uri = URI->new($server->started_ok);
 my $plugin = Jifty->find_plugin("Jifty::Plugin::TestServerWarnings");
 
-my @bogus = qw{
-    ../../../../../../../../../etc/passwd
-    /../../../../../../../../../etc/passwd
-    /__jifty/../../../../../../../../../../etc/passwd
-    /static/../../../../../../../../../../etc/passwd
-    ../templates/index.html
-    ../templates/_elements/nav
-    /static/../templates/_elements/nav
-    /static/css/../../templates/index.html
-    /static/css/../../templates/_elements/nav
-};
+my @requests = (
+    "../../../../../../../../../etc/passwd"             => 404,
+    "/../../../../../../../../../etc/passwd"            => 404,
+    "/__jifty/../../../../../../../../../../etc/passwd" => 404,
+    "/static/../../../../../../../../../../etc/passwd"  => 404,
+    "../templates/index.html"                           => 404,
+    "../templates/_elements/nav"                        => 404,
+    "/static/../templates/_elements/nav"                => 404,
+    "/static/css/../../templates/index.html"            => 404,
+    "/static/css/../../templates/_elements/nav"         => 404,
+    "/static/css/base.css"                              => qr/body/,
+    "/static/css/../css/base.css"                       => qr/body/,
+    "/static/css//../css/base.css"                      => qr/body/,
+    "/somedir/stuff"                                    => qr/dhandler arg is stuff/,
+    "/somedir/stuff/../things"                          => qr/dhandler arg is things/,
+    "__jifty/webservices/yaml"                          => qr/--- {}/,
+    "/__jifty//../__jifty/webservices/yaml"             => qr/--- {}/,
+    "/__jifty/webservices/../webservices/yaml"          => qr/--- {}/,
+    "///__jifty/webservices/yaml"                       => qr/--- {}/,
+    "/__jifty/../index.html"                            => qr/pony/,
+);
 
-for my $path (@bogus) {
+while (my ($path, $expect) = splice(@requests,0,2)) {
     my ($status, $body) = bogus_request($path);
-    isnt($status, 200, "Didn't get a 200" );
+    my $expect_status = $expect =~ /\D/ ? 200 : $expect;
+    is($status, $expect_status, "Got a $status" );
+
     unlike( $body, qr/root/, "Doesn't have a root user in it");
-    unlike( $body, qr{\Q<&|/_elements/\E}, "Doesn't have the source code" );
-    unlike( $body, qr/Jifty->web->navigation/, "Doesn't have the source" );
-    is(scalar $plugin->decoded_warnings($uri), 1);
-}
+    unlike( $body, qr{\Q<&|/_elements/\E|Jifty->web}, "Doesn't have the source code" );
 
-my %ok = (
-    "/static/css/base.css" => qr/body/,
-    "/static/css/../css/base.css" => qr/body/,
-    "/static/css//../css/base.css" => qr/body/,
-    "/somedir/stuff" => qr/dhandler arg is stuff/,
-    "/somedir/stuff/../things" => qr/dhandler arg is things/,
-    "__jifty/webservices/yaml" => qr/--- {}/,
-    "/__jifty//../__jifty/webservices/yaml" => qr/--- {}/,
-    "/__jifty/webservices/../webservices/yaml" => qr/--- {}/,
-    "///__jifty/webservices/yaml" => qr/--- {}/,
-    "/__jifty/../index.html" => qr/pony/,
-);
+    like( $body, $expect, "Has content" ) if $expect_status == 200;
 
-for my $path (keys %ok) {
-    my ($status, $body) = bogus_request($path);
-    is( $status, 200, "Got a 200" );
-    like( $body, $ok{$path}, "Has content" );
-    unlike( $body, qr{\Q<&|/_elements/\E}, "Doesn't have the source code" );
-    is(scalar $plugin->decoded_warnings($uri), 0);
+    my @warn = $plugin->decoded_warnings($uri);
+    my $warn_expect = $expect_status == 200 ? 0 : 1;
+    is(scalar @warn, $warn_expect, "Got expected warning: @warn");
 }
 
 sub bogus_request {

commit 200a13bc352374ea1fc374774f7efff9e1bcae2a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 01:21:48 2010 -0400

    Downgrade the 404 warning to info-level -- it's not an error

diff --git a/lib/Jifty/Plugin/ErrorTemplates/View.pm b/lib/Jifty/Plugin/ErrorTemplates/View.pm
index 3f5feae..a92cf66 100644
--- a/lib/Jifty/Plugin/ErrorTemplates/View.pm
+++ b/lib/Jifty/Plugin/ErrorTemplates/View.pm
@@ -110,7 +110,7 @@ sub maybe_page (&;$) {
 
 template '/errors/404' => sub {
     my $file = get('path') || Jifty->web->request->path;
-    Jifty->log->error( "404: user tried to get to " . $file );
+    Jifty->log->info( "404: user tried to get to " . $file );
     Jifty->web->response->status( 404 )
         unless Jifty->web->request->is_subrequest;
     maybe_page { title => _("Something's not quite right") } content {
diff --git a/t/TestApp/t/07-sandboxing.t b/t/TestApp/t/07-sandboxing.t
index c14177a..1e4b01f 100644
--- a/t/TestApp/t/07-sandboxing.t
+++ b/t/TestApp/t/07-sandboxing.t
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 126, actual_server => 1;
+use Jifty::Test::Dist tests => 104, actual_server => 1;
 use Jifty::Test::WWW::Mechanize;
 use Net::HTTP;
 use URI;
@@ -45,10 +45,6 @@ while (my ($path, $expect) = splice(@requests,0,2)) {
     unlike( $body, qr{\Q<&|/_elements/\E|Jifty->web}, "Doesn't have the source code" );
 
     like( $body, $expect, "Has content" ) if $expect_status == 200;
-
-    my @warn = $plugin->decoded_warnings($uri);
-    my $warn_expect = $expect_status == 200 ? 0 : 1;
-    is(scalar @warn, $warn_expect, "Got expected warning: @warn");
 }
 
 sub bogus_request {

commit 3aa3f6e8d2bfdf5aab9483a02b26780c356b9eab
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 01:22:46 2010 -0400

    PSGI's static handler 403's anything with a ../ in it

diff --git a/t/TestApp/t/07-sandboxing.t b/t/TestApp/t/07-sandboxing.t
index 1e4b01f..10c3da9 100644
--- a/t/TestApp/t/07-sandboxing.t
+++ b/t/TestApp/t/07-sandboxing.t
@@ -18,15 +18,15 @@ my @requests = (
     "../../../../../../../../../etc/passwd"             => 404,
     "/../../../../../../../../../etc/passwd"            => 404,
     "/__jifty/../../../../../../../../../../etc/passwd" => 404,
-    "/static/../../../../../../../../../../etc/passwd"  => 404,
+    "/static/../../../../../../../../../../etc/passwd"  => 403,
     "../templates/index.html"                           => 404,
     "../templates/_elements/nav"                        => 404,
-    "/static/../templates/_elements/nav"                => 404,
-    "/static/css/../../templates/index.html"            => 404,
-    "/static/css/../../templates/_elements/nav"         => 404,
+    "/static/../templates/_elements/nav"                => 403,
+    "/static/css/../../templates/index.html"            => 403,
+    "/static/css/../../templates/_elements/nav"         => 403,
     "/static/css/base.css"                              => qr/body/,
-    "/static/css/../css/base.css"                       => qr/body/,
-    "/static/css//../css/base.css"                      => qr/body/,
+    "/static/css/../css/base.css"                       => 403,
+    "/static/css//../css/base.css"                      => 403,
     "/somedir/stuff"                                    => qr/dhandler arg is stuff/,
     "/somedir/stuff/../things"                          => qr/dhandler arg is things/,
     "__jifty/webservices/yaml"                          => qr/--- {}/,

commit 23f36ebe4b8153edaa34f8266b0c8d2cac4e0f26
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 01:23:35 2010 -0400

    PSGI 404's anything that doesn't start with a /

diff --git a/t/TestApp/t/07-sandboxing.t b/t/TestApp/t/07-sandboxing.t
index 10c3da9..bfc3b61 100644
--- a/t/TestApp/t/07-sandboxing.t
+++ b/t/TestApp/t/07-sandboxing.t
@@ -29,7 +29,7 @@ my @requests = (
     "/static/css//../css/base.css"                      => 403,
     "/somedir/stuff"                                    => qr/dhandler arg is stuff/,
     "/somedir/stuff/../things"                          => qr/dhandler arg is things/,
-    "__jifty/webservices/yaml"                          => qr/--- {}/,
+    "__jifty/webservices/yaml"                          => 404,
     "/__jifty//../__jifty/webservices/yaml"             => qr/--- {}/,
     "/__jifty/webservices/../webservices/yaml"          => qr/--- {}/,
     "///__jifty/webservices/yaml"                       => qr/--- {}/,

commit c63843bae8d95e815c0105d0a82c7f2ba6003f10
Author: c9s <cornelius.howl at gmail.com>
Date:   Sat May 22 05:39:22 2010 +0800

    Update js region document and added a region helper function

diff --git a/share/web/static/js/jifty.js b/share/web/static/js/jifty.js
index b3c1efe..afb442b 100644
--- a/share/web/static/js/jifty.js
+++ b/share/web/static/js/jifty.js
@@ -1102,28 +1102,53 @@ var apply_fragment_updates = function(fragment, f) {
     }
 }
 
-// Update a region. It takes two arguments.
-//
-// The first argument is a hash of named parameters, including:
-//  - 'actions' is an array of monikers to submit
-//  - 'action_arguments' is a hash of action monikers to hashes of arguments which should override any arguments coming from form fields
-//        the hash keys for 'action_arguments' are the values of the 'actions' array
-//  - 'continuation' is ??? Please document me
-//  - 'hide_wait_message' for when you don't want to see it
-//  - 'preload' this request is preloading regions
-//  - 'preload_key' the cache key for using preloaded regions
-//  - 'headers' is a hash of headers to send in this request
-//  - 'fragments' is an array of hashes, which may have:
-//     - 'region' is the name of the region to update
-//     - 'args' is a hash of arguments to override
-//     - 'path' is the path of the fragment (if this is a new fragment)
-//     - 'element' is the CSS selector of the element to update, if 'region' isn't supplied
-//     - 'mode' is one of 'Replace', 'Top', 'Bottom', 'Before', or 'After'
-//     - 'effect' is the name of an effect
-//
-// The second argument is the element (usually a submit button) that triggered
-// it.
-//
+/* Region update helper 
+ *  Jifty.replaceRegion( 'region-name' , '/path' , { id: 123123 , msg: 'blah'  } );
+ */
+Jifty.updateRegion = function( regionName , path , args , mode ) {
+    Jifty.update({
+        fragments: [{ region: '__page-' + regionName ,
+            args: args, path: path, mode: mode ? mode : 'Replace' }]
+    });
+};
+
+/* Update a region. It takes two arguments.
+  
+   Usage:
+
+    Jifty.update({
+        fragments: [{
+            region: '__page-region_name' ,
+            args: { id => 123  }
+            path: '/path_to_replace',
+            mode: 'Replace'
+        }]
+    });
+   
+   Description:
+
+   The first argument is a hash of named parameters, including:
+    - 'actions' is an array of monikers to submit
+    - 'action_arguments' is a hash of action monikers to hashes of arguments which should override any arguments coming from form fields
+          the hash keys for 'action_arguments' are the values of the 'actions' array
+    - 'continuation' is ??? Please document me
+    - 'hide_wait_message' for when you don't want to see it
+    - 'preload' this request is preloading regions
+    - 'preload_key' the cache key for using preloaded regions
+    - 'headers' is a hash of headers to send in this request
+    - 'fragments' is an array of hashes, which may have:
+       - 'region' is the name of the region to update
+       - 'args' is a hash of arguments to override
+       - 'path' is the path of the fragment (if this is a new fragment)
+       - 'element' is the CSS selector of the element to update, if 'region' isn't supplied
+       - 'mode' is one of 'Replace', 'Top', 'Bottom', 'Before', or 'After'
+       - 'effect' is the name of an effect
+  
+    The second argument is the element (usually a submit button) that triggered
+    it.
+ */
+
+
 Jifty.update = function () {
     // Let the regular form submit take over if this browser can't do this
     if (!Jifty.hasAjaxTransport) return true;

commit 64f990b70bcec7d30795547751ecee411fa35c01
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 08:49:29 2010 -0400

    Test fixes for 404s no longer being warnings

diff --git a/t/TestApp-Dispatcher/t/00-basic.t b/t/TestApp-Dispatcher/t/00-basic.t
index 871f275..ceadfb7 100644
--- a/t/TestApp-Dispatcher/t/00-basic.t
+++ b/t/TestApp-Dispatcher/t/00-basic.t
@@ -33,4 +33,4 @@ get_ok("/on_not_exist_show");
 $mech->content_contains("woot");
 
 get_nok("/something_that_really_not_exists");
-$mech->warnings_like(qr/404/);
+$mech->content_like(qr/we don&#39;t think exists/);
diff --git a/t/TestApp/t/02-dispatch-show-rule-in-wrong-ruleset.t b/t/TestApp/t/02-dispatch-show-rule-in-wrong-ruleset.t
index e702dea..7c17ee2 100644
--- a/t/TestApp/t/02-dispatch-show-rule-in-wrong-ruleset.t
+++ b/t/TestApp/t/02-dispatch-show-rule-in-wrong-ruleset.t
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 11;
+use Jifty::Test::Dist tests => 9;
 use Jifty::Test::WWW::Mechanize;
 
 my $server  = Jifty::Test->make_server;
@@ -15,7 +15,7 @@ my $mech    = Jifty::Test::WWW::Mechanize->new();
 $mech->get("$URL/before_stage_show");
 $mech->content_lacks("This is content");
 is( $mech->status , '404');
-$mech->warnings_like([qr/can't call a 'show' rule in a 'before' or 'after' block/, qr/404/]);
+$mech->warnings_like([qr/can't call a 'show' rule in a 'before' or 'after' block/]);
 
 $mech->get("$URL/on_stage_show");
 $mech->content_contains("his is content");
@@ -23,6 +23,6 @@ $mech->content_contains("his is content");
 $mech->get("$URL/after_stage_show");
 $mech->content_lacks("This is content");
 is( $mech->status , '404');
-$mech->warnings_like([qr/404/, qr/can't call a 'show' rule in a 'before' or 'after' block/]);
+$mech->warnings_like([qr/can't call a 'show' rule in a 'before' or 'after' block/]);
 
 1;
diff --git a/t/TestApp/t/regex_meta_in_path_info.t b/t/TestApp/t/regex_meta_in_path_info.t
index 679f6ec..49298cc 100644
--- a/t/TestApp/t/regex_meta_in_path_info.t
+++ b/t/TestApp/t/regex_meta_in_path_info.t
@@ -6,7 +6,7 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 3;
+use Jifty::Test::Dist tests => 2;
 use Jifty::Test::WWW::Mechanize;
 
 my $server  = Jifty::Test->make_server;
@@ -15,4 +15,3 @@ my $mech    = Jifty::Test::WWW::Mechanize->new();
 
 $mech->get("$URL/*****");
 is( $mech->status, '404', 'regex metachars in URL does not cause error' );
-$mech->warnings_like(qr/404/);

commit 54665315f79a99fe1a9d807cfac1e322d29553ae
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 10:55:32 2010 -0400

    Remove an extraneous "diag"

diff --git a/t/TestApp/t/20-error-pages.t b/t/TestApp/t/20-error-pages.t
index 9efd026..5efeafb 100644
--- a/t/TestApp/t/20-error-pages.t
+++ b/t/TestApp/t/20-error-pages.t
@@ -13,8 +13,6 @@ use Jifty::Test::Dist tests => 1 + 2 * 29;
 use Jifty::Test::WWW::Mechanize;
 
 my $URL = Jifty::Test->make_server->started_ok;
-#my $URL = $s->started_ok;
-diag $URL;
 my $mech = Jifty::Test::WWW::Mechanize->new;
 
 for my $path ("", "/td") {

commit aa5f694c048c10296d277605ce8f5e38e94cf5ce
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 10:55:54 2010 -0400

    POD formatting nitpick

diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index 0bf5929..da58ad6 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -114,6 +114,7 @@ method of that name is called, with the I<PARAMHASH>'s value as its
 sole argument.
 
 =cut
+
 sub BUILD {
     my $self = shift;
 

commit ac5284fc9568583442aaf04da7fb91f345b965fb
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 10:56:27 2010 -0400

    Factor out method to create new subrequest env from top request

diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index da58ad6..59967d0 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -118,13 +118,7 @@ sole argument.
 sub BUILD {
     my $self = shift;
 
-    # Copy a bunch of information off of the top Plack request
-    if ( Jifty->web->request ) {
-        my $env = Jifty->web->request->top_request->env;
-        $self->{env}{$_} = $env->{$_} for qw/psgi.version psgi.multithread psgi.multiprocess psgi.errors/;
-        # Stub in an empty input filehandle
-        $self->{env}{"psgi.input"} = Plack::Util::inline_object( read => sub {0} );
-    }
+    $self->setup_subrequest_env if Jifty->web->request;
 
     $self->{'actions'} = {};
     $self->{'state_variables'} = {};
@@ -136,6 +130,23 @@ sub BUILD {
     $self->template_arguments({});
 }
 
+=head2 setup_subrequest_env
+
+Copies the bare minimals of the plack environment from the top
+request; this is called in L</BUILD> if the request is a subrequest.
+
+=cut
+
+sub setup_subrequest_env {
+    my $self = shift;
+    # Copy a bunch of information off of the top Plack request
+    my $env = Jifty->web->request->top_request->env;
+    $self->{env} = {};
+    $self->{env}{$_} = $env->{$_} for qw/psgi.version psgi.multithread psgi.multiprocess psgi.errors/;
+    # Stub in an empty input filehandle
+    $self->{env}{"psgi.input"} = Plack::Util::inline_object( read => sub {0} );
+}
+
 =head2 clone
 
 Return a copy of the request.

commit 2826d95c441ef6328db3d8225cf38ecf3c85a3c2
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 10:57:10 2010 -0400

    We may need to clean out both the current and top request envs

diff --git a/lib/Jifty/Continuation.pm b/lib/Jifty/Continuation.pm
index 6b87bf9..2819535 100644
--- a/lib/Jifty/Continuation.pm
+++ b/lib/Jifty/Continuation.pm
@@ -131,12 +131,14 @@ sub new {
     my $key = Jifty->web->serial . "_" . int(rand(10)) . int(rand(10)) . int(rand(10)) . int(rand(10)) . int(rand(10)) . int(rand(10));
     $self->id($key);
 
-    # XXX: Jifty::Request should really just extract useful things
-    # from plack so we don't have plack-specified fields to hide here.
-
     # Make sure we don't store any of the connection information
-    local $self->request->{env};
-    local $self->request->{_body_parser}{input_handle} if defined $self->request->{_body_parser};
+    my $req = $self->request;
+    local $req->{env};
+    local $req->{_body_parser}{input_handle} if defined $req->{_body_parser};
+    # We may also need to clean out the top request, if this is a subrequest
+    $req = $req->top_request;
+    local $req->{env};
+    local $req->{_body_parser}{input_handle} if defined $req->{_body_parser};
 
     # Save it into the session
     Jifty->web->session->set_continuation($key => $self);

commit 89731cdb9210dc18c91165e7b9a53c0c1e513b10
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 10:57:48 2010 -0400

    We actually want to clone over the top request env, and re-create an empty subrequest env as necessary

diff --git a/lib/Jifty/Continuation.pm b/lib/Jifty/Continuation.pm
index 2819535..41bb436 100644
--- a/lib/Jifty/Continuation.pm
+++ b/lib/Jifty/Continuation.pm
@@ -255,13 +255,15 @@ sub return {
 
     # We want to preserve the current actual request environment
     # (headers, etc)
-    my $env = Jifty->web->request->env;
+    my $env = Jifty->web->request->top_request->env;
 
     # Set the current request to the one in the continuation
     Jifty->web->request($self->request->clone);
 
     # Restore the environment we came in with
-    Jifty->web->request->{env} = $env;
+    Jifty->web->request->top_request->{env} = $env;
+    Jifty->web->request->setup_subrequest_env
+        if Jifty->web->request->is_subrequest;
 
     return Jifty->web->request;
 }

commit 6a05c29ec46d206917da65159d40aa58fde626fe
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sat May 22 10:58:11 2010 -0400

    Use the ->method abstraction rather than going through ->{env}

diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index 59967d0..4095951 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -123,7 +123,7 @@ sub BUILD {
     $self->{'actions'} = {};
     $self->{'state_variables'} = {};
     $self->{'fragments'} = {};
-    $self->{env}{'REQUEST_METHOD'} ||= 'GET';
+    $self->method('GET') unless $self->method;
 
     $self->path("/") unless $self->path;
     $self->arguments({});

-----------------------------------------------------------------------


More information about the Jifty-commit mailing list