Skip to content

Commit

Permalink
CT-1402 - test fix and test also componentAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtabiberle committed Apr 30, 2024
1 parent 68def4a commit f15df6d
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tests/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Keboola\ManageApi\Backend;
use Keboola\ManageApi\Client;
use Keboola\ManageApi\ClientException;
use Keboola\ManageApi\Exception;
use Keboola\ManageApi\ProjectRole;
use Keboola\StorageApi\ClientException as StorageApiClientException;
use Keboola\StorageApi\Options\ListFilesOptions;
Expand Down Expand Up @@ -1149,7 +1150,7 @@ public function testCreateProjectStorageTokenWithBucketPermissions()
$this->assertEquals([$newBucketId => 'read'], $verified['bucketPermissions']);
}

public function testCreateProjectStorageTokenWithMangeTokensPermission()
public function testCreateProjectStorageTokenWithMangeTokensPermissionAndComponentAccess()
{
$organization = $this->client->createOrganization($this->testMaintainerId, [
'name' => 'My org',
Expand All @@ -1159,11 +1160,29 @@ public function testCreateProjectStorageTokenWithMangeTokensPermission()
'name' => 'My test',
]);

try {
// new token with canManageTokens
$this->client->createProjectStorageToken($project['id'], [
'description' => 'test',
'expiresIn' => 60,
'canManageBuckets' => true,
'canReadAllFileUploads' => true,
'canManageTokens' => true,
]);
$this->fail('Should fail.');
} catch (ClientException $e) {
$this->assertEquals(400, $e->getCode());
$this->assertEquals('CanManageTokens is not allowed.', $e->getMessage());
}

$requestedComponents = ['component1', 'component2', 'component3'];

$token = $this->client->createProjectStorageToken($project['id'], [
'description' => 'test',
'expiresIn' => 60,
'canManageBuckets' => true,
'canReadAllFileUploads' => true,
'componentAccess' => $requestedComponents,
]);

$client = $this->getStorageClient([
Expand All @@ -1174,8 +1193,9 @@ public function testCreateProjectStorageTokenWithMangeTokensPermission()
$verified = $client->verifyToken();
$this->assertEquals($project['id'], $verified['owner']['id']);
$this->assertTrue($verified['canManageBuckets']);
$this->assertTrue($verified['canManageTokens']);
$this->assertFalse($verified['canManageTokens']);
$this->assertTrue($verified['canReadAllFileUploads']);
$this->assertEquals($requestedComponents, $verified['componentAccess']);
}

public function testSuperAdminCanDisableAndEnableProject()
Expand Down

0 comments on commit f15df6d

Please sign in to comment.