use constant REMOTE_IP => "192.168.1.1";
use Newslash::Plugin::UserAuth;
+use Test::More;
+
sub new {
my ($class, $test, $options) = @_;
$options ||= {};
return shift->{test}->app;
}
+sub t {
+ return shift->{test};
+}
sub srcid {
my ($self, $ip, $mask) = @_;
my ($self, $name, $passwd) = @_;
my $user = Newslash::Util::Test::create_user($self->app, $name, $passwd);
if (!$user) {
- warn "user create failed!";
+ fail("create test user - $name / $passwd");
return;
}
$user->{srcids} = {
24 => Newslash::Util::Test::srcid(REMOTE_IP, 24),
32 => Newslash::Util::Test::srcid(REMOTE_IP, 32),
};
+ $user->{_passwd} = $passwd;
push @{$self->{users}}, $user;
return $user;
}
+sub login {
+ my ($self, $user, $passwd) = @_;
+ $passwd //= $user->{_passwd};
+ $self->t->post_ok('/login'
+ => {Accept => '*/*'}
+ => form
+ => {nickname => $user->{nickname}, passwd => $passwd})
+ ->status_is(302);
+}
+
+sub logout {
+ my ($self) = @_;
+ $self->t->get_ok('/logout')->status_is(302);
+}
+
sub create_admin {
my ($self, $name, $passwd) = @_;
my $user = Newslash::Util::Test::create_admin_user($self->app, $name, $passwd);