← Back to team overview

mvhub-dev team mailing list archive

[Merge] lp:~omacneil/mvhub/fix_password_test into lp:mvhub

 

Dan MacNeil has proposed merging lp:~omacneil/mvhub/fix_password_test into lp:mvhub.

Requested reviews:
  MVHub devs with commit rights (mvhub-commit)


Added code to die in a more friendly, informative way if tmp_dir can't be written to when setting up sessions
-- 
https://code.launchpad.net/~omacneil/mvhub/fix_password_test/+merge/29180
Your team MVHub Developers is subscribed to branch lp:mvhub.
=== modified file 'app-mvhub/t/mech/user/login_with_good_password.t'
--- app-mvhub/t/mech/user/login_with_good_password.t	2010-05-26 18:32:04 +0000
+++ app-mvhub/t/mech/user/login_with_good_password.t	2010-07-04 23:25:41 +0000
@@ -7,10 +7,6 @@
 use Test::More;
 use Test::WWW::Mechanize;
 
-BEGIN {
-    use FindBin qw($Bin);
-    chdir $Bin;
-}
 use TestHelper;
 
 {    #main

=== modified file 'lib-mvhub/lib/MVHub/AgencyAccount.pm'
--- lib-mvhub/lib/MVHub/AgencyAccount.pm	2010-05-24 19:44:00 +0000
+++ lib-mvhub/lib/MVHub/AgencyAccount.pm	2010-07-04 23:25:41 +0000
@@ -92,7 +92,7 @@
     my $caller_id    = $self->param('caller_id');
 
     # If it's an admin, they probably don't want the pretty, space-wasting GUI
-    # However, we need some additional HTML tags, and the javascript
+    # However, we neeFd some additional HTML tags, and the javascript
     if ( defined $caller_id && $caller_id == $MVHub::Common::ADMIN_ID ) {
         my $js = $JAVASCRIPT_BY_MODE{$calling_mode} || '';
         my $page_body = $$output_ref;
@@ -435,14 +435,12 @@
     my $quick_login_id = $cgi->param('id');
 
     my $agency_id = decode_quick_login_id($quick_login_id);
-
     if ( int($agency_id) == $agency_id ) {
 
         my $cookie
             = MVHub::AuthAccount::init_session( caller_id => $agency_id );
         $self->header_add( -cookie => $cookie );
         $self->redirect( cgi_params_href => { rm => 'display_agency_home' } );
-
         return
             "Login successful - redirecting to agency $agency_id home page";
 

=== modified file 'lib-mvhub/lib/MVHub/AuthAccount.pm'
--- lib-mvhub/lib/MVHub/AuthAccount.pm	2010-06-23 15:59:27 +0000
+++ lib-mvhub/lib/MVHub/AuthAccount.pm	2010-07-04 23:25:41 +0000
@@ -6,6 +6,8 @@
 
 use MVHub::Utils;
 use MVHub::Utils::ConfigSimple qw/create_config_from/;
+use Params::Validate;
+use Carp;
 
 our ($VERSION) = '$Revision: 1146 $' =~ /([.\d]+)/;
 
@@ -19,6 +21,7 @@
 my $ADMIN_ID         = $CFG->param('CONSTANTS.admin_id');
 our @EXPORT_OK = qw(
     authenticate_session
+    _die_loudly_if_dir_not_writable
     init_session
 );
 
@@ -144,6 +147,23 @@
     }
 }
 
+sub _die_loudly_if_dir_not_writable {
+    Params::Validate::validate_pos( @_, 1 );
+    my $dir = shift;
+
+    my $writeable = -d $dir && -W $dir;
+    use English '-no_match_vars';
+    my $process_ownername = getpwuid($EFFECTIVE_USER_ID);
+
+    if ( !$writeable ) {
+
+        # extra carp  to avoid msg being truncated
+        carp "not dir or writable: $dir \n";
+        carp "apache runs as $process_ownername\n";
+        croak "$process_ownername can't write to: $dir\n";
+    }
+}
+
 # Returns a session object as follows:
 # If you pass in no session id, returns a new session object.
 # If you pass in a valid session id, returns its corresponding session object.
@@ -151,7 +171,8 @@
 sub _produce_session {
     my $session_id = shift;
 
-    # TODO put location of sessions dir in config file
+    _die_loudly_if_dir_not_writable($TMP_DIR);
+
     my $session = new CGI::Session( "driver:File", $session_id,
         { Directory => $TMP_DIR } );
 

=== added directory 'lib-mvhub/t/AuthAccount'
=== added file 'lib-mvhub/t/AuthAccount/_die_loudly_if_dir_not_writable.t'
--- lib-mvhub/t/AuthAccount/_die_loudly_if_dir_not_writable.t	1970-01-01 00:00:00 +0000
+++ lib-mvhub/t/AuthAccount/_die_loudly_if_dir_not_writable.t	2010-07-04 23:25:41 +0000
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+# $Source$
+# $Revision: 1209 $
+
+use strict;
+use warnings;
+
+# EDIT
+use Test::More tests => 3 + 1;    # +1 for NoWarnings
+use Test::Exception;
+use Test::NoWarnings;
+
+use MVHub::AuthAccount qw/
+    _die_loudly_if_dir_not_writable
+    /;
+
+my $test_message;
+
+$test_message = 'die if file not dir';
+dies_ok { _die_loudly_if_dir_not_writable('bin/sh') } $test_message;
+
+$test_message = 'die if dir not writable';
+dies_ok { _die_loudly_if_dir_not_writable('/dev') } $test_message;
+
+$test_message = 'lives if dir and writable';
+lives_ok { MVHub::AuthAccount::_die_loudly_if_dir_not_writable('/tmp/') }
+$test_message;
+
+__END__


Follow ups