[Rt-commit] r2487 - in rt/branches/3.4-RELEASE: . bin html/NoAuth/images lib/RT/Interface/Web lib/t/regression sbin

jesse at bestpractical.com jesse at bestpractical.com
Mon Mar 21 12:10:04 EST 2005


Author: jesse
Date: Mon Mar 21 12:10:03 2005
New Revision: 2487

Added:
   rt/branches/3.4-RELEASE/lib/RT/Interface/Web/Standalone.pm   (contents, props changed)
   rt/branches/3.4-RELEASE/lib/t/regression/02basic_web.t
   rt/branches/3.4-RELEASE/lib/t/regression/03web_compiliation_errors.t
Removed:
   rt/branches/3.4-RELEASE/lib/t/regression/03basic_web.t
Modified:
   rt/branches/3.4-RELEASE/   (props changed)
   rt/branches/3.4-RELEASE/bin/standalone_httpd.in
   rt/branches/3.4-RELEASE/bin/webmux.pl.in
   rt/branches/3.4-RELEASE/html/NoAuth/images/autohandler
   rt/branches/3.4-RELEASE/lib/RT/Interface/Web/Handler.pm
   rt/branches/3.4-RELEASE/sbin/rt-test-dependencies.in
Log:
 r9502 at hualien:  jesse | 2005-03-22 01:07:59 +0800
 * Refactored standalone_httpd to use HTTP::Server::Simple::Mason
 * Moved some configuration from webmux.pl to RT::Interface::Web::Handler
 * Split apart some of the web tests for better isolation


Modified: rt/branches/3.4-RELEASE/bin/standalone_httpd.in
==============================================================================
--- rt/branches/3.4-RELEASE/bin/standalone_httpd.in	(original)
+++ rt/branches/3.4-RELEASE/bin/standalone_httpd.in	Mon Mar 21 12:10:03 2005
@@ -44,170 +44,23 @@
 # those contributions and any derivatives thereof.
 # 
 # END BPS TAGGED BLOCK }}}
-package RT::Mason;
 
+use warnings;
 use strict;
-use vars '$Handler';
-
-BEGIN { require ('@RT_BIN_PATH@/webmux.pl') };
-
-use lib( "@LOCAL_LIB_PATH@", "@RT_LIB_PATH@");
-
-use Socket;
-
-$SIG{CHLD} = 'IGNORE'; # reap child processes
-$SIG{HUP} = sub {
-    # on a "kill -HUP", we first close our socket handles.
-    close Remote;
-    close HTTPDaemon;
-
-    # and then, on systems implementing fork(), we make sure
-    # we are running with a new pid, so another -HUP will still
-    # work on the new process.
-    require Config;
-    if ($Config::Config{d_fork} and my $pid = fork()) {
-        # finally, allow ^C on the parent process to terminate
-        # the children.
-        waitpid($pid, 0); exit;
-    }
-
-    # do the exec. if $0 is not executable, try running it with $^X.
-    exec { $0 } ( ((-x $0) ? () : ($^X)), $0, @ARGV );
-};
 
+BEGIN {
+    use lib( "@LOCAL_LIB_PATH@", "@RT_LIB_PATH@");
+    use RT;
+    RT::LoadConfig();
+    if ($RT::DevelMode) { require Module::Refresh; }
+}
 
 RT::Init();
 
-my $port = shift || '8080';
-
-main_loop($port);
-
-sub main_loop {
-    my $port = shift;
-    my $tcp  = getprotobyname('tcp');
-
-    socket( HTTPDaemon, PF_INET, SOCK_STREAM, $tcp ) or die "socket: $!";
-    setsockopt( HTTPDaemon, SOL_SOCKET, SO_REUSEADDR, pack( "l", 1 ) )
-      or warn "setsockopt: $!";
-    bind( HTTPDaemon, sockaddr_in( $port, INADDR_ANY ) ) or die "bind: $!";
-    listen( HTTPDaemon, SOMAXCONN ) or die "listen: $!";
-
-    print("You can connect to your RT server at http://localhost:$port/\n");
-
-    while (1) {
-
-        for ( ; accept( Remote, HTTPDaemon ); close Remote ) {
-            Module::Refresh->refresh if $RT::DevelMode;
-
-            binmode *Remote, ':utf8';
-            *STDIN  = *Remote;
-            *STDOUT = *Remote;
-
-            my $remote_sockaddr = getpeername(STDIN);
-            my ( undef, $iaddr ) = sockaddr_in($remote_sockaddr);
-            my $peername = gethostbyaddr( $iaddr, AF_INET ) || "localhost";
-            my $peeraddr = inet_ntoa($iaddr) || "127.0.0.1";
-
-            my $local_sockaddr = getsockname(STDIN);
-            my ( undef, $localiaddr ) = sockaddr_in($local_sockaddr);
-            my $localname = gethostbyaddr( $localiaddr, AF_INET )
-              || "localhost";
-            my $localaddr = inet_ntoa($localiaddr) || "127.0.0.1";
-
-            chomp( $_ = <STDIN> );
-            my ( $method, $request_uri, $proto, undef ) = split;
-
-            #$request_uri =~ s#\\#/#g;
-            $RT::Logger->info("<- $peername: $_\n");
-            my ( $file, undef, $query_string ) =
-              ( $request_uri =~ /([^?]*)(\?(.*))?/ );    # split at ?
-            #$file =~ s/%([\dA-Fa-f]{2})/chr(hex($1))/eg;  # decode url-escaped entities
-
-            last if ( $method !~ /^(GET|POST|HEAD)$/ );
-
-            $query_string = '' if !defined $query_string;
-
-            build_cgi_env( method       => $method,
-                           query_string => $query_string,
-                           path         => $file,
-                           protocol     => $proto,
-                           port         => $port,
-                           peername     => $peername,
-                           peeraddr     => $peeraddr,
-                           localname    => $localname,
-                           request_uri  => $request_uri );
-
-            RT::ConnectToDatabase();
-            my $cgi = CGI->new();
-
-            print "HTTP/1.0 200 OK\n";    # probably OK by now
-
-            if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) )
-                && ($Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) )
-              ) {
-                $cgi->path_info( $cgi->path_info . "/index.html" );
-            }
-
-            eval { $Handler->handle_cgi_object($cgi); };
-            $RT::Logger->crit($@) if ($@);
-
-	    RT::Interface::Web::Handler->CleanupRequest();
-        }
-
-    }
-
-}
-
+use RT::Interface::Web::Standalone;
 
+my $server = RT::Interface::Web::Standalone->new;
+$server->port(shift @ARGV) if ($ARGV[0]);
+$server->run();
 
-sub build_cgi_env {
-        my %args = ( query_string => '',
-                     path => '',
-                     port => undef,
-                     protocol => undef,
-                     localname => undef,
-                     method => undef,
-                     remote_name => undef,
- 
-
-                        @_);
-                    
-        foreach my $var qw(USER_AGENT CONTENT_LENGTH CONTENT_TYPE
-          COOKIE SERVER_PORT SERVER_PROTOCOL SERVER_NAME
-          PATH_INFO REQUEST_URI REQUEST_METHOD REMOTE_ADDR
-          REMOTE_HOST QUERY_STRING SERVER_SOFTWARE) {
-            delete $ENV{$var};
-          }
-        while (<STDIN>) {
-            s/[\r\l\n\s]+$//;
-            if( /^([\w\-]+): (.+)/i) {
-                my $tag = uc($1);
-                $tag =~ s/^COOKIES$/COOKIE/;
-                my $val = $2;
-                $tag =~ s/-/_/g;
-                $tag = "HTTP_".$tag unless (grep /^$tag$/, qw(CONTENT_LENGTH CONTENT_TYPE COOKIE));
-                if ($ENV{$tag}) {
-                $ENV{$tag} .= "; $val";
-                }
-                else {
-                $ENV{$tag} = $val;
-                }
-            } 
-            last if (/^$/);
-        }
-
-
-        $ENV{SERVER_PROTOCOL} = $args{protocol};
-        $ENV{SERVER_PORT}     = $args{port};
-        $ENV{SERVER_NAME}     = $args{'localname'};
-        $ENV{SERVER_URL}      = "http://".$args{'localname'}.":".$args{'port'}."/";
-        $ENV{PATH_INFO}       = $args{'path'};
-        $ENV{REQUEST_URI}     = $args{'request_uri'};
-        $ENV{REQUEST_METHOD}  = $args{method};
-        $ENV{REMOTE_ADDR}     = $args{'peeraddr'};
-        $ENV{REMOTE_HOST}     = $args{'peername'};
-        $ENV{QUERY_STRING}    = $args{'query_string'};
-        $ENV{SERVER_SOFTWARE} = "rt-standalone/$RT::VERSION";
 
-        CGI::initialize_globals();
-} 

Modified: rt/branches/3.4-RELEASE/bin/webmux.pl.in
==============================================================================
--- rt/branches/3.4-RELEASE/bin/webmux.pl.in	(original)
+++ rt/branches/3.4-RELEASE/bin/webmux.pl.in	Mon Mar 21 12:10:03 2005
@@ -53,6 +53,9 @@
     $ENV{'ENV'}    = '' if defined $ENV{'ENV'};
     $ENV{'IFS'}    = '' if defined $ENV{'IFS'};
 
+    use CGI qw(-private_tempfiles);    #bring this in before mason, to make sure we
+                                   #set private_tempfiles
+
     eval { require Apache2; require Apache::Request; 1 } or
     eval { require Apache2; require Apache::compat; 1 } or die $@
       if $ENV{'MOD_PERL'}
@@ -65,11 +68,6 @@
 
 package RT::Mason;
 
-use CGI qw(-private_tempfiles);    #bring this in before mason, to make sure we
-                                   #set private_tempfiles
-
-use HTML::Mason;    # brings in subpackages: Parser, Interp, etc.
-
 use vars qw($Nobody $SystemUser $Handler $r);
 
 #This drags in RT's config.pm
@@ -78,24 +76,14 @@
     if ($RT::DevelMode) { require Module::Refresh; }
 }
 
-use Carp;
 
 {
 
     package HTML::Mason::Commands;
     use vars qw(%session);
-
-    use RT::Interface::Web;
-    use MIME::Entity;
-    use Text::Wrapper;
-    use CGI::Cookie;
-    use Time::ParseDate;
-    use Time::HiRes;
-    use HTML::Entities;
-    use HTML::Scrubber;
-    use Text::Quoted;
 }
 
+use RT::Interface::Web;
 use RT::Interface::Web::Handler;
 $Handler = RT::Interface::Web::Handler->new(@RT::MasonParameters);
 

Modified: rt/branches/3.4-RELEASE/html/NoAuth/images/autohandler
==============================================================================
--- rt/branches/3.4-RELEASE/html/NoAuth/images/autohandler	(original)
+++ rt/branches/3.4-RELEASE/html/NoAuth/images/autohandler	Mon Mar 21 12:10:03 2005
@@ -15,7 +15,10 @@
 die unless (-f $file && -r $file);
 $r->content_type($type);
 open (FILE, "<$file") || die;
-$m->out($_) while (<FILE>);
-close(FILE);
+{
+    local $/ = \16384;
+    $m->out($_) while (<FILE>);
+    close(FILE);
+}
 $m->abort;
 </%init>

Modified: rt/branches/3.4-RELEASE/lib/RT/Interface/Web/Handler.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/Interface/Web/Handler.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/Interface/Web/Handler.pm	Mon Mar 21 12:10:03 2005
@@ -43,8 +43,23 @@
 # those contributions and any derivatives thereof.
 # 
 # END BPS TAGGED BLOCK }}}
+
 package RT::Interface::Web::Handler;
 
+use CGI qw/-private_tempfiles/;
+use MIME::Entity;
+use Text::Wrapper;
+use CGI::Cookie;
+use Time::ParseDate;
+use Time::HiRes;
+use HTML::Entities;
+use HTML::Scrubber;
+use Text::Quoted;
+use RT::Interface::Web::Handler;
+use File::Path qw( rmtree );
+use File::Glob qw( bsd_glob );
+use File::Spec::Unix;
+
 sub DefaultHandlerArgs  { (
     comp_root => [
         [ local    => $RT::MasonLocalComponentRoot ],

Added: rt/branches/3.4-RELEASE/lib/RT/Interface/Web/Standalone.pm
==============================================================================
--- (empty file)
+++ rt/branches/3.4-RELEASE/lib/RT/Interface/Web/Standalone.pm	Mon Mar 21 12:10:03 2005
@@ -0,0 +1,24 @@
+package RT::Interface::Web::Standalone;
+
+use strict;
+use base 'HTTP::Server::Simple::Mason';
+use RT::Interface::Web::Handler;
+use RT::Interface::Web;
+
+sub new_handler {
+    RT::Interface::Web::Handler->new(@RT::MasonParameters);
+}
+
+sub handle_request {
+
+    my $self = shift;
+    my $cgi = shift;
+
+    $self->SUPER::handle_request($cgi);
+    $RT::Logger->crit($@) if ($@);
+
+    RT::Interface::Web::Handler->CleanupRequest();
+
+}
+
+1;

Added: rt/branches/3.4-RELEASE/lib/t/regression/02basic_web.t
==============================================================================
--- (empty file)
+++ rt/branches/3.4-RELEASE/lib/t/regression/02basic_web.t	Mon Mar 21 12:10:03 2005
@@ -0,0 +1,148 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More qw/no_plan/;
+use WWW::Mechanize;
+use HTTP::Request::Common;
+use HTTP::Cookies;
+use LWP;
+use Encode;
+
+my $cookie_jar = HTTP::Cookies->new;
+my $agent = WWW::Mechanize->new();
+
+# give the agent a place to stash the cookies
+
+$agent->cookie_jar($cookie_jar);
+
+
+# get the top page
+my $url = "http://localhost".$RT::WebPath."/";
+$agent->get($url);
+
+is ($agent->{'status'}, 200, "Loaded a page");
+
+
+# {{{ test a login
+
+# follow the link marked "Login"
+
+ok($agent->{form}->find_input('user'));
+
+ok($agent->{form}->find_input('pass'));
+ok ($agent->{'content'} =~ /username:/i);
+$agent->field( 'user' => 'root' );
+$agent->field( 'pass' => 'password' );
+# the field isn't named, so we have to click link 0
+$agent->click(0);
+is($agent->{'status'}, 200, "Fetched the page ok");
+ok( $agent->{'content'} =~ /Logout/i, "Found a logout link");
+
+
+
+$agent->get($url."Ticket/Create.html?Queue=1");
+is ($agent->{'status'}, 200, "Loaded Create.html");
+$agent->form(3);
+# Start with a string containing characters in latin1
+my $string = "I18N Web Testing æøå";
+Encode::from_to($string, 'iso-8859-1', 'utf8');
+$agent->field('Subject' => "Ticket with utf8 body");
+$agent->field('Content' => $string);
+ok($agent->submit(), "Created new ticket with $string as Content");
+ok( $agent->{'content'} =~ qr{$string} , "Found the content");
+$agent->get($url."Ticket/Create.html?Queue=1");
+is ($agent->{'status'}, 200, "Loaded Create.html");
+$agent->form(3);
+# Start with a string containing characters in latin1
+my $string = "I18N Web Testing æøå";
+Encode::from_to($string, 'iso-8859-1', 'utf8');
+$agent->field('Subject' => $string);
+$agent->field('Content' => "Ticket with utf8 subject");
+ok($agent->submit(), "Created new ticket with $string as Subject");
+
+ok( $agent->{'content'} =~ qr{$string} , "Found the content");
+
+
+
+# }}}
+
+# {{{ Query Builder tests
+
+my $response = $agent->get($url."Search/Build.html");
+ok( $response->is_success, "Fetched " . $url."Search/Build.html" );
+
+# Parsing TicketSQL
+#
+# Adding items
+
+# set the first value
+ok($agent->form_name('BuildQuery'));
+$agent->field("AttachmentField", "Subject");
+$agent->field("AttachmentOp", "LIKE");
+$agent->field("ValueOfAttachment", "aaa");
+$agent->submit();
+
+# set the next value
+ok($agent->form_name('BuildQuery'));
+$agent->field("AttachmentField", "Subject");
+$agent->field("AttachmentOp", "LIKE");
+$agent->field("ValueOfAttachment", "bbb");
+$agent->submit();
+
+ok($agent->form_name('BuildQuery'));
+
+# get the query
+my $query = $agent->current_form->find_input("Query")->value;
+# strip whitespace from ends
+$query =~ s/^\s*//g;
+$query =~ s/\s*$//g;
+
+# collapse other whitespace
+$query =~ s/\s+/ /g;
+
+is ($query, "Subject LIKE 'aaa' AND Subject LIKE 'bbb'");
+
+# - new items go one level down
+# - add items at currently selected level
+# - if nothing is selected, add at end, one level down
+#
+# move left
+# - error if nothing selected
+# - same item should be selected after move
+# - can't move left if you're at the top level
+#
+# move right
+# - error if nothing selected
+# - same item should be selected after move
+# - can always move right (no max depth...should there be?)
+#
+# move up
+# - error if nothing selected
+# - same item should be selected after move
+# - can't move up if you're first in the list
+#
+# move down
+# - error if nothing selected
+# - same item should be selected after move
+# - can't move down if you're last in the list
+#
+# toggle
+# - error if nothing selected
+# - change all aggregators in the grouping
+# - don't change any others
+#
+# delete
+# - error if nothing selected
+# - delete currently selected item
+# - delete all children of a grouping
+# - if delete leaves a node with no children, delete that, too
+# - what should be selected?
+#
+# Clear
+# - clears entire query
+# - clears it from the session, too
+
+# }}}
+
+
+1;

Added: rt/branches/3.4-RELEASE/lib/t/regression/03web_compiliation_errors.t
==============================================================================
--- (empty file)
+++ rt/branches/3.4-RELEASE/lib/t/regression/03web_compiliation_errors.t	Mon Mar 21 12:10:03 2005
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More qw/no_plan/;
+use WWW::Mechanize;
+use HTTP::Request::Common;
+use HTTP::Cookies;
+use LWP;
+use Encode;
+
+my $cookie_jar = HTTP::Cookies->new;
+my $agent = WWW::Mechanize->new();
+
+# give the agent a place to stash the cookies
+
+$agent->cookie_jar($cookie_jar);
+
+
+# get the top page
+my $url = "http://localhost".$RT::WebPath."/";
+$agent->get($url);
+
+is ($agent->{'status'}, 200, "Loaded a page");
+
+
+# {{{ test a login
+
+# follow the link marked "Login"
+
+ok($agent->{form}->find_input('user'));
+
+ok($agent->{form}->find_input('pass'));
+ok ($agent->{'content'} =~ /username:/i);
+$agent->field( 'user' => 'root' );
+$agent->field( 'pass' => 'password' );
+# the field isn't named, so we have to click link 0
+$agent->click(0);
+is($agent->{'status'}, 200, "Fetched the page ok");
+ok( $agent->{'content'} =~ /Logout/i, "Found a logout link");
+
+
+use File::Find;
+find ( \&wanted , 'html/');
+
+sub wanted {
+        -f  && /\.html$/ && $_ !~ /Logout.html$/  && test_get($File::Find::name);
+}       
+
+sub test_get {
+        my $file = shift;
+
+
+        $file =~ s#^html/##; 
+        ok ($agent->get("$url/$file", "GET $url/$file"));
+        is ($agent->{'status'}, 200, "Loaded $file");
+#        ok( $agent->{'content'} =~ /Logout/i, "Found a logout link on $file ");
+        ok( $agent->{'content'} !~ /Not logged in/i, "Still logged in for  $file");
+        ok( $agent->{'content'} !~ /System error/i, "Didn't get a Mason compilation error on $file");
+        
+}
+
+# }}}
+
+1;

Modified: rt/branches/3.4-RELEASE/sbin/rt-test-dependencies.in
==============================================================================
--- rt/branches/3.4-RELEASE/sbin/rt-test-dependencies.in	(original)
+++ rt/branches/3.4-RELEASE/sbin/rt-test-dependencies.in	Mon Mar 21 12:10:03 2005
@@ -162,6 +162,8 @@
 Storable 2.08
 Apache::Session 1.53
 XML::RSS
+HTTP::Server::Simple 0.04
+HTTP::Server::Simple::Mason 0.04
 .
 
 $deps{'MAILGATE'} = [ _( << '.') ];


More information about the Rt-commit mailing list