[prev] [thread] [next] [lurker] [Date index for 2002/09/20]
Update of /cvsroot/siesta/siesta/t In directory usw-pr-cvs1:/tmp/cvs-serv4423/t Modified Files: 10plugin_subscribe.t Log Message: Subscribe now challenges the user with a unique number. Index: 10plugin_subscribe.t =================================================================== RCS file: /cvsroot/siesta/siesta/t/10plugin_subscribe.t,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- 10plugin_subscribe.t 15 Sep 2002 11:34:06 -0000 1.5 +++ 10plugin_subscribe.t 20 Sep 2002 13:29:39 -0000 1.6 @@ -1,6 +1,6 @@ #!perl -w use strict; -use Test::More tests => 4; +use Test::More tests => 11; use Test::MockObject; use Siesta::Plugin::Subscribe; @@ -8,26 +8,109 @@ Siesta->connect( DBI => "dbi:SQLite:t/test.db" ); my $plugin = Siesta::Plugin::Subscribe->new; -my $list = + +# set up the mock objects +my $reply; +my $subject = ""; +my $user = Test::MockObject->new->mock( id => sub { 'suzanne@lab' } ); +my $juser = Test::MockObject->new->mock( id => sub { 'jay@jail' } ); + +my $list = Test::MockObject->new->mock( id => sub { 'escapees' } ) ->mock( owner => sub { 'houdini@elsewhere' } ) - ->mock( add_member => sub { $_[1] eq 'suzanne@lab' } ); + ->mock( add_member => sub { $_[1] eq 'suzanne@lab' || $_[1] eq 'foo@bar' } ) + ->mock( members => sub { return ($juser) } ); + -my $reply; my $mail = Test::MockObject->new->mock( list => sub { $list } ) ->mock( from => sub { 'suzanne@lab' } ) + ->mock( user => sub { $user } ) + ->mock( subject => sub { shift; + my $nsubject = shift; + $subject = $nsubject if (defined $nsubject); + return $subject; + } ) ->mock( reply => sub { shift; $reply = {@_}->{body} } ); + +$mail ->mock( clone => sub { $mail } ); + + +# try an initial sub mail ok( $plugin->process($mail), "request handled" ); like( $reply, - qr/You have been successfully subscribed to escapees/, - "subscribed suzanne" ); + qr/You have requested to be subscribed to/, + "challenged suzanne" ); + + +# now try again +$subject = "FOO BAR"; +ok( $plugin->process($mail), "request handled" ); +like( $reply, + qr/You have requested to be subscribed to/, + "not fooled by repeated requests" ); + +# now try a fake subscriber key +my $tmp = $subject; # save the valid subscribers key +$subject = 'SUBSCRIBE foobar'; + +$plugin->process($mail); +like( $reply, + qr/The subscribe key you gave was invalid/, + "invalid key" ); + + +# try again with a valid key +$subject = $tmp; +$plugin->process($mail); +like( $reply, + qr/You have been successfully subscribed to/, + "valid key" ); + + + + + +# try faking with a previously valid key +$mail->mock( from => sub { 'foo@bar' } ); +$plugin->process($mail); + +like( $reply, + qr/The subscribe key you gave was invalid/, + "none existent key" ); + + +# try a previously subscribed user +$user = $juser; $mail->mock( from => sub { 'jay@jail' } ); -ok( $plugin->process($mail) ); + +$subject = 'Foo'; + +$plugin->process($mail); like( $reply, - qr/You could not be subscribed to escapees./, - "subscribing jay failed" ); + qr/Maybe you are already subscribed/, + "already subbed" ); + +# try an invalid user (only invalid cos we say it is) +$mail->mock( from => sub { 'bob@jail' } ); + +$subject = 'Bar'; + +$user = Test::MockObject->new()->mock( id => sub { 'bob@jail' } ); +$plugin->process($mail); +like($reply, + qr/You have requested to be subscribed to/, + "trying to sub bob"); + +# send it right back at them +ok($plugin->process($mail),"processed again"); + +like( $reply, + qr/Maybe you are already subscribed/, + "force failure" ); + + 1;
Generated at 13:57 on 01 Jul 2004 by mariachi 0.52