123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Credentials;
- use PHPUnit\Framework\TestCase;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use AlibabaCloud\Client\Credentials\StsCredential;
- use AlibabaCloud\Client\Tests\Mock\Services\Ecs\DescribeAccessPointsRequest;
- use AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Credentials\Ini\VirtualRsaKeyPairCredential;
- /**
- * Class RsaKeyPairCredentialTest
- *
- * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Credentials
- */
- class RsaKeyPairCredentialTest extends TestCase
- {
- /**
- * @var string
- */
- private $clientName = 'RsaKeyPairCredentialTest';
- /**
- * @throws ClientException
- */
- public function setUp()
- {
- $regionId = 'ap-northeast-1';
- $publicKeyId = \AlibabaCloud\Client\env('PUBLIC_KEY_ID');
- $privateKeyFile = VirtualRsaKeyPairCredential::privateKeyFileUrl();
- AlibabaCloud::rsaKeyPairClient($publicKeyId, $privateKeyFile)
- ->regionId($regionId)
- ->name($this->clientName);
- }
- /**
- * @throws ClientException
- */
- public function tearDown()
- {
- AlibabaCloud::del($this->clientName);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /NoPermission: You are not authorized to do this action. You should be authorized by RAM./
- * @throws ClientException
- * @throws ServerException
- */
- public function testGetSessionCredential()
- {
- $credential = AlibabaCloud::get($this->clientName)
- ->getSessionCredential(30, 25);
- self::assertInstanceOf(StsCredential::class, $credential);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /NoPermission: You are not authorized to do this action. You should be authorized by RAM./
- * @throws ClientException
- * @throws ServerException
- */
- public function testEcsInJapan()
- {
- $result = (new DescribeAccessPointsRequest())
- ->client($this->clientName)
- ->connectTimeout(20)
- ->timeout(25)
- ->request();
- static::assertArrayHasKey('AccessPointSet', $result);
- }
- /**
- * @expectedException \AlibabaCloud\Client\Exception\ServerException
- * @expectedExceptionMessageRegExp /NoPermission: You are not authorized to do this action. You should be authorized by RAM./
- * @throws ClientException
- * @throws ServerException
- */
- public function testEcsNotInJapan()
- {
- // Setup
- $regionId = \AlibabaCloud\Client\env('REGION_ID', 'cn-hangzhou');
- // Test
- (new DescribeAccessPointsRequest())
- ->client($this->clientName)
- ->regionId($regionId)
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- }
- }
|