Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ci/apiv2/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ def test_patch_color_null(self):
obj = Task.objects.get(taskId=task.id)
self.assertIsNone(obj.color)

def test_runtime(self):
def test_runtime_preprocessor(self):
task = self.create_test_object(file_id='002')

obj = Task.objects.get(taskId=task.id)
self.assertEqual(obj.useNewBench, 1)

def test_runtime(self):
task = self.create_test_object(file_id='004')

obj = Task.objects.get(taskId=task.id)
self.assertEqual(obj.useNewBench, 0)

Expand Down
22 changes: 22 additions & 0 deletions ci/apiv2/testfiles/task/create_task_004.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"attackCmd": "#HL# -a 0 ad a1",
"chunkSize": 1000,
"chunkTime": 600,
"color": "7C6EFF",
"crackerBinaryId": 1,
"forcePipe": true,
"files": [],
"isArchived": false,
"isCpuTask": false,
"isSmall": false,
"maxAgents": 112,
"notes": "example-note",
"preprocessorCommand": "",
"priority": 10,
"skipKeyspace": 500,
"staticChunks": 2,
"statusTimer": 5,
"taskName": "Example - runtime",
"useNewBench": false,
"preprocessorId": 0
}
40 changes: 40 additions & 0 deletions ci/phpunit/dba/AbstractModelFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function testUpdateModelSuccessMultipleChanges(): void {
*/
public function testMsetSuccess(): void {
$hashType = $this->createDatabaseObject(Factory::getHashTypeFactory(), new HashType(null, 'placeholder', 0, 0));
$this->assertInstanceOf(HashType::class, $hashType);
Factory::getHashTypeFactory()->mset($hashType, [HashType::IS_SALTED => 1, HashType::IS_SLOW_HASH => 1]);
$hashTypeUpdated = Factory::getHashTypeFactory()->get($hashType->getId());
$this->assertEquals(1, $hashTypeUpdated->getIsSalted());
Expand Down Expand Up @@ -259,6 +260,7 @@ public function testMsetSuccessTwoObjects(): void {
*/
public function testSetSuccess(): void {
$hashType = $this->createDatabaseObject(Factory::getHashTypeFactory(), new HashType(null, 'placeholder', 0, 0));
$this->assertTrue($hashType instanceof HashType);
Factory::getHashTypeFactory()->set($hashType, HashType::IS_SALTED, 1);
$hashTypeUpdated = Factory::getHashTypeFactory()->get($hashType->getId());
$this->assertEquals(1, $hashTypeUpdated->getIsSalted());
Expand Down Expand Up @@ -294,6 +296,38 @@ public function testSetSuccessTwoObjects(): void {
$this->assertEquals('something else', $hashTypeUpdated->getDescription());
}

/**
* Tests that set() replaces the by-ref model with a new instance of the correct concrete type
*
* @return void
* @throws Exception
*/
public function testSetRefreshesModel(): void {
$hashType = $this->createDatabaseObject(Factory::getHashTypeFactory(), new HashType(null, 'placeholder', 0, 0));
$this->assertInstanceOf(HashType::class, $hashType);
$originalObject = $hashType;
$hashType = Factory::getHashTypeFactory()->set($hashType, HashType::IS_SALTED, 1);
$this->assertNotSame($originalObject, $hashType);
$this->assertEquals(1, $hashType->getIsSalted());
$this->assertEquals(0, $hashType->getIsSlowHash());
}

/**
* Tests that mset() replaces the by-ref model with a new instance of the correct concrete type
*
* @return void
* @throws Exception
*/
public function testMsetRefreshesModel(): void {
$hashType = $this->createDatabaseObject(Factory::getHashTypeFactory(), new HashType(null, 'placeholder', 0, 0));
$this->assertInstanceOf(HashType::class, $hashType);
$originalObject = $hashType;
$hashType = Factory::getHashTypeFactory()->mset($hashType, [HashType::IS_SALTED => 1, HashType::IS_SLOW_HASH => 1]);
$this->assertNotSame($originalObject, $hashType);
$this->assertEquals(1, $hashType->getIsSalted());
$this->assertEquals(1, $hashType->getIsSlowHash());
}

/**
* Tests if values with inc() are set properly
*
Expand Down Expand Up @@ -333,11 +367,13 @@ public function testIncSuccessTwoObjects(): void {

Factory::getHashTypeFactory()->inc($hashType1, HashType::IS_SALTED, 2);

$this->assertTrue($hashType1 instanceof HashType);
$this->assertEquals(3, $hashType1->getIsSalted());
$this->assertEquals(1, $hashType2->getIsSalted());

Factory::getHashTypeFactory()->inc($hashType2, HashType::IS_SALTED, 20);

$this->assertTrue($hashType2 instanceof HashType);
$this->assertEquals(23, $hashType2->getIsSalted());

$hashTypeUpdated = Factory::getHashTypeFactory()->get($hashType1->getId());
Expand Down Expand Up @@ -407,11 +443,13 @@ public function testDecSuccessTwoObjects(): void {

Factory::getHashTypeFactory()->dec($hashType1, HashType::IS_SALTED, 2);

$this->assertTrue($hashType1 instanceof HashType);
$this->assertEquals(48, $hashType1->getIsSalted());
$this->assertEquals(50, $hashType2->getIsSalted());

Factory::getHashTypeFactory()->dec($hashType2, HashType::IS_SALTED, 20);

$this->assertTrue($hashType2 instanceof HashType);
$this->assertEquals(28, $hashType2->getIsSalted());

$hashTypeUpdated = Factory::getHashTypeFactory()->get($hashType1->getId());
Expand Down Expand Up @@ -1315,6 +1353,7 @@ public function testFilterWithJoinOverrideOwnFactory(): void {

$accessGroup = $this->createDatabaseObject(Factory::getAccessGroupFactory(), new AccessGroup(null, 'ag_' . $testId));
$this->createDatabaseObject(Factory::getFileFactory(), new File(null, 'file_' . $testId, 1, 0, 0, $accessGroup->getId(), 1));
$this->assertTrue($accessGroup instanceof AccessGroup);

$qF = new QueryFilter(AccessGroup::GROUP_NAME, $accessGroup->getGroupName(), '=', Factory::getAccessGroupFactory());
$jF = new JoinFilter(
Expand All @@ -1341,6 +1380,7 @@ public function testFilterWithJoinQueryFilters(): void {
$accessGroup = $this->createDatabaseObject(Factory::getAccessGroupFactory(), new AccessGroup(null, 'ag_' . $testId));
$this->createDatabaseObject(Factory::getFileFactory(), new File(null, 'file1_' . $testId, 1, 0, 0, $accessGroup->getId(), 1));
$this->createDatabaseObject(Factory::getFileFactory(), new File(null, 'file2_' . $testId, 2, 0, 0, $accessGroup->getId(), 1));
$this->assertTrue($accessGroup instanceof AccessGroup);

$qF = new QueryFilter(AccessGroup::GROUP_NAME, $accessGroup->getGroupName(), '=', Factory::getAccessGroupFactory());
$jF = new JoinFilter(
Expand Down
2 changes: 1 addition & 1 deletion ci/phpunit/inc/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ public function testGetUsernameById(): void {
*/
public function testGetUsernameByIdNotFound(): void {
$result = Util::getUsernameById(99999999);
$this->assertEquals("-99999999", $result);
$this->assertEquals("Unknown-99999999", $result);
}

/**
Expand Down
7 changes: 0 additions & 7 deletions ci/phpunit/inc/utils/ChunkUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ public static function invalidBenchmarkCases(): array {
];
}

// Verifies that a benchmark string with no colon routes to the old-benchmark
// path and PHP 8 throws TypeError on arithmetic with a non-numeric string.
public function testOldBenchmarkNonNumericStringThrowsTypeError(): void {
$this->expectException(\TypeError::class);
ChunkUtils::calculateChunkSize(1000000, 'invalid', 60);
}

// Verifies the safety floor: when the formula produces a size <= 0 the result
// is clamped to 1 so dispatching never stalls on an infinite zero-size loop.
// $QUERY must be set because the clamp path calls Util::createLogEntry which
Expand Down
12 changes: 6 additions & 6 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
parameters:
paths:
- src/inc/apiv2
- ci/phpunit
level: 4
treatPhpDocTypesAsCertain: false
scanDirectories:
- src/dba
- src/inc
- ci/phpunit
level: 4
treatPhpDocTypesAsCertain: false
excludePaths:
# Exclude the DBA tests due PHPStan doing weird complaints
- ci/phpunit/dba/AbstractModelFactoryTest.php
# this is deprecated/legacy and will not be touched until remove
- src/inc/Auth_Yubico.php
- src/inc/Login.php
7 changes: 6 additions & 1 deletion src/dba/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ abstract function getPrimaryKeyValue();
/**
* This function is used to set the id to the real database value
* @param $id string
* @return
* @return void
*/
abstract function setId(string $id): void;

/**
* this function returns the models id
*/
abstract function getId();

/**
* The function is used to retrieve information about the attributes of the model
*/
abstract static function getFeatures();
}
Loading
Loading