BearerTokenCredentialTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Credentials;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\AlibabaCloud;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use AlibabaCloud\Client\Exception\ClientException;
  7. use AlibabaCloud\Client\Tests\Mock\Services\CCC\ListPhoneNumbersRequest;
  8. use AlibabaCloud\Client\Tests\Mock\Services\Cdn\DescribeCdnServiceRequest;
  9. use AlibabaCloud\Client\Tests\Mock\Services\Ecs\DescribeAccessPointsRequest;
  10. /**
  11. * Class BearerTokenCredentialTest
  12. *
  13. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Credentials
  14. */
  15. class BearerTokenCredentialTest extends TestCase
  16. {
  17. /**
  18. * @var string
  19. */
  20. protected $clientName = 'BearerTokenCredentialTest';
  21. /**
  22. * @throws ClientException
  23. */
  24. public function setUp()
  25. {
  26. $regionId = 'cn-hangzhou';
  27. $bearerToken =
  28. 'eyJhbGciOiJSUzI1NiIsImsyaWQiOiJlNE92NnVOUDhsMEY2RmVUMVhvek5wb1NBcVZLblNGRyIsImtpZCI6IkpDOXd4enJocUowZ3RhQ0V0MlFMVWZldkVVSXdsdEZodWk0TzFiaDY3dFUifQ.N3plS0w2cm83YzhtVzJqSkI0U0JIMldzNW45cFBOSWdNellvQ3VpZGV5NzRVOHNsMkJUWTVULzl3RDdkbzhHQkorM3dvclg1SGY1STZXL1FjaVhLVnc5ck5YeVNYanBuK2N6UkN1SnRRc3FRMGJIVTF4cVVjUDVRNUJpK2JsSWxZdlowZ2VWSzYvS2pzcVNjWHJLSlVvWkNnWE0wWGJZZ0NCVm1BUlNXS1plUnNzdnAvUmwwV01tSFFkWmlOMGtKV0o5TllQU3M0QU1aenpHVTdUY1BnYlhIVy9uTmdMY1JVSytROXlrPQ.kvZes7-6IU-xjOzK1goPPjODz1XLt73yCmDLSpRwzlz3d9A_uYvbQK0HHltVKo0K0dI0wJOfpCeOHJlrV0m4RI4bynL9ltl31rscPhQ-G4Ybqw4KXVBZCIzjSqzWcniIWnGWl-TpOy0Y7sAcJmp0Lg2ndu_shGqiTP6DTVBNV8f94mveHmRqouLxr2OKMvCyxTV1zUEJmC-JnZaljfNG-i483qG8Hm60CwAjM91FTGib3eXGzjJa3XOOY7zpZTrvahBYFpyrVhRuvDvRs6tLKVAL_7bYwCIo_tdh9rhRmFtyq0k2iykZQJmAIlDMt-VENP7hJTH62uUQzNLQ28ISTQ';
  29. AlibabaCloud::bearerTokenClient($bearerToken)
  30. ->regionId($regionId)
  31. ->name($this->clientName);
  32. }
  33. /**
  34. * @throws ClientException
  35. */
  36. public function tearDown()
  37. {
  38. AlibabaCloud::del($this->clientName);
  39. }
  40. /**
  41. * @throws ClientException
  42. */
  43. public function testCCC()
  44. {
  45. try {
  46. (new ListPhoneNumbersRequest())
  47. ->client($this->clientName)
  48. ->withInstanceId(\getenv('CC_INSTANCE_ID'))
  49. ->withOutboundOnly(true)
  50. ->scheme('https')
  51. ->host('ccc.cn-shanghai.aliyuncs.com')
  52. ->options([
  53. 'verify' => false,
  54. ])
  55. ->connectTimeout(25)
  56. ->timeout(30)
  57. ->request();
  58. } catch (ServerException $e) {
  59. $result = $e->getResult();
  60. self::assertEquals(
  61. 'InvalidBearerTokenException: Bearertoken has expired',
  62. $result['Message']
  63. );
  64. }
  65. }
  66. /**
  67. * @expectedException \AlibabaCloud\Client\Exception\ServerException
  68. * @expectedExceptionMessageRegExp /UnsupportedSignatureType: This signature type is not supported./
  69. * @throws ClientException
  70. */
  71. public function testEcs()
  72. {
  73. (new DescribeAccessPointsRequest())
  74. ->client($this->clientName)
  75. ->connectTimeout(25)
  76. ->timeout(30)
  77. ->request();
  78. }
  79. /**
  80. * @expectedException \AlibabaCloud\Client\Exception\ServerException
  81. * @expectedExceptionMessageRegExp /UnsupportedSignatureType: This signature type is not supported./
  82. * @throws ClientException
  83. */
  84. public function testCdn()
  85. {
  86. (new DescribeCdnServiceRequest())->client($this->clientName)
  87. ->connectTimeout(25)
  88. ->timeout(30)
  89. ->request();
  90. }
  91. }