-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust ScanCallbackResponse to new enhanced format
- Loading branch information
Showing
7 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Responses; | ||
|
||
use App\Scan; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ScanCallbackResponse extends Model | ||
{ | ||
public function __construct(Scan $scan) | ||
{ | ||
$this->url = $scan->url; | ||
$this->dangerLevel = $scan->dangerLevel; | ||
$this->started_at = $scan->created_at->toDateTimeString(); | ||
$this->finished_at = now()->toDateTimeString(); | ||
$this->results = $this->getFormattedResults($scan); | ||
} | ||
|
||
public function getFormattedResults(Scan $scan) | ||
{ | ||
$results = collect(); | ||
|
||
foreach ($scan->results as $result) { | ||
$results->push(array_merge([ | ||
'started_at' => $result->created_at->toDateTimeString(), | ||
'finished_at' => $result->updated_at->toDateTimeString(), | ||
], $result->result->toArray())); | ||
} | ||
|
||
return $results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use App\Http\Responses\ScanCallbackResponse; | ||
use Carbon\Carbon; | ||
|
||
class ScanCallbackResponseTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$knownDate = Carbon::create(2019, 5, 7, 11, 55, 15); | ||
Carbon::setTestNow($knownDate); | ||
} | ||
|
||
/** @test */ | ||
public function the_scanCallbackResponse_has_the_defined_format() | ||
{ | ||
$scan = $this->generateScanWithResult(); | ||
$scan->update([ | ||
'dangerLevel' => 7, | ||
'started_at' => now() | ||
]); | ||
|
||
$response = new ScanCallbackResponse($scan->refresh()); | ||
|
||
$this->assertEquals(json_encode([ | ||
'url' => 'https://example.org', | ||
'dangerLevel' => '7', | ||
'started_at' => '2019-05-07 11:55:15', | ||
'finished_at' => '2019-05-07 11:55:15', | ||
'results' => [ | ||
[ | ||
'started_at' => now()->toDateTimeString(), | ||
'finished_at' => now()->toDateTimeString(), | ||
"name" => "INI_S", | ||
"version" => "1.0.0", | ||
"hasError" => false, | ||
"errorMessage" => null, | ||
"score" => 100, | ||
"tests" => [ | ||
[ | ||
"name" => "PHISHING", | ||
"hasError" => false, | ||
"errorMessage" => null, | ||
"score" => 100, | ||
"scoreType" => "success", | ||
"testDetails" => [] | ||
], | ||
[ | ||
"name" => "SPAM", | ||
"hasError" => false, | ||
"errorMessage" => null, | ||
"score" => 100, | ||
"scoreType" => "success", | ||
"testDetails" => [] | ||
], | ||
[ | ||
"name" => "MALWARE", | ||
"hasError" => false, | ||
"errorMessage" => null, | ||
"score" => 100, | ||
"scoreType" => "success", | ||
"testDetails" => [] | ||
] | ||
] | ||
] | ||
] | ||
]), $response->toJson()); | ||
} | ||
} |