-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add isEnableIMDSv2 && update IMDSv2 doc for ecs ram role
- Loading branch information
Showing
54 changed files
with
2,801 additions
and
80 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
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,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="tests/bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
logIncompleteSkipped="true" | ||
testSuiteLoaderFile="phpunit/src/Runner/StandardTestSuiteLoader.php"> | ||
|
||
<testsuites> | ||
<testsuite name="All"> | ||
<directory>tests/HigherthanorEqualtoVersion7_2</directory> | ||
</testsuite> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/HigherthanorEqualtoVersion7_2/Unit</directory> | ||
</testsuite> | ||
|
||
<testsuite name="Feature"> | ||
<directory suffix="Test.php">./tests/HigherthanorEqualtoVersion7_2/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<groups> | ||
<exclude> | ||
<group>integration</group> | ||
</exclude> | ||
</groups> | ||
|
||
<logging> | ||
<log type="coverage-html" target="cache/coverage" lowUpperBound="35" highLowerBound="70"/> | ||
<log type="coverage-clover" target="cache/coverage.clover"/> | ||
</logging> | ||
</phpunit> |
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
148 changes: 148 additions & 0 deletions
148
tests/HigherthanorEqualtoVersion7_2/Feature/CredentialTest.php
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,148 @@ | ||
<?php | ||
|
||
namespace AlibabaCloud\Credentials\Tests\HigherthanorEqualtoVersion7_2\Feature; | ||
|
||
use AlibabaCloud\Credentials\Credential; | ||
use AlibabaCloud\Credentials\Credentials; | ||
use AlibabaCloud\Credentials\Helper; | ||
use AlibabaCloud\Credentials\Tests\HigherthanorEqualtoVersion7_2\Unit\Ini\VirtualRsaKeyPairCredential; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionException; | ||
|
||
/** | ||
* Class CredentialTest | ||
* | ||
* @package AlibabaCloud\Credentials\Tests\HigherthanorEqualtoVersion7_2\Feature | ||
*/ | ||
class CredentialTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @throws ReflectionException | ||
*/ | ||
public function testAccessKey() | ||
{ | ||
$config = new Credential\Config([ | ||
'type' => 'access_key', | ||
'accessKeyId' => 'foo', | ||
'accessKeySecret' => 'bar', | ||
]); | ||
$credential = new Credential($config); | ||
|
||
// Assert | ||
$this->assertEquals('foo', $credential->getAccessKeyId()); | ||
$this->assertEquals('bar', $credential->getAccessKeySecret()); | ||
$this->assertEquals('access_key', $credential->getType()); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @throws ReflectionException | ||
* @expectedException \GuzzleHttp\Exception\ConnectException | ||
* @expectedExceptionMessageRegExp /timed/ | ||
*/ | ||
public function testEcsRamRoleCredential() | ||
{ | ||
$config = new Credential\Config([ | ||
'type' => 'ecs_ram_role', | ||
'roleName' => 'foo', | ||
'enableIMDSv2' => true, | ||
]); | ||
$credential = new Credential($config); | ||
|
||
// Assert | ||
$this->assertEquals('foo', $credential->getRoleName()); | ||
$this->assertEquals('ecs_ram_role', $credential->getType()); | ||
$this->assertTrue($credential->isEnableIMDSv2()); | ||
$credential->getAccessKeySecret(); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @throws ReflectionException | ||
*/ | ||
public function testRamRoleArnCredential() | ||
{ | ||
Credentials::cancelMock(); | ||
$config = new Credential\Config([ | ||
'type' => 'ram_role_arn', | ||
'accessKeyId' => Helper::envNotEmpty('ACCESS_KEY_ID'), | ||
'accessKeySecret' => Helper::envNotEmpty('ACCESS_KEY_SECRET'), | ||
'roleArn' => Helper::envNotEmpty('ROLE_ARN'), | ||
'roleSessionName' => 'role_session_name', | ||
'policy' => '', | ||
]); | ||
|
||
$credential = new Credential($config); | ||
|
||
// Assert | ||
$this->assertTrue(null !== $credential->getAccessKeyId()); | ||
$this->assertTrue(null !== $credential->getAccessKeySecret()); | ||
$this->assertEquals('ram_role_arn', $credential->getType()); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @throws ReflectionException | ||
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage Specified access key type is not match with signature type. | ||
*/ | ||
public function testRsaKeyPairCredential() | ||
{ | ||
Credentials::cancelMock(); | ||
$publicKeyId = Helper::envNotEmpty('PUBLIC_KEY_ID'); | ||
$privateKeyFile = VirtualRsaKeyPairCredential::privateKeyFileUrl(); | ||
$config = new Credential\Config([ | ||
'type' => 'rsa_key_pair', | ||
'publicKeyId' => $publicKeyId, | ||
'privateKeyFile' => $privateKeyFile, | ||
]); | ||
$credential = new Credential($config); | ||
|
||
// Assert | ||
$this->assertTrue(null !== $credential->getAccessKeyId()); | ||
$this->assertTrue(null !== $credential->getAccessKeySecret()); | ||
$this->assertEquals('rsa_key_pair', $credential->getType()); | ||
$credential->getAccessKeySecret(); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @throws ReflectionException | ||
*/ | ||
public function testSTS() | ||
{ | ||
$config = new Credential\Config([ | ||
'type' => 'sts', | ||
'accessKeyId' => 'foo', | ||
'accessKeySecret' => 'bar', | ||
'securityToken' => 'token', | ||
]); | ||
$credential = new Credential($config); | ||
|
||
// Assert | ||
$this->assertEquals('foo', $credential->getAccessKeyId()); | ||
$this->assertEquals('bar', $credential->getAccessKeySecret()); | ||
$this->assertEquals('token', $credential->getSecurityToken()); | ||
$this->assertEquals('sts', $credential->getType()); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @throws ReflectionException | ||
*/ | ||
public function testBearerToken() | ||
{ | ||
$config = new Credential\Config([ | ||
'type' => 'bearer', | ||
'bearerToken' => 'token', | ||
]); | ||
$credential = new Credential($config); | ||
|
||
// Assert | ||
$this->assertEquals('token', $credential->getBearerToken()); | ||
$this->assertEquals('bearer', $credential->getType()); | ||
} | ||
} |
Oops, something went wrong.