[prev] [thread] [next] [lurker] [Date index for 2003/11/24]
Author: gabor
Date: 2003-11-24 14:49:16 +0200 (Mon, 24 Nov 2003)
New Revision: 14
Added:
t/09-web-change-password.t
templates/change_password.tmpl
templates/message.tmpl
Log:
add interface for users to change their password missing files
Added: t/09-web-change-password.t
===================================================================
--- t/09-web-change-password.t 2003-11-24 10:41:33 UTC (rev 13)
+++ t/09-web-change-password.t 2003-11-24 12:49:16 UTC (rev 14)
@@ -0,0 +1,135 @@
+#!/usr/bin/perl
+# -T
+
+# Testing how can a user change the password
+# using the web interface
+
+
+use strict;
+use warnings;
+use Test::More qw(no_plan);
+use lib qw(lib);
+use lib qw(t/lib);
+use YAPC::Test 'init_db';
+use YAPC::Test::Data;
+
+use YAPC::Person;
+use CGI; # needed for some of the tests
+
+$ENV{CGI_APP_RETURN_ONLY} = 1; # to eliminate screen output
+
+# to avoid warning caused my lack of web server in the test environment
+$ENV{HTTP_HOST} = 'test-host';
+# $ENV{REQUEST_URI} = 'test-uri'; #should be set for each request as we are using it
+$ENV{YAPCOM_NOMAIL} = 1;
+$ENV{REQUEST_URI} = '/';
+
+BEGIN { use_ok( 'YAPC::Organizer' ); }
+
+###### prepare the environment: create and validate users and make them login
+my @cookies;
+
+YAPC::Test::Data::register_user(0);
+YAPC::Test::Data::register_user(1);
+push @cookies, YAPC::Test::Data::login_user(0);
+push @cookies, YAPC::Test::Data::login_user(0);
+push @cookies, YAPC::Test::Data::login_user(1);
+isnt($cookies[0], $cookies[1], 'cookies are different');
+isnt($cookies[0], $cookies[2], 'cookies are different');
+isnt($cookies[1], $cookies[2], 'cookies are different');
+
+# access the change password page fails if not authenticated
+{
+ local $ENV{REQUEST_URI} = '/change_password.html';
+ #local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
+ my $q = CGI->new();
+ my $webapp = YAPC::Organizer->new;
+ $webapp->query($q);
+ my $result = $webapp->run();
+ like($result, qr@<h2>Login</h2>@, 'Redirected to login page');
+}
+
+# update password failes if not authenticated
+# redirect to login page and do not touch database
+{
+ #local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
+ my $q = CGI->new(
+ {
+ password => 'somenewpw',
+ password2 => 'somenewpw',
+ run => 'change_password'
+ });
+ my $webapp = YAPC::Organizer->new;
+ $webapp->query($q);
+ my $result = $webapp->run();
+ like($result, qr@<h2>Login</h2>@, 'Redirected to login page');
+ my @ppl = YAPC::Person->search(password => 'somenewpw');
+ is(@ppl, 0, 'No entry was set in the database to the new password');
+ @ppl = YAPC::Person->search(password => 'nopassword');
+ my @all = YAPC::Person->retrieve_all();
+ is(@ppl, @all, 'Non of the passwords were changed.');
+}
+
+
+
+# fetch form by authenticated user
+{
+ local $ENV{REQUEST_URI} = '/change_password.html';
+ local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
+ my $q = CGI->new();
+ my $webapp = YAPC::Organizer->new;
+ $webapp->query($q);
+ my $result = $webapp->run();
+ like($result, qr@<h2>Change Password Form</h2>@, 'Display change password form');
+}
+
+
+
+# submit form with bad passwords should yield an error message
+# and database should not change
+{
+ local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
+ my $q = CGI->new(
+ {
+ password => 'somenewpw',
+ password2 => 'somenewpwx',
+ run => 'change_password'
+ });
+ my $webapp = YAPC::Organizer->new;
+ $webapp->query($q);
+ my $result = $webapp->run();
+ like($result, qr@<h2>Change Password Form</h2>@, 'Get back the password form');
+ like($result, qr@Error@, 'Get error message');
+ my @ppl = YAPC::Person->search(password => 'somenewpw');
+ is(@ppl, 0, 'No entry was set in the database to the new password');
+ @ppl = YAPC::Person->search(password => 'nopassword');
+ my @all = YAPC::Person->retrieve_all();
+ is(@ppl, @all, 'Non of the passwords were changed.');
+}
+
+
+
+# submit form with good password should yield a success message
+# database should be updated.
+{
+ local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
+ my $q = CGI->new(
+ {
+ password => 'somenewpw',
+ password2 => 'somenewpw',
+ run => 'change_password'
+ });
+ my $webapp = YAPC::Organizer->new;
+ $webapp->query($q);
+ my $result = $webapp->run();
+ like($result, qr@Your password has been successfully updated@, 'Success message');
+ my @ppl = YAPC::Person->search(password => 'somenewpw');
+ is(@ppl, 1, 'One password was set to the new password in the database');
+ @ppl = YAPC::Person->search(password => 'nopassword');
+ my @all = YAPC::Person->retrieve_all();
+ is(@ppl, @all-1, 'Non of the other passwords were changed.');
+}
+
+
+
+
Property changes on: t/09-web-change-password.t
___________________________________________________________________
Name: svn:executable
+ *
Added: templates/change_password.tmpl
===================================================================
--- templates/change_password.tmpl 2003-11-24 10:41:33 UTC (rev 13)
+++ templates/change_password.tmpl 2003-11-24 12:49:16 UTC (rev 14)
@@ -0,0 +1,27 @@
+<TMPL_VALUE NAME="title" VALUE="Change Password Form">
+<TMPL_INCLUDE NAME="header.tmpl">
+ <td valign="top">
+
+<p>
+<font color="red"><TMPL_VAR NAME="MESSAGE"></font>
+<p>
+<form method="post">
+<input type="hidden" name="run" value="change_password" />
+<table>
+<tr><td>New Password:</td><td><input size=40 name="password" type="password" /></td></tr>
+<tr><td>Retype new Password:</td><td><input size=40 name="password2" type="password" /></td></tr>
+<tr><td></td><td><input type="submit" value="Change password"></td></tr>
+</table>
+</form>
+
+ <br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br />
+ <hr />
+
+ <p class="bottomtext">
+ Please send comments, questions etc. to
+ <a href="mailto:yapc-organizers@xxxx.xxx.xx">yapc-organizers@xxxx.xxx.xx</a>
+ </p>
+
+ </td>
+<TMPL_INCLUDE NAME="footer.tmpl">
+
Added: templates/message.tmpl
===================================================================
--- templates/message.tmpl 2003-11-24 10:41:33 UTC (rev 13)
+++ templates/message.tmpl 2003-11-24 12:49:16 UTC (rev 14)
@@ -0,0 +1,18 @@
+<TMPL_VALUE NAME="title" VALUE="Respons page">
+<TMPL_INCLUDE NAME="header.tmpl">
+ <td valign="top">
+
+<TMPL_IF NAME="password_changed">
+Your password has been successfully updated.
+</TMPL_IF>
+ <br /> <br /><br /> <br /><br /> <br /><br /> <br /><br /> <br />
+ <hr />
+
+ <p class="bottomtext">
+ Please send comments, questions etc. to
+ <a href="mailto:yapc-organizers@xxxx.xxx.xx">yapc-organizers@xxxx.xxx.xx</a>
+ </p>
+
+ </td>
+<TMPL_INCLUDE NAME="footer.tmpl">
+
Generated at 15:06 on 24 Nov 2003 by mariachi 0.51