fix: validate dossier scope and accurate directory MFA status
This commit is contained in:
@@ -190,9 +190,13 @@ final class OpportunityPromotionTest extends TestCase
|
||||
public function test_profile_directory_uses_existing_accounts_without_exposing_authentication_secrets(): void
|
||||
{
|
||||
$other = User::factory()->create();
|
||||
$missingSecret = User::factory()->create(['two_factor_secret' => null, 'two_factor_confirmed_at' => now()]);
|
||||
$unconfirmed = User::factory()->create(['two_factor_secret' => Crypt::encryptString('SYNTHETIC-QA'), 'two_factor_confirmed_at' => null]);
|
||||
DB::table('portal_superuser_pair')->updateOrInsert(['id' => 1], ['first_user_id' => $this->actor->id, 'second_user_id' => $other->id, 'approved_by' => $other->id]);
|
||||
$this->get('/perfis/gestao')->assertOk()->assertInertia(fn (AssertableInertia $page) => $page
|
||||
->has('staffAccounts')->where('staffAccounts', fn ($rows) => collect($rows)->contains(fn ($row) => $row['id'] === $this->actor->id && $row['email'] === $this->actor->email && $row['verified'] && $row['mfa'])
|
||||
&& collect($rows)->contains(fn ($row) => $row['id'] === $missingSecret->id && $row['mfa'] === false)
|
||||
&& collect($rows)->contains(fn ($row) => $row['id'] === $unconfirmed->id && $row['mfa'] === false)
|
||||
&& collect($rows)->every(fn ($row) => ! isset($row['password']) && ! isset($row['two_factor_secret']))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\InvestmentConsumerScope;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvestmentConsumerScopeTest extends TestCase
|
||||
{
|
||||
public function test_an_explicit_opportunity_cannot_be_silently_discarded_when_the_dossier_has_no_choices(): void
|
||||
{
|
||||
$context = ['fields' => ['project_title' => 'Synthetic QA dossier'], 'selection' => [], 'opportunity_choices' => []];
|
||||
|
||||
try {
|
||||
app(InvestmentConsumerScope::class)->context($context, 'opportunity:99999999');
|
||||
$this->fail('An explicit opportunity outside the dossier must be rejected instead of becoming general context.');
|
||||
} catch (HttpException $error) {
|
||||
$this->assertSame(422, $error->getStatusCode());
|
||||
$this->assertSame([], $context['opportunity_choices']);
|
||||
$this->assertSame('Synthetic QA dossier', $context['fields']['project_title']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_general_context_without_an_opportunity_preserves_an_empty_dossier(): void
|
||||
{
|
||||
$context = ['fields' => ['project_title' => 'Synthetic QA dossier'], 'selection' => []];
|
||||
|
||||
$this->assertSame($context, app(InvestmentConsumerScope::class)->context($context, null));
|
||||
}
|
||||
|
||||
public function test_an_explicit_opportunity_outside_existing_choices_is_rejected(): void
|
||||
{
|
||||
$context = ['fields' => [], 'selection' => [], 'opportunity_choices' => [['opportunity' => ['key' => 'opportunity:1']]]];
|
||||
|
||||
$this->expectException(HttpException::class);
|
||||
app(InvestmentConsumerScope::class)->context($context, 'opportunity:2');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user