Skip to content

Commit

Permalink
Merge branch 'feature/PB-25346_v411-release-based' into 'release'
Browse files Browse the repository at this point in the history
Merge branch 'feature/PB-25346_v411-release-based' into 'release'

See merge request passbolt/passbolt-ce-api!150
  • Loading branch information
pabloelcolombiano committed Jul 11, 2023
2 parents ff2deb3 + cdf4566 commit 01d675a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [4.1.1-rc.1] - 2023-07-11
### Fixed
- PB-25325 As an administrator running the database healthcheck I should not see a false fail on the default database content

## [4.1.0] - 2023-06-29
### Added
- PB-24259 As an administrator I can define with role based access control users' rights
Expand Down
4 changes: 2 additions & 2 deletions config/version.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
return [
'passbolt' => [
'version' => '4.1.0',
'name' => 'War Pigs',
'version' => '4.1.1-rc.1',
'name' => 'Insane in the Brain',
]
];
6 changes: 3 additions & 3 deletions src/Model/Table/RolesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
*/
class RolesTable extends Table
{
public const ALLOWED_ROLE_NAMES = [Role::GUEST, Role::USER, Role::ADMIN];

/**
* Initialize method
*
Expand Down Expand Up @@ -114,9 +116,7 @@ public function buildRules(RulesChecker $rules): RulesChecker
*/
public function isValidRoleName(string $roleName): bool
{
$allowedRoleNames = [Role::GUEST, Role::USER, Role::ADMIN];

return in_array($roleName, $allowedRoleNames);
return in_array($roleName, self::ALLOWED_ROLE_NAMES);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Utility/Healthchecks/DatabaseHealthchecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ private static function defaultContent(?array $checks = []): array
{
$checks['database']['defaultContent'] = false;
try {
$roles = TableRegistry::getTableLocator()->get('Roles');
$i = $roles->find('all')->count();
$checks['database']['defaultContent'] = ($i > 3);
$nRoles = TableRegistry::getTableLocator()
->get('Roles')
->find()
->count();
$checks['database']['defaultContent'] = ($nRoles >= 3);
} catch (DatabaseException | MissingConnectionException | \PDOException $e) {
}

Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/Command/HealthcheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
namespace App\Test\TestCase\Command;

use App\Command\HealthcheckCommand;
use App\Model\Table\RolesTable;
use App\Model\Validation\EmailValidationRule;
use App\Test\Factory\RoleFactory;
use App\Test\Lib\AppTestCase;
use App\Test\Lib\Utility\PassboltCommandTestTrait;
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
Expand Down Expand Up @@ -185,4 +187,17 @@ public function testHealthcheckCommand_Database_ConnectionError()
ConnectionManager::alias('test', 'default');
ConnectionManager::drop('invalid');
}

public function testHealthcheckCommand_Database_Happy_Path()
{
RoleFactory::make(RolesTable::ALLOWED_ROLE_NAMES)->persist();

$this->exec('passbolt healthcheck --database');
$this->assertExitSuccess();

$this->assertOutputContains('The application is able to connect to the database');
$this->assertOutputContains('tables found');
$this->assertOutputContains('Some default content is present');
$this->assertOutputContains('The database schema up to date.');
}
}

0 comments on commit 01d675a

Please sign in to comment.