From 1bb94cd0bf0821927b3f449d832a9982b0397fa9 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 31 May 2017 12:48:17 +0100 Subject: Auto-add strict/warnings/Test::More with TestMech. --- t/app/controller/auth.t | 4 ---- 1 file changed, 4 deletions(-) (limited to 't/app/controller/auth.t') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 3a11cfc4a..d1e313df2 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -1,7 +1,3 @@ -use strict; -use warnings; - -use Test::More; use Test::MockModule; use FixMyStreet::TestMech; -- cgit v1.2.3 From 3b72526db1cdb4695f61a188261351ddd2aea395 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 14 Jun 2017 13:59:43 +0100 Subject: Run each test file in a transaction. This means that the tests can be run in parallel. --- t/app/controller/auth.t | 3 --- 1 file changed, 3 deletions(-) (limited to 't/app/controller/auth.t') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index d1e313df2..388216a1f 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -6,11 +6,8 @@ my $mech = FixMyStreet::TestMech->new; my $test_email = 'test@example.com'; my $test_email2 = 'test@example.net'; my $test_password = 'foobar'; -$mech->delete_user($test_email); END { - $mech->delete_user($test_email); - $mech->delete_user($test_email2); done_testing(); } -- cgit v1.2.3 From 217cc18a47c09120a75668eaf365e8e62171b853 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Mon, 12 Jun 2017 12:00:46 +0100 Subject: Add SIGNUPS_DISABLED config flag --- t/app/controller/auth.t | 93 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) (limited to 't/app/controller/auth.t') diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 388216a1f..cb7d16969 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -5,6 +5,7 @@ my $mech = FixMyStreet::TestMech->new; my $test_email = 'test@example.com'; my $test_email2 = 'test@example.net'; +my $test_email3 = 'newuser@example.org'; my $test_password = 'foobar'; END { @@ -279,6 +280,94 @@ subtest "sign in but have email form autofilled" => sub { is $mech->uri->path, '/my', "redirected to correct page"; }; +$mech->log_out_ok; -# more test: -# TODO: test that email are always lowercased +subtest "sign in with uppercase email" => sub { + $mech->get_ok('/auth'); + my $uc_test_email = uc $test_email; + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { + email => $uc_test_email, + password_sign_in => $test_password, + }, + button => 'sign_in', + }, + "sign in with '$uc_test_email' and auto-completed name" + ); + is $mech->uri->path, '/my', "redirected to correct page"; + + $mech->content_contains($test_email); + $mech->content_lacks($uc_test_email); + + my $count = FixMyStreet::App->model('DB::User')->search( { email => $uc_test_email } )->count; + is $count, 0, "uppercase user wasn't created"; +}; + + +FixMyStreet::override_config { + SIGNUPS_DISABLED => 1, +}, sub { + subtest 'signing in with an unknown email address disallowed' => sub { + $mech->log_out_ok; + # create a new account + $mech->clear_emails_ok; + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { email => $test_email3, }, + button => 'email_sign_in', + }, + "create a new account" + ); + + ok $mech->email_count_is(0); + + my $count = FixMyStreet::App->model('DB::User')->search( { email => $test_email3 } )->count; + is $count, 0, "no user exists"; + }; + + subtest 'signing in as known email address with new password is allowed' => sub { + my $new_password = "myshinynewpassword"; + + $mech->clear_emails_ok; + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { + email => "$test_email", + password_register => $new_password, + r => 'faq', # Just as a test + }, + button => 'email_sign_in', + }, + "email_sign_in with '$test_email'" + ); + + $mech->not_logged_in_ok; + + ok $mech->email_count_is(1); + my $link = $mech->get_link_from_email; + $mech->get_ok($link); + is $mech->uri->path, '/faq', "redirected to the Help page"; + + $mech->log_out_ok; + + $mech->get_ok('/auth'); + $mech->submit_form_ok( + { + form_name => 'general_auth', + fields => { + email => $test_email, + password_sign_in => $new_password, + }, + button => 'sign_in', + }, + "sign in with '$test_email' and new password" + ); + is $mech->uri->path, '/my', "redirected to correct page"; + }; +}; -- cgit v1.2.3