Skip to content

Commit ac9f83a

Browse files
committed
Fix test to run with new bootstrapping
1 parent e8ea218 commit ac9f83a

File tree

3 files changed

+10
-38
lines changed

3 files changed

+10
-38
lines changed

app/Services/Helpers/TemporaryPasswordService.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99

1010
namespace Pterodactyl\Services\Helpers;
1111

12+
use Ramsey\Uuid\Uuid;
1213
use Illuminate\Contracts\Hashing\Hasher;
1314
use Illuminate\Database\ConnectionInterface;
14-
use Illuminate\Contracts\Config\Repository as ConfigRepository;
1515

1616
class TemporaryPasswordService
1717
{
1818
const HMAC_ALGO = 'sha256';
1919

20-
/**
21-
* @var \Illuminate\Contracts\Config\Repository
22-
*/
23-
protected $config;
24-
2520
/**
2621
* @var \Illuminate\Database\ConnectionInterface
2722
*/
@@ -35,16 +30,11 @@ class TemporaryPasswordService
3530
/**
3631
* TemporaryPasswordService constructor.
3732
*
38-
* @param \Illuminate\Contracts\Config\Repository $config
3933
* @param \Illuminate\Database\ConnectionInterface $connection
4034
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
4135
*/
42-
public function __construct(
43-
ConfigRepository $config,
44-
ConnectionInterface $connection,
45-
Hasher $hasher
46-
) {
47-
$this->config = $config;
36+
public function __construct(ConnectionInterface $connection, Hasher $hasher)
37+
{
4838
$this->connection = $connection;
4939
$this->hasher = $hasher;
5040
}
@@ -57,7 +47,7 @@ public function __construct(
5747
*/
5848
public function handle($email)
5949
{
60-
$token = hash_hmac(self::HMAC_ALGO, str_random(40), $this->config->get('app.key'));
50+
$token = hash_hmac(self::HMAC_ALGO, Uuid::uuid4()->toString(), config('app.key'));
6151

6252
$this->connection->table('password_resets')->insert([
6353
'email' => $email,

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
processIsolation="false"
1111
stopOnFailure="false">
1212
<testsuites>
13-
<testsuite name="Feature">
14-
<directory suffix="Test.php">./tests/Feature</directory>
13+
<testsuite name="Integration">
14+
<directory suffix="Test.php">./tests/Integration</directory>
1515
</testsuite>
1616
<testsuite name="Unit">
1717
<directory suffix="Test.php">./tests/Unit</directory>

tests/Unit/Services/Helpers/TemporaryPasswordServiceTest.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
<?php
2-
/*
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Tests\Unit\Services\Helpers;
114

125
use Mockery as m;
136
use Tests\TestCase;
14-
use phpmock\phpunit\PHPMock;
7+
use Tests\Traits\MocksUuids;
158
use Illuminate\Contracts\Hashing\Hasher;
16-
use Illuminate\Contracts\Config\Repository;
179
use Illuminate\Database\ConnectionInterface;
1810
use Pterodactyl\Services\Helpers\TemporaryPasswordService;
1911

2012
class TemporaryPasswordServiceTest extends TestCase
2113
{
22-
use PHPMock;
23-
24-
/**
25-
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
26-
*/
27-
protected $config;
14+
use MocksUuids;
2815

2916
/**
3017
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
@@ -48,23 +35,18 @@ public function setUp()
4835
{
4936
parent::setUp();
5037

51-
$this->config = m::mock(Repository::class);
5238
$this->connection = m::mock(ConnectionInterface::class);
5339
$this->hasher = m::mock(Hasher::class);
5440

55-
$this->service = new TemporaryPasswordService($this->config, $this->connection, $this->hasher);
41+
$this->service = new TemporaryPasswordService($this->connection, $this->hasher);
5642
}
5743

5844
/**
5945
* Test that a temporary password is stored and the token is returned.
6046
*/
6147
public function testTemporaryPasswordIsStored()
6248
{
63-
$this->getFunctionMock('\\Pterodactyl\\Services\\Helpers', 'str_random')
64-
->expects($this->once())->with(40)->willReturn('random_string');
65-
66-
$this->config->shouldReceive('get')->with('app.key')->once()->andReturn('123456');
67-
$token = hash_hmac(TemporaryPasswordService::HMAC_ALGO, 'random_string', '123456');
49+
$token = hash_hmac(TemporaryPasswordService::HMAC_ALGO, $this->getKnownUuid(), config('app.key'));
6850

6951
$this->hasher->shouldReceive('make')->with($token)->once()->andReturn('hashed_token');
7052
$this->connection->shouldReceive('table')->with('password_resets')->once()->andReturnSelf();

0 commit comments

Comments
 (0)