Skip to content

Commit

Permalink
Item13839: Validate, don't encode username
Browse files Browse the repository at this point in the history
Fix for 2.0.2 registration was too aggressive.
  • Loading branch information
gac410 committed Nov 4, 2015
1 parent 5da8166 commit f853dd1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
46 changes: 46 additions & 0 deletions UnitTestContrib/test/unit/ManageDotPmTests.pm
Expand Up @@ -641,6 +641,52 @@ sub test_NoUserAddToNewGroupCreate {
return;
}

sub test_InvalidUserAddToNewGroupCreate {
my $this = shift;
my $ret;

$ret = $this->addUserToGroup(
{
'username' => ['Bad<script>User'],
'groupname' => ['NewGroup'],
'create' => [1],
'action' => ['addUserToGroup']
}
);

$this->assert_equals( $ret->{status}, 500 );
$this->assert_equals( $ret->{def}, 'problem_adding_to_group' );
$this->assert_matches( qr/Invalid username/, $ret->{params}[0] );

#SMELL: TopicUserMapping specific - we don't refresh Groups cache :(
$this->assert(
Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" ) );

#need to reload to force Foswiki to reparse Groups :(
my $q = $this->{request};
$this->createNewFoswikiSession( undef, $q );

$this->assert(
Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" ) );

$ret = $this->addUserToGroup(
{
'username' => ['Us_aaUser'],
'groupname' => ['NewGroup'],
'create' => [1],
'action' => ['addUserToGroup']
}
);

#need to reload to force Foswiki to reparse Groups :(
$q = $this->{request};
$this->createNewFoswikiSession( undef, $q );

$this->assert( Foswiki::Func::isGroupMember( "NewGroup", 'Us_aaUser' ) );

return;
}

sub test_NoUserAddToNewGroupCreateAsAdmin {
my $this = shift;
my $ret;
Expand Down
14 changes: 9 additions & 5 deletions core/lib/Foswiki/UserMapping.pm
Expand Up @@ -566,11 +566,15 @@ sub validateRegistrationField {

return $_[2] if ( lc( $_[1] ) eq 'loginname' );

if ( ( lc( $_[1] ) eq 'username' )
&& length( $_[2] )
&& !( $_[2] =~ m/$Foswiki::cfg{LoginNameFilterIn}/ ) )
{
throw Error::Simple( Foswiki::entityEncode("Invalid $_[1]") );
if ( lc( $_[1] ) eq 'username' ) {
if ( length( $_[2] )
&& !( $_[2] =~ m/$Foswiki::cfg{LoginNameFilterIn}/ ) )
{
throw Error::Simple( Foswiki::entityEncode("Invalid $_[1]") );
}
else {
return $_[2];
}
}

# Don't check contents of password - it's never displayed.
Expand Down

0 comments on commit f853dd1

Please sign in to comment.