Skip to content

Commit

Permalink
Item12323: Use Meta to trash spammer,
Browse files Browse the repository at this point in the history
Check to make sure topic does not exist in tests.

Unit tests were undefining the wrong cache variables

Mailinator changed their address.

git-svn-id: http://svn.foswiki.org/trunk/AntiWikiSpamPlugin@16319 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Dec 31, 2012
1 parent 67dc0c9 commit 76c44a0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
3 changes: 2 additions & 1 deletion data/System/AntiWikiSpamPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ To cause a true failure, remove the VIEW and CHANGE restrictions to the topic an
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 1.5 (15 Dec 2012) | Foswikitask:Item12296: !BypassGroup doesn't work, also unit tests don't work on trunk. |
| 1.5 (31 Dec 2012) | Foswikitask:Item12296: !BypassGroup doesn't work, also unit tests don't work on trunk.%BR%\
Foswikitask:Item12323: Fails to remove user topic on Foswiki 1.1.x |
| 1.4 (10 Aug 2012) | Foswikitask:Item11679: When removing a user, remove it from any groups.<br />\
Foswikitask:Item12038: Allow checking to be disabled |
| 1.3.1 (19 Mar 2012) | Remove dialog would remove current user if entered user was not konwn to the Mapper. |
Expand Down
1 change: 1 addition & 0 deletions data/System/AntiWikiSpamRegistrationBlackList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ escape full-stops in regular expressions!

<verbatim>
^76\.74\.239\.26$ # mailinator.com
^72\.51\.33\.80$ # another mailinator
</verbatim>

* Set ALLOWTOPICVIEW = %USERSWEB%.AdminGroup
Expand Down
31 changes: 14 additions & 17 deletions lib/Foswiki/Plugins/AntiWikiSpamPlugin/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ sub validateRegistrationHandler {
}
print STDERR "white: $white black: $black\n" if MONITOR;
unless ( $white && !$black ) {
print STDERR "REJECTED\n" if MONITOR;
$Foswiki::Plugins::SESSION->logger->log( 'warning',
"Registration of $data->{WikiName} ($data->{Email}) rejected by AntiWikiSpamPlugin: white: $white black: $black"
);
Expand Down Expand Up @@ -485,27 +486,23 @@ sub _removeUser {
( my $web, $wikiname ) =
Foswiki::Func::normalizeWebTopicName( $Foswiki::cfg{UsersWebName},
$wikiname );
if ( Foswiki::Func::topicExists( $web, $wikiname ) ) {

# Spoof the user so we can delete their topic. Don't need to
# do this for the REST handler, but we do for the registration
# abort.
my $safe = $Foswiki::Plugins::SESSION->{user};
if ( Foswiki::Func::topicExists( $web, $wikiname ) ) {

my $newTopic = "SuspectSpammer$wikiname" . time;
try {
Foswiki::Func::moveTopic( $web, $wikiname,
$Foswiki::cfg{TrashWebName}, $newTopic );
$message .=
" - user topic moved to $Foswiki::cfg{TrashWebName}.$newTopic <br/>";
$logMessage .=
"User topic moved to $Foswiki::cfg{TrashWebName}.$newTopic, ";
}
finally {

# Restore the original user
$Foswiki::Plugins::SESSION->{user} = $safe;
};
my $from =
Foswiki::Meta->new( $Foswiki::Plugins::SESSION, $web, $wikiname );
my $to =
Foswiki::Meta->new( $Foswiki::Plugins::SESSION,
$Foswiki::cfg{TrashWebName}, $newTopic );

$from->move($to);

$message .=
" - user topic moved to $Foswiki::cfg{TrashWebName}.$newTopic <br/>";
$logMessage .=
"User topic moved to $Foswiki::cfg{TrashWebName}.$newTopic, ";
}
else {
$message .= " - user topic not found <br/>";
Expand Down
32 changes: 28 additions & 4 deletions test/unit/AntiWikiSpamPlugin/AntiWikiSpamPluginRegTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ sub set_up {
$Foswiki::cfg{Plugins}{AntiWikiSpamPlugin}{CheckRegistrations} = 1;
$Foswiki::cfg{Register}{NeedVerification} = 0;
$Foswiki::cfg{Plugins}{AntiWikiSpamPlugin}{ANTISPAMREGEXLISTURL} = '';
undef $Foswiki::Plugins::AntiWikiSpamPlugin::regoWhite;
undef $Foswiki::Plugins::AntiWikiSpamPlugin::regoBlack;
undef $Foswiki::Plugins::AntiWikiSpamPlugin::Core::regoWhite;
undef $Foswiki::Plugins::AntiWikiSpamPlugin::Core::regoBlack;
}

sub tear_down {
my $this = shift;
$this->SUPER::tear_down();
undef $Foswiki::Plugins::AntiWikiSpamPlugin::regoWhite;
undef $Foswiki::Plugins::AntiWikiSpamPlugin::regoBlack;
undef $Foswiki::Plugins::AntiWikiSpamPlugin::Core::regoWhite;
undef $Foswiki::Plugins::AntiWikiSpamPlugin::Core::regoBlack;
}

# Test removeUser REST handler
Expand Down Expand Up @@ -178,6 +178,12 @@ TEXT
otherwise {
$this->assert( 0, 'SPAM Registration was permitted' );
};
$this->assert(
!Foswiki::Func::topicExists(
$Foswiki::cfg{UsersWebName},
'MustaphaGoody'
)
);

# matches whitelist, matches blacklist
$qd->{Fwk1Email} = ['mustapha@badrobot.org'];
Expand All @@ -201,6 +207,12 @@ TEXT
otherwise {
$this->assert(0);
};
$this->assert(
!Foswiki::Func::topicExists(
$Foswiki::cfg{UsersWebName},
'MustaphaGoody'
)
);

# matches whitelist, matches IP in blacklist
$qd->{Fwk1Email} = ['mustapha@safetymail.info'];
Expand All @@ -224,6 +236,12 @@ TEXT
otherwise {
$this->assert(0);
};
$this->assert(
!Foswiki::Func::topicExists(
$Foswiki::cfg{UsersWebName},
'MustaphaGoody'
)
);

# matches whitelist, does not match blacklist => good rego
$qd->{Fwk1Email} = ['mustapha@mustapha.good.time.info'];
Expand All @@ -249,6 +267,12 @@ qr/A confirmation e-mail has been sent to mustapha\@mustapha.good.time.info/,
otherwise {
$this->assert(0);
};
$this->assert(
Foswiki::Func::topicExists(
$Foswiki::cfg{UsersWebName},
'MustaphaGoody'
)
);
}

1;
3 changes: 1 addition & 2 deletions test/unit/AntiWikiSpamPlugin/AntiWikiSpamPluginTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sub tear_down {
}

#SMELL: Enabling this test breaks the AntiWikiSpamPluginRegTests ???
sub disable_test_spamSaveTopic {
sub test_spamSaveTopic {
my $this = shift;

my ( $meta, $text );
Expand Down Expand Up @@ -81,7 +81,6 @@ TEXT
};

$text = Foswiki::Func::readTopicText( $this->{test_web}, 'SpamTopic' );
print STDERR "Read $text\n";

}

Expand Down

0 comments on commit 76c44a0

Please sign in to comment.