From b42bf08363cfdc5ba4b96b4b8e3be387d2f699e5 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 24 Jul 2018 22:31:09 +0200 Subject: [PATCH] Fix #76 Add .zip file check in the tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is dedicated to Nartagnan, who is supporting me with Ğ1. Many thanks :-) --- CHANGELOG | 1 + t/test.t | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 4ee30d8..3f3d75f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ Revision history for Lutim - Add CLI command to print informations about images - Add CLI command to remove images - Add CLI command to search images based on the uploader's IP address + - Add .zip file check in the tests 0.10.4 2018-05-07 - Fix bug in cache system that would allow someone to view an image with an incorrect decryption key diff --git a/t/test.t b/t/test.t index 0172b97..00850b0 100644 --- a/t/test.t +++ b/t/test.t @@ -9,6 +9,7 @@ use Test::Mojo; use FindBin qw($Bin); use Digest::file qw(digest_file_hex); +use IO::Uncompress::Unzip qw($UnzipError); my ($m, $cfile); @@ -108,6 +109,26 @@ $t->get_ok('/'.$short) $t->get_ok('/'.$short) ->status_is(302); +# Get zip file and test it +$t->get_ok('/zip?i='.$short) + ->status_is(200) + ->header_is('Content-Disposition' => 'attachment;filename=images.zip'); + +my $zip = $t->ua->get('/zip?i='.$short)->res->body; +my $u = new IO::Uncompress::Unzip \$zip + or die "Cannot open zip file: $UnzipError"; + +my $status; +my @files = qw(hosted_with_lutim.png images/ images/Lutim.png.txt); +for ($status = 1; $status > 0; $status = $u->nextStream()) { + my $name = $u->getHeaderInfo()->{Name}; + is($name, shift(@files)); + my $buff; + while (($status = $u->read($buff)) > 0) { + } + last if $status < 0; +} + # Delete image with token $raw = $t->ua->post('/' => form => { file => { file => $image }, format => 'json' })->res; my $rshort = $raw->json('/msg/real_short');