| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace AlibabaCloud\Client\Tests\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\Unit\Credentials\Ini\VirtualRsaKeyPairCredential;
- /**
- * Class RsaKeyPairCredentialTest
- *
- * @package AlibabaCloud\Client\Tests\Feature\Credentials
- */
- class RsaKeyPairCredentialTest extends TestCase
- {
- /**
- * @var string
- */
- private $clientName = 'RsaKeyPairCredentialTest';
- /**
- * @before
- * @throws ClientException
- */
- protected function initialize()
- {
- parent::setUp();
- $regionId = 'ap-northeast-1';
- $publicKeyId = \AlibabaCloud\Client\env('PUBLIC_KEY_ID');
- $privateKeyFile = VirtualRsaKeyPairCredential::privateKeyFileUrl();
- AlibabaCloud::rsaKeyPairClient($publicKeyId, $privateKeyFile)
- ->regionId($regionId)
- ->name($this->clientName);
- }
- /**
- * @after
- * @throws ClientException
- */
- protected function finalize()
- {
- parent::tearDown();
- AlibabaCloud::del($this->clientName);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testGetSessionCredential()
- {
- $this->expectException(ServerException::class);
- $reg = '/InvalidAccessKeyId.NotMatchWithSignatureType/';
- if (method_exists($this, 'expectExceptionMessageMatches')) {
- $this->expectExceptionMessageMatches($reg);
- } elseif (method_exists($this, 'expectExceptionMessageRegExp')) {
- $this->expectExceptionMessageRegExp($reg);
- }
- $credential = AlibabaCloud::get($this->clientName)
- ->getSessionCredential(30, 25);
- // self::assertInstanceOf(StsCredential::class, $credential);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testEcsInJapan()
- {
-
-
- $this->expectException(ServerException::class);
- $reg = '/InvalidAccessKeyId.NotMatchWithSignatureType/';
- if (method_exists($this, 'expectExceptionMessageMatches')) {
- $this->expectExceptionMessageMatches($reg);
- } elseif (method_exists($this, 'expectExceptionMessageRegExp')) {
- $this->expectExceptionMessageRegExp($reg);
- }
- $this->expectException(ServerException::class);
- $reg = '/InvalidAccessKeyId.NotMatchWithSignatureType/';
- if (method_exists($this, 'expectExceptionMessageMatches')) {
- $this->expectExceptionMessageMatches($reg);
- } elseif (method_exists($this, 'expectExceptionMessageRegExp')) {
- $this->expectExceptionMessageRegExp($reg);
- }
- $result = (new DescribeAccessPointsRequest())
- ->client($this->clientName)
- ->connectTimeout(20)
- ->timeout(25)
- ->request();
- // static::assertArrayHasKey('AccessPointSet', $result);
- }
- /**
- * @throws ClientException
- * @throws ServerException
- */
- public function testEcsNotInJapan()
- {
-
- $this->expectException(ServerException::class);
- $reg = '/InvalidAccessKeyId.NotMatchWithSignatureType/';
- if (method_exists($this, 'expectExceptionMessageMatches')) {
- $this->expectExceptionMessageMatches($reg);
- } elseif (method_exists($this, 'expectExceptionMessageRegExp')) {
- $this->expectExceptionMessageRegExp($reg);
- }
- // Setup
- $regionId = \AlibabaCloud\Client\env('REGION_ID', 'cn-hangzhou');
- // Test
- (new DescribeAccessPointsRequest())
- ->client($this->clientName)
- ->regionId($regionId)
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- }
- }
|