From f598f56fab4492821eaf8e7507d7b3a99e4a9e2a Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 6 Apr 2016 15:28:47 +0100 Subject: Prevent dev sites auto-creating session. We check for a session's existence before looking in it, as looking in it first would auto create a session. --- t/app/controller/auth_social.t | 3 +++ 1 file changed, 3 insertions(+) (limited to 't') diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t index 84fdd4dfe..b8675a8fd 100644 --- a/t/app/controller/auth_social.t +++ b/t/app/controller/auth_social.t @@ -31,7 +31,10 @@ my $fb_uid = 123456789; for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { for my $page ( 'my', 'report', 'update' ) { subtest "test FB '$fb_state' login for page '$page'" => sub { + # Lots of user changes happening here, make sure we don't confuse + # Catalyst with a cookie session user that no longer exists $mech->log_out_ok; + $mech->cookie_jar({}); if ($fb_state eq 'existing UID') { my $user = $mech->create_user_ok($fb_email); $user->update({ facebook_id => $fb_uid }); -- cgit v1.2.3 From b7099e8e513fe64ec183b1403515f46a7cc25f19 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 8 Apr 2016 21:11:48 +0100 Subject: Add PNG image support. Store image type along with hash in photo column, and use that when outputting images / generating URLs. Make sure all public photo URL generation goes through appropriate functions, and change temp URLs so the filename can be output directly from the list. --- t/app/controller/photo.t | 4 ++-- t/app/controller/report_new.t | 4 ++-- t/app/model/photoset.t | 2 +- t/open311.t | 26 +++++++++++++++++++------- t/open311/getservicerequestupdates.t | 2 +- 5 files changed, 25 insertions(+), 13 deletions(-) (limited to 't') diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t index 39380e769..425e3c4df 100644 --- a/t/app/controller/photo.t +++ b/t/app/controller/photo.t @@ -65,10 +65,10 @@ subtest "Check multiple upload worked" => sub { ok $mech->success, 'Made request with multiple photo upload'; $mech->base_is('http://localhost/report/new'); $mech->content_like( - qr[(\s*){3}], + qr[(\s*){3}], 'Three uploaded pictures are all shown, safe'); $mech->content_contains( - 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687"', + 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg,1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg,1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg"', 'Returned upload_fileid contains expected hash, 3 times'); my $image_file = path($UPLOAD_DIR, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg'); ok $image_file->exists, 'File uploaded to temp'; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index cf72221b4..eb29d37da 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -420,7 +420,7 @@ foreach my $test ( changes => { photo1 => '', }, - errors => [ "Please upload a JPEG image only" ], + errors => [ "Please upload an image only" ], }, { msg => 'bad photo upload gives error', @@ -443,7 +443,7 @@ foreach my $test ( changes => { photo1 => '', }, - errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ], + errors => [ "That image doesn't appear to have uploaded correctly (Please upload an image only ), please try again." ], }, { msg => 'photo with octet-stream gets through okay', diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t index cfb5236a8..577e39eb1 100644 --- a/t/app/model/photoset.t +++ b/t/app/model/photoset.t @@ -58,7 +58,7 @@ subtest 'Photoset with photo inline in DB' => sub { my $report = make_report( $image_path->slurp ); my $photoset = $report->get_photoset(); is $photoset->num_images, 1, 'Found just 1 image'; - is $photoset->data, '1cdd4329ceee2234bd4e89cb33b42061a0724687'; + is $photoset->data, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg'; }; $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); diff --git a/t/open311.t b/t/open311.t index 6333355e8..42d09b29c 100644 --- a/t/open311.t +++ b/t/open311.t @@ -3,6 +3,8 @@ use utf8; use strict; use warnings; +use File::Temp 'tempdir'; +use Path::Tiny; use Test::More; use Test::Warn; use FixMyStreet::DB; @@ -24,7 +26,7 @@ EOT is $o->_process_error( $err_text ), "400: Service Code cannot be null -- can't proceed with the request.\n", 'error text parsing'; is $o->_process_error( '503 - service unavailable' ), 'unknown error', 'error text parsing of bad error'; -my $o2 = Open311->new( endpoint => 'http://192.168.50.1/open311/', jurisdiction => 'example.org' ); +my $o2 = Open311->new( endpoint => 'http://127.0.0.1/open311/', jurisdiction => 'example.org' ); my $u = FixMyStreet::DB->resultset('User')->new( { email => 'test@example.org', name => 'A User' } ); @@ -258,16 +260,26 @@ subtest 'extended request update post parameters' => sub { }; subtest 'check media url set' => sub { - $comment->photo(1); + my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); + + my $image_path = path('t/app/controller/sample.jpg'); + $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); + + $comment->photo("0123456789012345678901234567890123456789"); $comment->cobrand('fixmystreet'); - my $results = make_update_req( $comment, '248' ); + FixMyStreet::override_config { + UPLOAD_DIR => $UPLOAD_DIR, + }, sub { + my $results = make_update_req( $comment, '248' ); - is $results->{ res }, 248, 'got update id'; + is $results->{ res }, 248, 'got update id'; - my $c = CGI::Simple->new( $results->{ req }->content ); - my $expected_path = '/c/' . $comment->id . '.full.jpeg'; - like $c->param('media_url'), qr/$expected_path/, 'image url included'; + my $c = CGI::Simple->new( $results->{ req }->content ); + my $expected_path = '/c/' . $comment->id . '.0.full.jpeg'; + like $c->param('media_url'), qr/$expected_path/, 'image url included'; + }; + $comment->photo(undef); }; foreach my $test ( diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 18a5802bb..a57d2d0e6 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -388,7 +388,7 @@ subtest 'Update with media_url includes image in update' => sub { is $problem->comments->count, 1, 'comment count'; my $c = $problem->comments->first; is $c->external_id, 638344; - is $c->photo, '1cdd4329ceee2234bd4e89cb33b42061a0724687', 'photo exists'; + is $c->photo, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg', 'photo exists'; }; foreach my $test ( -- cgit v1.2.3