| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace Webkul\BagistoApi\Tests\Unit\Migration;
- use App\Auth\CustomerUserProvider;
- use App\Support\Magento1Password;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Schema;
- use Webkul\BagistoApi\Tests\BagistoApiTestCase;
- use Webkul\Customer\Models\Customer;
- class Magento1PasswordAttemptTest extends BagistoApiTestCase
- {
- public function setUp(): void
- {
- parent::setUp();
- if (! Schema::hasColumn('customers', 'legacy_password')) {
- $this->markTestSkipped('Run php artisan migrate to add Asteria customer columns.');
- }
- $this->seedRequiredData();
- }
- public function test_attempt_upgrades_a_legacy_hash_to_bcrypt(): void
- {
- $customer = $this->createCustomer([
- 'password' => Hash::make('placeholder-secret'),
- 'legacy_password' => md5('abcsecret12').':abc',
- ]);
- $this->assertTrue(Magento1Password::attempt($customer, 'secret12'));
- $customer->refresh();
- $this->assertTrue(Hash::check('secret12', $customer->password));
- $this->assertNull($customer->legacy_password);
- }
- public function test_attempt_accepts_an_existing_bcrypt_password(): void
- {
- $customer = $this->createCustomer([
- 'password' => Hash::make('secret12'),
- 'legacy_password' => null,
- ]);
- $this->assertTrue(Magento1Password::attempt($customer, 'secret12'));
- $this->assertFalse(Magento1Password::attempt($customer, 'wrong-password'));
- }
- public function test_customer_user_provider_upgrades_legacy_password(): void
- {
- $customer = $this->createCustomer([
- 'password' => Hash::make('placeholder-secret'),
- 'legacy_password' => md5('abcsecret12').':abc',
- ]);
- $provider = new CustomerUserProvider(app('hash'), Customer::class);
- $this->assertTrue($provider->validateCredentials($customer, ['password' => 'secret12']));
- $customer->refresh();
- $this->assertTrue(Hash::check('secret12', $customer->password));
- $this->assertNull($customer->legacy_password);
- }
- }
|