Fix MakerWorld 2FA duplicate email loop and add email SMTP diagnostics
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Models\Material;
|
||||
use App\Models\Product;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -215,4 +216,33 @@ class AuthAndEmailTest extends TestCase
|
||||
&& str_contains($mail->envelope()->subject, 'Bestelbevestiging');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_admin_can_trigger_test_email_via_web_and_cli(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$admin = User::create([
|
||||
'name' => 'Admin Jouwdriedee',
|
||||
'email' => 'info@jouwdriedee.nl',
|
||||
'password' => bcrypt('Jw3D!x9#QmK7$vR2'),
|
||||
'is_admin' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($admin);
|
||||
|
||||
// Web endpoint
|
||||
$response = $this->post(route('admin.content.test-mail'), [
|
||||
'test_email' => 'testgmail@gmail.com',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
// CLI command
|
||||
$exitCode = Artisan::call('app:test-mail', [
|
||||
'email' => 'testcli@gmail.com',
|
||||
]);
|
||||
|
||||
$this->assertEquals(0, $exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,4 +215,72 @@ class MakerWorldImporterTest extends TestCase
|
||||
$disconnectResponse->assertRedirect();
|
||||
$this->assertNull(Setting::get('makerworld_token'));
|
||||
}
|
||||
|
||||
public function test_makerworld_login_with_2fa_redirects_to_auth_tab_without_duplicate_email(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://api.bambulab.com/v1/user-service/user/login' => Http::response([
|
||||
'loginType' => 'verifyCode',
|
||||
'message' => 'Verification code sent',
|
||||
], 200),
|
||||
'https://api.bambulab.com/v1/user-service/user/sendemail/code' => Http::response([
|
||||
'success' => true,
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$response = $this->post(route('admin.makerworld.login'), [
|
||||
'account' => 'test2fa@jouwdriedee.nl',
|
||||
'password' => 'secret_pass',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.makerworld.index', ['tab' => 'auth']));
|
||||
$response->assertSessionHas('makerworld_2fa_account', 'test2fa@jouwdriedee.nl');
|
||||
|
||||
// Verify that sendemail/code was NOT called automatically (Bambu Lab already sent it on login)
|
||||
Http::assertNotSent(function ($request) {
|
||||
return str_contains($request->url(), 'sendemail/code');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_makerworld_can_verify_2fa_code(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://api.bambulab.com/v1/user-service/user/login' => Http::response([
|
||||
'accessToken' => 'token_after_2fa_code_9999',
|
||||
], 200),
|
||||
'https://api.bambulab.com/v1/design-user-service/my/preference' => Http::response([
|
||||
'uid' => 12345,
|
||||
'name' => 'Verified User',
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$response = $this->post(route('admin.makerworld.verify-code'), [
|
||||
'account' => 'test2fa@jouwdriedee.nl',
|
||||
'code' => '123456',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.makerworld.index', ['tab' => 'collections']));
|
||||
$this->assertSame('token_after_2fa_code_9999', Setting::get('makerworld_token'));
|
||||
}
|
||||
|
||||
public function test_makerworld_can_manually_resend_2fa_code(): void
|
||||
{
|
||||
Http::fake([
|
||||
'https://api.bambulab.com/v1/user-service/user/sendemail/code' => Http::response([
|
||||
'success' => true,
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$response = $this->post(route('admin.makerworld.resend-code'), [
|
||||
'account' => 'test2fa@jouwdriedee.nl',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.makerworld.index', ['tab' => 'auth']));
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
Http::assertSent(function ($request) {
|
||||
return str_contains($request->url(), 'sendemail/code') &&
|
||||
$request['email'] === 'test2fa@jouwdriedee.nl';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user