Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
csavelief committed Sep 9, 2024
1 parent 64b1921 commit 42b9556
Show file tree
Hide file tree
Showing 5 changed files with 840 additions and 1,243 deletions.
16 changes: 12 additions & 4 deletions app/Modules/AdversaryMeter/Http/Controllers/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public function removeTag(Asset $asset, AssetTag $assetTag): void
public function infosFromAsset(string $assetBase64): array
{
$domainOrIpOrRange = base64_decode($assetBase64);
/** @var Asset $asset */
$asset = Asset::where('asset', $domainOrIpOrRange)->first();

if (!$asset) {
Expand All @@ -253,10 +254,11 @@ public function infosFromAsset(string $assetBase64): array
}

// Load the asset's tags
$tags = $asset->tags()->get()->map(fn(AssetTag $tag) => $tag->tag)->toArray();
$tags = $asset->tags()->orderBy('tag')->get()->map(fn(AssetTag $tag) => $tag->tag)->toArray();

// Load the asset's open ports
$ports = $asset->ports()
->orderBy('port')
->get()
->map(function (Port $port) {
return [
Expand All @@ -265,7 +267,7 @@ public function infosFromAsset(string $assetBase64): array
'protocol' => $port->protocol,
'products' => [$port->product],
'services' => [$port->service],
'tags' => $port->tags()->get()->map(fn(PortTag $tag) => $tag->tag)->toArray(),
'tags' => $port->tags()->orderBy('tag')->get()->map(fn(PortTag $tag) => $tag->tag)->toArray(),
'screenshotId' => $port->screenshot()->first()?->id,
];
})
Expand Down Expand Up @@ -296,9 +298,15 @@ public function infosFromAsset(string $assetBase64): array
'title' => $alert->title,
'flarum_url' => null,
'start_date' => $alert->created_at,
'is_hidden' => $alert->is_hidden,
'is_hidden' => $alert->is_hidden === 1,
];
});
})
->sortBy([
['ip', 'asc'],
['port', 'asc'],
['protocol', 'asc'],
])
->values();

// Load the asset's scans
$scansInProgress = $asset->scanInProgress();
Expand Down
Loading

0 comments on commit 42b9556

Please sign in to comment.