my $password = $userinfo->{password};
my $role = $userinfo->{role} || 'user';
- return unless ($username =~ /^https?:/
- || ($username && $self->validate_password($password))) ;
+ throw( "No username given" ) unless $username;
+ throw( "Invalid password - must be at least " . $self->MIN_PASS_LEN
+ . " characters long" )
+ unless ( $self->validate_password($password) || $username =~ /^https?:/ );
my $user = Text::Tradition::User->new(
id => $username,
my $password = $userinfo->{password};
my $role = $userinfo->{role};
- return unless $username;
- return if($password && !$self->validate_password($password));
+ throw( "Missing username or bad password" )
+ unless $username && $self->validate_password($password);
my $user = $self->find_user({ username => $username });
- return unless $user;
+ throw( "Could not find user $username" ) unless $user;
if($password) {
$user->password(crypt_password($password));
my ($self, $userinfo) = @_;
my $username = $userinfo->{username};
- return if !$username;
+ throw( "Need to specify a username for deactivation" ) unless $username;
my $user = $self->find_user({ username => $username });
- return if !$user;
+ throw( "User $username not found" ) unless $user;
$user->active(0);
foreach my $tradition (@{ $user->traditions }) {
my ($self, $userinfo) = @_;
my $username = $userinfo->{username};
- return if !$username;
+ throw( "Need to specify a username for reactivation" ) unless $username;
my $user = $self->lookup(Text::Tradition::User->id_for_user($username));
- return if !$user;
+ throw( "User $username not found" ) unless $user;
return $user if $user->active;
my ($self, $userinfo) = @_;
my $username = $userinfo->{username};
- return if !$username;
+ throw( "Need to specify a username for deletion" ) unless $username;
my $user = $self->find_user({ username => $username });
- return if !$user;
+ throw( "User $username not found" ) unless $user;
## Should we be using Text::Tradition::Directory for this bit?
$self->delete( @{ $user->traditions });
use Test::More 'no_plan';
use File::Temp;
+use TryCatch;
use_ok('Text::Tradition::Directory');
## passwords
my $shortpass = 'bloggs';
ok(!$user_store->validate_password($shortpass), '"bloggs" is too short for a password');
+try {
+ my $dud_user = $user_store->add_user({ username => 'joe',
+ password => $shortpass });
+ ok( 0, "User with short password should not have been created" );
+} catch ( Text::Tradition::Error $e ) {
+ is( $e->message, "Invalid password - must be at least "
+ . $user_store->MIN_PASS_LEN . " characters long",
+ "Attempt to add user with too-short password threw correct error" );
+}
## create user
my $new_user = $user_store->add_user({ username => 'fred',