2017-09-27 03:16:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services\Helpers;
|
|
|
|
|
|
|
|
use Mockery as m;
|
|
|
|
use Tests\TestCase;
|
2018-03-05 04:42:33 +00:00
|
|
|
use Tests\Traits\MocksUuids;
|
2017-09-27 03:16:26 +00:00
|
|
|
use Illuminate\Contracts\Hashing\Hasher;
|
|
|
|
use Illuminate\Database\ConnectionInterface;
|
|
|
|
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
|
|
|
|
|
|
|
|
class TemporaryPasswordServiceTest extends TestCase
|
|
|
|
{
|
2018-03-05 04:42:33 +00:00
|
|
|
use MocksUuids;
|
2017-09-27 03:16:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
protected $connection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Hashing\Hasher|\Mockery\Mock
|
|
|
|
*/
|
|
|
|
protected $hasher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Helpers\TemporaryPasswordService
|
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->connection = m::mock(ConnectionInterface::class);
|
|
|
|
$this->hasher = m::mock(Hasher::class);
|
|
|
|
|
2018-03-05 04:42:33 +00:00
|
|
|
$this->service = new TemporaryPasswordService($this->connection, $this->hasher);
|
2017-09-27 03:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a temporary password is stored and the token is returned.
|
|
|
|
*/
|
|
|
|
public function testTemporaryPasswordIsStored()
|
|
|
|
{
|
2018-03-05 04:42:33 +00:00
|
|
|
$token = hash_hmac(TemporaryPasswordService::HMAC_ALGO, $this->getKnownUuid(), config('app.key'));
|
2017-09-27 03:16:26 +00:00
|
|
|
|
|
|
|
$this->hasher->shouldReceive('make')->with($token)->once()->andReturn('hashed_token');
|
|
|
|
$this->connection->shouldReceive('table')->with('password_resets')->once()->andReturnSelf();
|
|
|
|
$this->connection->shouldReceive('insert')->with([
|
|
|
|
'email' => 'test@example.com',
|
|
|
|
'token' => 'hashed_token',
|
|
|
|
])->once()->andReturnNull();
|
|
|
|
|
|
|
|
$response = $this->service->handle('test@example.com');
|
|
|
|
$this->assertNotEmpty($response);
|
|
|
|
$this->assertEquals($token, $response);
|
|
|
|
}
|
|
|
|
}
|