Skip to content

Commit

Permalink
Item13897: PasswordTests and PluginHandlersTests are completed.
Browse files Browse the repository at this point in the history
Big change: Foswiki::Users doesn't call plugins->load() anymore as it
doesn't look like a good idea.

- Added 'presets' concept to the preferences. It is a possibility to set
some session preferences before the main stack is ready – i.e. before the
application completed it's initialization stage. Can be used by plugins in
earlyInitHandler(). Foswiki::Prefs::setSessionsPreferences() method uses
presets if called before the main stack is ready.

Presets are load the app object right after loadDefaultPreferences() method
finishes.

Currently used to keep TWikiCompatibilityPlugin happy. Experimental.

- Foswiki::Engine::Test::user attribute can now be set from
initialAttributes parameter with user or remote_user keys; and
FOSWIKI_TEST_[REMOTE_]_USER environment variables. 'user' form has
precedence over 'remote_user' though both forms are there for mere
convinience.

- TestRunner now sets $| to 1 before starting a tester. Previously it was
tricky job to identify where error output comes from.

- FoswikiFnTestCase::tear_down is now checking if configuration key
UsersWebName isn't equal to 'Main'.

- A LOT of bugfixes.
  • Loading branch information
vrurg committed Jun 11, 2016
1 parent ad1bedc commit a6c1ab8
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 226 deletions.
Expand Up @@ -55,8 +55,9 @@ This may not be enough for Plugins that do have in topic preferences.

sub earlyInitPlugin {

my $session = $Foswiki::Plugins::SESSION;
_patchWebTopic( $session->{webName}, $session->{topicName} );
my $app = $Foswiki::app;
my $req = $app->request;
_patchWebTopic( $req->web, $req->topic );

#Map TWIKIWEB to SYSTEMWEB and MAINWEB to USERSWEB
#TODO: should we test for existance and other things?
Expand Down
7 changes: 7 additions & 0 deletions UnitTestContrib/lib/Foswiki/Engine/Test.pm
Expand Up @@ -143,6 +143,13 @@ around _prepareHeaders => sub {
return $headers;
};

around _prepareUser => sub {
my $orig = shift;
my $this = shift;
my $initHash = $this->initFromEnv(qw(user remote_user));
return $initHash->{user} // $initHash->{remote_user};
};

sub setUrl {
my $this = shift;
my ($queryString) = @_;
Expand Down
1 change: 1 addition & 0 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -605,6 +605,7 @@ sub runOne {
print "SKIP\t$test - $skip\n";
}
else {
local $| = 1;
Devel::Leak::Object::checkpoint() if CHECKLEAK;
print "\t$test\n";
$action .= "\n# $test\n ";
Expand Down
38 changes: 21 additions & 17 deletions UnitTestContrib/test/unit/FoswikiFnTestCase.pm
Expand Up @@ -89,28 +89,30 @@ around loadExtraConfig => sub {

$orig->( $this, @_ );

#$Foswiki::cfg{Store}{Implementation} = "Foswiki::Store::RcsLite";
$Foswiki::cfg{Store}{Implementation} = "Foswiki::Store::PlainFile";
$Foswiki::cfg{RCS}{AutoAttachPubFiles} = 0;
my $cfgData = $this->app->cfg->data;

$Foswiki::cfg{Register}{AllowLoginName} = 1;
$Foswiki::cfg{Htpasswd}{FileName} = "$Foswiki::cfg{WorkingDir}/htpasswd";
unless ( -e $Foswiki::cfg{Htpasswd}{FileName} ) {
#$cfgData->{Store}{Implementation} = "Foswiki::Store::RcsLite";
$cfgData->{Store}{Implementation} = "Foswiki::Store::PlainFile";
$cfgData->{RCS}{AutoAttachPubFiles} = 0;

$cfgData->{Register}{AllowLoginName} = 1;
$cfgData->{Htpasswd}{FileName} = $cfgData->{WorkingDir} . "/htpasswd";
unless ( -e $cfgData->{Htpasswd}{FileName} ) {
my $fh;
open( $fh, ">:encoding(utf-8)", $Foswiki::cfg{Htpasswd}{FileName} )
open( $fh, ">:encoding(utf-8)", $cfgData->{Htpasswd}{FileName} )
|| die $!;
close($fh) || die $!;
}
$Foswiki::cfg{PasswordManager} = 'Foswiki::Users::HtPasswdUser';
$Foswiki::cfg{Htpasswd}{GlobalCache} = 0;
$Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::TopicUserMapping';
$Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin';
$Foswiki::cfg{Register}{EnableNewUserRegistration} = 1;
$Foswiki::cfg{RenderLoggedInButUnknownUsers} = 0;

$Foswiki::cfg{Register}{NeedVerification} = 0;
$Foswiki::cfg{MinPasswordLength} = 0;
$Foswiki::cfg{UsersWebName} = $this->users_web;
$cfgData->{PasswordManager} = 'Foswiki::Users::HtPasswdUser';
$cfgData->{Htpasswd}{GlobalCache} = 0;
$cfgData->{UserMappingManager} = 'Foswiki::Users::TopicUserMapping';
$cfgData->{LoginManager} = 'Foswiki::LoginManager::TemplateLogin';
$cfgData->{Register}{EnableNewUserRegistration} = 1;
$cfgData->{RenderLoggedInButUnknownUsers} = 0;

$cfgData->{Register}{NeedVerification} = 0;
$cfgData->{MinPasswordLength} = 0;
$cfgData->{UsersWebName} = $this->users_web;
};

around set_up => sub {
Expand Down Expand Up @@ -162,6 +164,8 @@ around tear_down => sub {
my $cfg = $app->cfg;

$this->removeWebFixture( $this->test_web );
$this->assert_str_not_equals( $cfg->data->{UsersWebName},
'Main', "UsersWebName equals to 'Main'" );
$this->removeWebFixture( $cfg->data->{UsersWebName} );
unlink( $Foswiki::cfg{Htpasswd}{FileName} );
$orig->( $this, @_ );
Expand Down
9 changes: 5 additions & 4 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Expand Up @@ -1076,11 +1076,11 @@ sub getUIFn {

=begin TML
---++ ObjectMethod createNewFoswikiApp(user => $user, request => $query, @params) -> ref to new Unit::TestApp obj
---++ ObjectMethod createNewFoswikiApp(%params) -> ref to new Unit::TestApp obj
cleans up the existing Foswiki object, and creates a new one
@params have to be key/value pairs and are passed directly to the new Foswiki() call
=%params= are passed directly to the =Foswiki::App= constructor.
typically called to force a full re-initialisation either with new preferences, topics, users, groups or CFG
Expand All @@ -1098,7 +1098,10 @@ sub createNewFoswikiApp {

$params{env} //= $this->app->cloneEnv;
my $app = Unit::TestApp->new( cfg => $this->app->cfg->clone, %params );

$this->_fixupAppObjects;
$this->app($app);

ASSERT( defined $Foswiki::app ) if SINGLE_SINGLETONS;

if ( $this->test_web && $this->test_topic ) {
Expand All @@ -1107,8 +1110,6 @@ sub createNewFoswikiApp {
[0] );
}

$this->_fixupAppObjects;

return $this->app;
}

Expand Down

0 comments on commit a6c1ab8

Please sign in to comment.