Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
csavelief committed Sep 10, 2024
1 parent 42b9556 commit 8677382
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions tests/AdversaryMeter/AdversaryMeterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@
use App\Modules\AdversaryMeter\Models\Asset;
use App\Modules\AdversaryMeter\Models\Attacker;
use App\Modules\AdversaryMeter\Models\Honeypot;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdversaryMeterTestCase extends TestCase
{
use RefreshDatabase;

protected User $user;
protected string $token;

protected function setUp(): void
{
parent::setUp();

$this->artisan("migrate --path=database/migrations --database=mysql");
$this->artisan("migrate --path=database/migrations/am --database=mysql_am");

$this->user = User::create([
'name' => 'QA',
'password' => bcrypt('whatapassword'),
'email' => 'qa@computablefacts.com'
]);
$this->token = $this->user->createToken('tests', [])->plainTextToken;
$this->user->am_api_token = $this->token;
$this->user->save();
}

protected function tearDown(): void
Expand Down
8 changes: 4 additions & 4 deletions tests/AdversaryMeter/DiscoveryShallowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function testItCreatesAnAssetAfterDiscovery()
'subdomains' => ['www1.example.com', 'www1.example.com' /* duplicate! */, 'www2.example.com'],
]);

event(new CreateAsset('example.com'));
event(new CreateAsset('example.com'));
event(new CreateAsset($this->user, 'example.com'));
event(new CreateAsset($this->user, 'example.com'));

TriggerDiscoveryShallow::dispatch();

Expand All @@ -31,7 +31,7 @@ public function testItCreatesAnAssetAfterDiscovery()
$this->assertEquals(1, $assetsOriginal->count());
$this->assertEquals(2, $assetsDiscovered->count());

$this->assertEquals(1, $assetsDiscovered->filter(fn(Asset $asset) => $asset->asset === 'www1.example.com')->count());
$this->assertEquals(1, $assetsDiscovered->filter(fn(Asset $asset) => $asset->asset === 'www2.example.com')->count());
$this->assertEquals(1, $assetsDiscovered->filter(fn(Asset $asset) => $asset->asset === 'www1.example.com' && $asset->created_by = $this->user->id)->count());
$this->assertEquals(1, $assetsDiscovered->filter(fn(Asset $asset) => $asset->asset === 'www2.example.com' && $asset->created_by = $this->user->id)->count());
}
}

0 comments on commit 8677382

Please sign in to comment.