User: sits
Date: 08/09/06 20:44:15
Added: t/Http/Method login.t authenticate.t
lib/Codestriker/Http/Method LoginMethod.pm
AuthenticateMethod.pm
Log:
New methods for handling the login form, and actual authentication.
Index: login.t
===================================================================
RCS file: login.t
diff -N login.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ login.t 7 Sep 2008 03:44:15 -0000 1.1
@@ -0,0 +1,41 @@
+# Tests for the Login method.
+
+use strict;
+use Test::More tests => 4;
+
+use lib '../../../lib';
+use Test::MockObject;
+use Codestriker;
+use Codestriker::Http::Method::LoginMethod;
+
+# Create a CGI mock object for these tests.
+my $mock_query = Test::MockObject->new();
+$mock_query->mock('url',
+ sub { 'http://localhost.localdomain/codestriker/codestriker.pl'
} );
+
+# Create two method objects to test each URL scheme.
+my $url_cgi = Codestriker::Http::Method::LoginMethod->new($mock_query, 1);
+my $url_nice = Codestriker::Http::Method::LoginMethod->new($mock_query, 0);
+
+is($url_cgi->url(feedback => 'Incorrect password',
+ redirect => 'http://zot.com/zot.pl?action=blah¶m=10'),
+ $mock_query->url() .
'?action=login&redirect=http%3A%2F%2Fzot.com%2Fzot.pl%3Faction%3Dblah%26param%3D10&feedback=Incorrect%20password',
+ "Login URL CGI syntax");
+
+is($url_nice->url(feedback => 'Incorrect password',
+ redirect => 'http://zot.com/zot.pl?action=blah¶m=10'),
+ $mock_query->url() .
'/login/form/redirect/http%3A%2F%2Fzot.com%2Fzot.pl%3Faction%3Dblah%26param%3D10/feedback/Incorrect%20password',
+ "Login URL nice syntax");
+
+# Check that the parameters extracted correctly.
+my $mock_http_input = Test::MockObject->new();
+$mock_http_input->{query} = $mock_query;
+$mock_http_input->mock('extract_cgi_parameters', sub { return undef; });
+$mock_query->mock('path_info',
+ sub {
+ return
'/login/form/redirect/http%3A%2F%2Fzot.com%2Fzot.pl%3Faction%3Dblah%26param%3D10/feedback/Incorrect%20password';
+ });
+$mock_query->mock('param', sub { return undef; });
+$url_nice->extract_parameters($mock_http_input);
+is ($mock_http_input->{redirect},
'http://zot.com/zot.pl?action=blah¶m=10', "redirect nice URL parameter
extraction");
+is ($mock_http_input->{feedback}, 'Incorrect password', "feedback nice URL
parameter extraction");
Index: authenticate.t
===================================================================
RCS file: authenticate.t
diff -N authenticate.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ authenticate.t 7 Sep 2008 03:44:15 -0000 1.1
@@ -0,0 +1,23 @@
+# Tests for the Authenticate method.
+
+use strict;
+use Test::More tests => 2;
+
+use lib '../../../lib';
+use Test::MockObject;
+use Codestriker;
+use Codestriker::Http::Method::AuthenticateMethod;
+
+# Create a CGI mock object for these tests.
+my $mock_query = Test::MockObject->new();
+$mock_query->mock('url',
+ sub { 'http://localhost.localdomain/codestriker/codestriker.pl'
} );
+
+# Create two method objects to test each URL scheme.
+my $url_cgi =
Codestriker::Http::Method::AuthenticateMethod->new($mock_query, 1);
+my $url_nice =
Codestriker::Http::Method::AuthenticateMethod->new($mock_query, 0);
+
+is($url_cgi->url(), $mock_query->url() . '?action=authenticate',
+ "Authenticate URL CGI syntax");
+is($url_nice->url(), $mock_query->url() . '/login/authenticate',
+ "Authenticate URL nice syntax");
Index: LoginMethod.pm
===================================================================
RCS file: LoginMethod.pm
diff -N LoginMethod.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LoginMethod.pm 7 Sep 2008 03:44:15 -0000 1.1
@@ -0,0 +1,56 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# [EMAIL PROTECTED]
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Method for going to the login form.
+
+package Codestriker::Http::Method::LoginMethod;
+
+use strict;
+use Codestriker::Http::Method;
+
[EMAIL PROTECTED]::Http::Method::LoginMethod::ISA =
("Codestriker::Http::Method");
+
+# Generate a URL for this method.
+sub url() {
+ my ($self, %args) = @_;
+
+ if ($self->{cgi_style}) {
+ return $self->{url_prefix} . "?action=login" .
+ (defined $args{redirect} ? "&redirect=" .
CGI::escape($args{redirect}) : "") .
+ (defined $args{feedback} ? "&feedback=" .
CGI::escape($args{feedback}) : "");
+ } else {
+ return $self->{url_prefix} . "/login/form" .
+ (defined $args{redirect} ? "/redirect/" .
CGI::escape($args{redirect}) : "") .
+ (defined $args{feedback} ? "/feedback/" .
CGI::escape($args{feedback}) : "");
+ }
+}
+
+sub extract_parameters {
+ my ($self, $http_input) = @_;
+
+ my $action = $http_input->{query}->param('action');
+ my $path_info = $http_input->{query}->path_info();
+ if ($self->{cgi_style} && defined $action && $action eq "login") {
+ $http_input->extract_cgi_parameters();
+ return 1;
+ } elsif ($path_info =~ m{^/login/form}) {
+ $self->_extract_nice_parameters($http_input,
+ redirect => 'redirect',
+ feedback => 'feedback');
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub execute {
+ my ($self, $http_input, $http_output) = @_;
+
+ Codestriker::Action::LoginAction->process($http_input, $http_output);
+}
+
+1;
Index: AuthenticateMethod.pm
===================================================================
RCS file: AuthenticateMethod.pm
diff -N AuthenticateMethod.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AuthenticateMethod.pm 7 Sep 2008 03:44:15 -0000 1.1
@@ -0,0 +1,50 @@
+###############################################################################
+# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
+# [EMAIL PROTECTED]
+#
+# This program is free software; you can redistribute it and modify it under
+# the terms of the GPL.
+
+# Method for authenticating a user.
+
+package Codestriker::Http::Method::AuthenticateMethod;
+
+use strict;
+use Codestriker::Http::Method;
+
[EMAIL PROTECTED]::Http::Method::AuthenticateMethod::ISA =
("Codestriker::Http::Method");
+
+# Generate a URL for this method.
+sub url() {
+ my ($self, %args) = @_;
+
+ if ($self->{cgi_style}) {
+ return $self->{url_prefix} . "?action=authenticate";
+ } else {
+ return $self->{url_prefix} . "/login/authenticate";
+ }
+}
+
+sub extract_parameters {
+ my ($self, $http_input) = @_;
+
+ my $action = $http_input->{query}->param('action');
+ my $path_info = $http_input->{query}->path_info();
+ if ($self->{cgi_style} && defined $action && $action eq "authenticate") {
+ $http_input->extract_cgi_parameters();
+ return 1;
+ } elsif ($path_info =~ m{^/login/authenticate}) {
+ $self->_extract_nice_parameters($http_input);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+sub execute {
+ my ($self, $http_input, $http_output) = @_;
+
+ Codestriker::Action::AuthenticateAction->process($http_input,
$http_output);
+}
+
+1;
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits