From 8c9995e325dedd688f271dcc792c736766ebee46 Mon Sep 17 00:00:00 2001 From: Sascha Brendel Date: Sun, 12 May 2019 12:09:56 +0200 Subject: [PATCH] Fixed callback failed logs caused by status code 201 --- app/Jobs/NotifyCallbacksJob.php | 2 +- app/Jobs/StartScannerJob.php | 2 +- composer.json | 8 +- composer.lock | 162 +++++++++++++------------- tests/Unit/NotifyCallbacksJobTest.php | 24 ++++ tests/Unit/StartScannerJobTest.php | 20 ++++ 6 files changed, 137 insertions(+), 81 deletions(-) diff --git a/app/Jobs/NotifyCallbacksJob.php b/app/Jobs/NotifyCallbacksJob.php index 7bd7788f..99b217c6 100644 --- a/app/Jobs/NotifyCallbacksJob.php +++ b/app/Jobs/NotifyCallbacksJob.php @@ -46,7 +46,7 @@ public function handle() 'json' => (new ScanCallbackResponse($this->scan)) ]); - if ($response->getStatusCode() === 200) { + if (in_array($response->getStatusCode(), [200, 201, 202])) { Log::info('Scan results for Scan ID ' . $this->scan->id . ' successfully sent to: ' . $this->scan->callbackurls[0]); $hasAtLeastOneSuccessfulCallback = true; } else { diff --git a/app/Jobs/StartScannerJob.php b/app/Jobs/StartScannerJob.php index 8f8604b8..d7e03123 100644 --- a/app/Jobs/StartScannerJob.php +++ b/app/Jobs/StartScannerJob.php @@ -61,7 +61,7 @@ public function handle() ]]); - if ($response->getStatusCode() === 200) { + if (in_array($response->getStatusCode(), [200, 201, 202])) { \Log::info('Scan successful started' . $logInfo); } else { \Log::critical('Failed to start scan' . $logInfo); diff --git a/composer.json b/composer.json index 1283f03c..4dbfe0f9 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,12 @@ "laravel" ], "license": "MIT", + "repositories": [ + { + "type": "git", + "url": "https://github.com/Lednerb/log-fake.git" + } + ], "require": { "php": "^7.1.3", "fideloper/proxy": "^4.0", @@ -23,7 +29,7 @@ "mockery/mockery": "^1.0", "nunomaduro/collision": "^2.0", "phpunit/phpunit": "^7.5", - "timacdonald/log-fake": "^1.0" + "timacdonald/log-fake": "dev-feature-loggedTimesWithCallback" }, "config": { "optimize-autoloader": true, diff --git a/composer.lock b/composer.lock index 22cc8de4..a8c68439 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "236f8f7137ff27529c86ae04a7aeefb7", + "content-hash": "b387c6b1e621fd938215d083648c1908", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -644,16 +644,16 @@ }, { "name": "laravel/framework", - "version": "v5.8.14", + "version": "v5.8.16", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "d1ba096bf809c7cbe6cb9624222326d75c92fd74" + "reference": "83d57f9f9162ab476c43b9ec00d463ff12c578fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/d1ba096bf809c7cbe6cb9624222326d75c92fd74", - "reference": "d1ba096bf809c7cbe6cb9624222326d75c92fd74", + "url": "https://api.github.com/repos/laravel/framework/zipball/83d57f9f9162ab476c43b9ec00d463ff12c578fd", + "reference": "83d57f9f9162ab476c43b9ec00d463ff12c578fd", "shasum": "" }, "require": { @@ -787,7 +787,7 @@ "framework", "laravel" ], - "time": "2019-04-23T13:22:19+00:00" + "time": "2019-05-07T14:37:11+00:00" }, { "name": "laravel/tinker", @@ -1127,16 +1127,16 @@ }, { "name": "opis/closure", - "version": "3.1.6", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/opis/closure.git", - "reference": "ccb8e3928c5c8181c76cdd0ed9366c5bcaafd91b" + "reference": "09b4389715a7eec100176ea58286649181753508" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opis/closure/zipball/ccb8e3928c5c8181c76cdd0ed9366c5bcaafd91b", - "reference": "ccb8e3928c5c8181c76cdd0ed9366c5bcaafd91b", + "url": "https://api.github.com/repos/opis/closure/zipball/09b4389715a7eec100176ea58286649181753508", + "reference": "09b4389715a7eec100176ea58286649181753508", "shasum": "" }, "require": { @@ -1149,7 +1149,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "3.2.x-dev" } }, "autoload": { @@ -1184,7 +1184,7 @@ "serialization", "serialize" ], - "time": "2019-02-22T10:30:00+00:00" + "time": "2019-05-05T12:50:25+00:00" }, { "name": "paragonie/random_compat", @@ -1794,7 +1794,7 @@ }, { "name": "symfony/console", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/console.git", @@ -1866,16 +1866,16 @@ }, { "name": "symfony/contracts", - "version": "v1.0.2", + "version": "v1.1.0", "source": { "type": "git", "url": "https://github.com/symfony/contracts.git", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" + "reference": "d3636025e8253c6144358ec0a62773cae588395b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "url": "https://api.github.com/repos/symfony/contracts/zipball/d3636025e8253c6144358ec0a62773cae588395b", + "reference": "d3636025e8253c6144358ec0a62773cae588395b", "shasum": "" }, "require": { @@ -1883,19 +1883,22 @@ }, "require-dev": { "psr/cache": "^1.0", - "psr/container": "^1.0" + "psr/container": "^1.0", + "symfony/polyfill-intl-idn": "^1.10" }, "suggest": { "psr/cache": "When using the Cache contracts", "psr/container": "When using the Service contracts", "symfony/cache-contracts-implementation": "", + "symfony/event-dispatcher-implementation": "", + "symfony/http-client-contracts-implementation": "", "symfony/service-contracts-implementation": "", "symfony/translation-contracts-implementation": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.1-dev" } }, "autoload": { @@ -1930,11 +1933,11 @@ "interoperability", "standards" ], - "time": "2018-12-05T08:06:11+00:00" + "time": "2019-04-27T14:29:50+00:00" }, { "name": "symfony/css-selector", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", @@ -1987,7 +1990,7 @@ }, { "name": "symfony/debug", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", @@ -2043,7 +2046,7 @@ }, { "name": "symfony/event-dispatcher", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -2107,7 +2110,7 @@ }, { "name": "symfony/finder", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -2156,16 +2159,16 @@ }, { "name": "symfony/http-foundation", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "6ebbe61f48069033225c9d3fa7eb5ed116d766d6" + "reference": "1ea878bd3af18f934dedb8c0de60656a9a31a718" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/6ebbe61f48069033225c9d3fa7eb5ed116d766d6", - "reference": "6ebbe61f48069033225c9d3fa7eb5ed116d766d6", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/1ea878bd3af18f934dedb8c0de60656a9a31a718", + "reference": "1ea878bd3af18f934dedb8c0de60656a9a31a718", "shasum": "" }, "require": { @@ -2206,20 +2209,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2019-04-17T14:56:00+00:00" + "time": "2019-05-01T08:36:31+00:00" }, { "name": "symfony/http-kernel", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "3db83303dbc1da9777e5ff63423b8b7fde423a1b" + "reference": "a7713bc522f1a1cdf0b39f809fa4542523fc3114" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/3db83303dbc1da9777e5ff63423b8b7fde423a1b", - "reference": "3db83303dbc1da9777e5ff63423b8b7fde423a1b", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/a7713bc522f1a1cdf0b39f809fa4542523fc3114", + "reference": "a7713bc522f1a1cdf0b39f809fa4542523fc3114", "shasum": "" }, "require": { @@ -2295,7 +2298,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "https://symfony.com", - "time": "2019-04-17T16:17:13+00:00" + "time": "2019-05-01T13:31:08+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2592,7 +2595,7 @@ }, { "name": "symfony/process", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/process.git", @@ -2641,16 +2644,16 @@ }, { "name": "symfony/routing", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "0e5719d216017b1a0342fa48e86467cedca1c954" + "reference": "f4e43bb0dff56f0f62fa056c82d7eadcdb391bab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/0e5719d216017b1a0342fa48e86467cedca1c954", - "reference": "0e5719d216017b1a0342fa48e86467cedca1c954", + "url": "https://api.github.com/repos/symfony/routing/zipball/f4e43bb0dff56f0f62fa056c82d7eadcdb391bab", + "reference": "f4e43bb0dff56f0f62fa056c82d7eadcdb391bab", "shasum": "" }, "require": { @@ -2713,20 +2716,20 @@ "uri", "url" ], - "time": "2019-04-14T18:04:59+00:00" + "time": "2019-04-27T09:38:08+00:00" }, { "name": "symfony/translation", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "46c0dede1f925383d13dc783857be2c41efd0b24" + "reference": "181a426dd129cb496f12d7e7555f6d0b37a7615b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/46c0dede1f925383d13dc783857be2c41efd0b24", - "reference": "46c0dede1f925383d13dc783857be2c41efd0b24", + "url": "https://api.github.com/repos/symfony/translation/zipball/181a426dd129cb496f12d7e7555f6d0b37a7615b", + "reference": "181a426dd129cb496f12d7e7555f6d0b37a7615b", "shasum": "" }, "require": { @@ -2788,20 +2791,20 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2019-04-10T16:20:36+00:00" + "time": "2019-05-01T12:55:36+00:00" }, { "name": "symfony/var-dumper", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "e760a38e12b15032325e64be63f7ffc1817af617" + "reference": "3c4084cb1537c0e2ad41aad622bbf55a44a5c9ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/e760a38e12b15032325e64be63f7ffc1817af617", - "reference": "e760a38e12b15032325e64be63f7ffc1817af617", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/3c4084cb1537c0e2ad41aad622bbf55a44a5c9ce", + "reference": "3c4084cb1537c0e2ad41aad622bbf55a44a5c9ce", "shasum": "" }, "require": { @@ -2864,7 +2867,7 @@ "debug", "dump" ], - "time": "2019-04-17T14:57:01+00:00" + "time": "2019-05-01T12:55:36+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -4069,16 +4072,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.0", + "version": "4.3.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", "shasum": "" }, "require": { @@ -4116,7 +4119,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30T07:14:17+00:00" + "time": "2019-04-30T17:48:53+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -4482,16 +4485,16 @@ }, { "name": "phpunit/phpunit", - "version": "7.5.9", + "version": "7.5.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "134669cf0eeac3f79bc7f0c793efbc158bffc160" + "reference": "d7d9cee051d03ed98df6023aad93f7902731a780" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/134669cf0eeac3f79bc7f0c793efbc158bffc160", - "reference": "134669cf0eeac3f79bc7f0c793efbc158bffc160", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d7d9cee051d03ed98df6023aad93f7902731a780", + "reference": "d7d9cee051d03ed98df6023aad93f7902731a780", "shasum": "" }, "require": { @@ -4562,7 +4565,7 @@ "testing", "xunit" ], - "time": "2019-04-19T15:50:46+00:00" + "time": "2019-05-09T05:06:47+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -4731,16 +4734,16 @@ }, { "name": "sebastian/environment", - "version": "4.2.1", + "version": "4.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "3095910f0f0fb155ac4021fc51a4a7a39ac04e8a" + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/3095910f0f0fb155ac4021fc51a4a7a39ac04e8a", - "reference": "3095910f0f0fb155ac4021fc51a4a7a39ac04e8a", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/f2a2c8e1c97c11ace607a7a667d73d47c19fe404", + "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404", "shasum": "" }, "require": { @@ -4780,7 +4783,7 @@ "environment", "hhvm" ], - "time": "2019-04-25T07:55:20+00:00" + "time": "2019-05-05T09:05:15+00:00" }, { "name": "sebastian/exporter", @@ -5225,7 +5228,7 @@ }, { "name": "symfony/filesystem", - "version": "v4.2.7", + "version": "v4.2.8", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", @@ -5315,17 +5318,11 @@ }, { "name": "timacdonald/log-fake", - "version": "v1.0.0", + "version": "dev-feature-loggedTimesWithCallback", "source": { "type": "git", - "url": "https://github.com/timacdonald/log-fake.git", - "reference": "46bf3d3e1d121d6ea085f05f3ff400b8e411e00a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/timacdonald/log-fake/zipball/46bf3d3e1d121d6ea085f05f3ff400b8e411e00a", - "reference": "46bf3d3e1d121d6ea085f05f3ff400b8e411e00a", - "shasum": "" + "url": "https://github.com/Lednerb/log-fake.git", + "reference": "d355ffe9149afa5b6b9df306bdc3b98dedade9b9" }, "require": { "illuminate/config": "~5.6", @@ -5341,7 +5338,14 @@ "TiMacDonald\\Log\\": "src" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + }, + "files": [ + "tests/helpers.php" + ] + }, "license": [ "MIT" ], @@ -5360,7 +5364,7 @@ "logger", "testing" ], - "time": "2018-10-06T03:36:12+00:00" + "time": "2019-05-12T09:22:11+00:00" }, { "name": "webmozart/assert", @@ -5416,7 +5420,9 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "timacdonald/log-fake": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { diff --git a/tests/Unit/NotifyCallbacksJobTest.php b/tests/Unit/NotifyCallbacksJobTest.php index e6d736d0..504c0c9c 100644 --- a/tests/Unit/NotifyCallbacksJobTest.php +++ b/tests/Unit/NotifyCallbacksJobTest.php @@ -66,4 +66,28 @@ public function if_a_callbackurl_was_not_reachable_a_proper_message_will_be_logg return Str::contains($message, 'Scan with ID ' . $this->scan->id . ' could not be sent to any given callbackurls.'); }); } + + /** @test */ + public function all_successful_http_status_codes_are_handled_as_success() + { + $scan = factory(Scan::class)->create([ + 'callbackurls' => [ + 'http://callback.one', + 'http://callback.two', + 'http://callback.three', + ] + ]); + + $job = new NotifyCallbacksJob($scan, $this->getMockedHttpClient([ + new Response(200), + new Response(201), + new Response(202), + ])); + + $job->handle(); + + Log::assertLogged('info', function ($message) use ($scan) { + return Str::contains($message, 'Scan results for Scan ID ' . $scan->id . ' successfully sent to: '); + }, 3); + } } diff --git a/tests/Unit/StartScannerJobTest.php b/tests/Unit/StartScannerJobTest.php index a9d1c53c..6450d971 100644 --- a/tests/Unit/StartScannerJobTest.php +++ b/tests/Unit/StartScannerJobTest.php @@ -65,4 +65,24 @@ public function if_a_scanner_could_not_be_started_a_critical_log_message_will_be }); $this->assertTrue($scan->hasError); } + + /** @test */ + public function all_successful_http_status_codes_are_handled_as_success() + { + $scan = factory(Scan::class)->create(); + + (new StartScannerJob($scan, 'testscanner', 'http://testscanner', $this->getMockedHttpClient([ + new Response(200) + ])))->handle(); + (new StartScannerJob($scan, 'testscanner', 'http://testscanner', $this->getMockedHttpClient([ + new Response(201) + ])))->handle(); + (new StartScannerJob($scan, 'testscanner', 'http://testscanner', $this->getMockedHttpClient([ + new Response(202) + ])))->handle(); + + Log::assertLogged('info', function ($message) { + return Str::contains($message, 'Scan successful started'); + }, 3); + } }