Update random ID method to use str_random and not random_bytes
The use of random_bytes in combination with bin2hex was producing a lot of duplicate keys when tested in batches of 10k (anywhere from 2 to 6). The use of str_random yielded no duplicates even at scales of 100k keys that were 8 characters.
This commit is contained in:
parent
0e518be6ca
commit
a8c4d6afdb
14 changed files with 50 additions and 59 deletions
|
@ -33,7 +33,6 @@ use Pterodactyl\Models\Node;
|
|||
use GuzzleHttp\Exception\RequestException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Services\Nodes\NodeUpdateService;
|
||||
use Pterodactyl\Services\Nodes\NodeCreationService;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
|
||||
|
||||
|
@ -97,20 +96,13 @@ class NodeUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testNodeIsUpdatedAndDaemonSecretIsReset()
|
||||
{
|
||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'random_bytes')
|
||||
->expects($this->once())->willReturnCallback(function ($bytes) {
|
||||
$this->assertEquals(NodeCreationService::DAEMON_SECRET_LENGTH, $bytes);
|
||||
|
||||
return '\00';
|
||||
});
|
||||
|
||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'bin2hex')
|
||||
->expects($this->once())->willReturn('hexResponse');
|
||||
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'str_random')
|
||||
->expects($this->once())->willReturn('random_string');
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
'daemonSecret' => 'hexResponse',
|
||||
'daemonSecret' => 'random_string',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andReturnSelf()
|
||||
|
|
Reference in a new issue