-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
SOX-78 tokens
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Keboola\Test\Backend\SOX; | ||
|
||
use Generator; | ||
use Keboola\StorageApi\Client; | ||
use Keboola\StorageApi\ClientException; | ||
use Keboola\StorageApi\Tokens; | ||
use Keboola\Test\StorageApiTestCase; | ||
|
||
class SOXTokensTest extends StorageApiTestCase | ||
{ | ||
private function getDefaultBranchTokenId(): int | ||
{ | ||
[, $tokenId,] = explode('-', STORAGE_API_DEFAULT_BRANCH_TOKEN); | ||
return (int) $tokenId; | ||
} | ||
|
||
public function tokensProvider(): Generator | ||
{ | ||
yield 'nobody can see token (privileged)' => [ | ||
$this->getDefaultBranchStorageApiClient(), | ||
]; | ||
yield 'nobody can see token (productionManager)' => [ | ||
$this->getDefaultClient(), | ||
]; | ||
yield 'nobody can see token (developer)' => [ | ||
$this->getDeveloperStorageApiClient(), | ||
]; | ||
yield 'nobody can see token (reviewer)' => [ | ||
$this->getReviewerStorageApiClient(), | ||
]; | ||
yield 'nobody can see token (readOnly)' => [ | ||
$this->getReadOnlyStorageApiClient(), | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider tokensProvider | ||
*/ | ||
public function testTokensVisibility(Client $client): void | ||
{ | ||
$tokens = new Tokens($client); | ||
$tokenList = $tokens->listTokens(); | ||
foreach ($tokenList as $token) { | ||
// check all tokens are without decrypted token | ||
$this->assertArrayNotHasKey('token', $token); | ||
} | ||
|
||
$token = $client->verifyToken(); | ||
// not visible in detail | ||
$this->assertArrayNotHasKey('token', $token); | ||
} | ||
|
||
public function testCannotRefreshCanManageProtectedBranchTokenEvenSelf(): void | ||
{ | ||
$client = $this->getDefaultBranchStorageApiClient(); | ||
$tokens = new Tokens($client); | ||
$this->expectExceptionCode(400); | ||
$this->expectExceptionMessage('Token with canManageProtectedDefaultBranch privilege cannot be refreshed'); | ||
$tokens->refreshToken($this->getDefaultBranchTokenId()); | ||
} | ||
|
||
/** | ||
* @dataProvider tokensProvider | ||
*/ | ||
public function testCannotShareCanManageProtectedBranchTokenEvenSelf(Client $client): void | ||
{ | ||
$tokens = new Tokens($client); | ||
try { | ||
$tokens->shareToken( | ||
$this->getDefaultBranchTokenId(), | ||
'test@devel.keboola.com', | ||
'hi' | ||
); | ||
$this->fail('Nobody can do this.'); | ||
} catch (ClientException $e) { | ||
$this->assertSame(403, $e->getCode()); | ||
$this->assertSame('You don\'t have access to the resource.', $e->getMessage()); | ||
} | ||
} | ||
} |