Skip to content

Commit

Permalink
Merge branch 'Release02x01'
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Nov 10, 2016
2 parents 5d1f44f + b8bad3e commit c124831
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
98 changes: 98 additions & 0 deletions UnitTestContrib/test/unit/RegisterTests.pm
Expand Up @@ -949,6 +949,104 @@ sub verify_rejectShortPassword {
return;
}

# Register a user with a required field set to zero. - Item14071
sub verify_rejectItem14071 {
my $this = shift;
$Foswiki::cfg{Register}{NeedVerification} = 0;
$Foswiki::cfg{MinPasswordLength} = 6;
$Foswiki::cfg{PasswordManager} = 'Foswiki::Users::HtPasswdUser';
$Foswiki::cfg{Register}{AllowLoginName} = 0;
my $query = Unit::Request->new(
{
'TopicName' => ['UserRegistration'],
'Twk1Email' => [ $this->{new_user_email} ],
'Twk1WikiName' => [ $this->{new_user_wikiname} ],
'Twk1Name' => [ $this->{new_user_fullname} ],
'Twk1Comment' => [''],

# 'Twk1LoginName' => [$this->{new_user_login}],
'Twk1FirstName' => [ $this->{new_user_fname} ],
'Twk1LastName' => [ $this->{new_user_sname} ],
'Twk1Password' => ['asdfasdf'],
'Twk1Confirm' => ['asdfasdf'],
'action' => ['register'],
}
);

$query->path_info("/$this->{users_web}/UserRegistration");
$this->createNewFoswikiSession( $Foswiki::cfg{DefaultUserLogin}, $query );
$this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail );

try {
$this->captureWithKey( register => $REG_UI_FN, $this->{session} );
}
catch Foswiki::OopsException with {
my $e = shift;
$this->assert_str_equals( 'attention', $e->{template},
$e->stringify() );
$this->assert_str_equals( "missing_fields", $e->{def},
$e->stringify() );
$this->assert_matches( 'Comment', $e->{params}->[0], $e->stringify() );
}
catch Foswiki::AccessControlException with {
my $e = shift;
$this->assert( 0, $e->stringify );
}
catch Error::Simple with {
$this->assert( 0, shift->stringify() );
}
otherwise {
$this->assert( 0, "expected an oops redirect" );
};

$query = Unit::Request->new(
{
'TopicName' => ['UserRegistration'],
'Twk1Email' => [ $this->{new_user_email} ],
'Twk1WikiName' => [ $this->{new_user_wikiname} ],
'Twk1Name' => [ $this->{new_user_fullname} ],
'Twk1Comment' => ['0'],

# 'Twk1LoginName' => [$this->{new_user_login}],
'Twk1FirstName' => [ $this->{new_user_fname} ],
'Twk1LastName' => [ $this->{new_user_sname} ],
'Twk1Password' => ['asdfasdf'],
'Twk1Confirm' => ['asdfasdf'],
'action' => ['register'],
}
);

$query->path_info("/$this->{users_web}/UserRegistration");
$this->createNewFoswikiSession( $Foswiki::cfg{DefaultUserLogin}, $query );
$this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail );

try {
$this->captureWithKey( register => $REG_UI_FN, $this->{session} );
}
catch Foswiki::OopsException with {
my $e = shift;
$this->assert_str_equals( $REG_TMPL, $e->{template}, $e->stringify() );
$this->assert_str_equals( "thanks", $e->{def}, $e->stringify() );
$this->assert_matches(
$this->{new_user_email},
$e->{params}->[0],
$e->stringify()
);
}
catch Foswiki::AccessControlException with {
my $e = shift;
$this->assert( 0, $e->stringify );
}
catch Error::Simple with {
$this->assert( 0, shift->stringify() );
}
otherwise {
$this->assert( 0, "expected an oops redirect" );
};

return;
}

# Register a user with an invalid template topic - must be rejected
sub verify_userTopictemplate {
my $this = shift;
Expand Down
4 changes: 3 additions & 1 deletion core/lib/Foswiki/UI/Register.pm
Expand Up @@ -1924,7 +1924,9 @@ sub _validateRegistration {
my @missing = ();
foreach my $fd ( sort { $a->{name} cmp $b->{name} } @{ $data->{form} } )
{
if ( ( $fd->{required} ) && ( !$fd->{value} ) ) {
if ( ( $fd->{required} )
&& ( !defined $fd->{value} || length( $fd->{value} ) == 0 ) )
{
push( @missing, $fd->{name} );
}
}
Expand Down

0 comments on commit c124831

Please sign in to comment.