StsCredentialTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Credentials;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Credentials\StsCredential;
  6. /**
  7. * Class StsCredentialTest
  8. *
  9. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Credentials
  10. *
  11. * @coversDefaultClass \AlibabaCloud\Client\Credentials\StsCredential
  12. */
  13. class StsCredentialTest extends TestCase
  14. {
  15. /**
  16. * @throws ClientException
  17. */
  18. public function testConstruct()
  19. {
  20. // Setup
  21. $accessKeyId = 'accessKeyId';
  22. $accessKeySecret = 'accessKeySecret';
  23. $securityToken = 'securityToken';
  24. // Test
  25. $credential = new StsCredential($accessKeyId, $accessKeySecret, $securityToken);
  26. // Assert
  27. $this->assertEquals($accessKeyId, $credential->getAccessKeyId());
  28. $this->assertEquals($accessKeySecret, $credential->getAccessKeySecret());
  29. $this->assertEquals($securityToken, $credential->getSecurityToken());
  30. $this->assertEquals(
  31. "$accessKeyId#$accessKeySecret#$securityToken",
  32. (string)$credential
  33. );
  34. }
  35. /**
  36. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  37. * @expectedExceptionMessage AccessKey ID cannot be empty
  38. * @throws ClientException
  39. */
  40. public function testAccessKeyIdEmpty()
  41. {
  42. // Setup
  43. $accessKeyId = '';
  44. $accessKeySecret = 'accessKeySecret';
  45. $securityToken = 'securityToken';
  46. new StsCredential($accessKeyId, $accessKeySecret, $securityToken);
  47. }
  48. /**
  49. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  50. * @expectedExceptionMessage AccessKey ID must be a string
  51. * @throws ClientException
  52. */
  53. public function testAccessKeyIdFormat()
  54. {
  55. // Setup
  56. $accessKeyId = null;
  57. $accessKeySecret = 'accessKeySecret';
  58. $securityToken = 'securityToken';
  59. new StsCredential($accessKeyId, $accessKeySecret, $securityToken);
  60. }
  61. /**
  62. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  63. * @expectedExceptionMessage AccessKey Secret cannot be empty
  64. * @throws ClientException
  65. */
  66. public function testAccessKeySecretEmpty()
  67. {
  68. // Setup
  69. $accessKeyId = 'accessKeyId';
  70. $accessKeySecret = '';
  71. $securityToken = 'securityToken';
  72. new StsCredential($accessKeyId, $accessKeySecret, $securityToken);
  73. }
  74. /**
  75. * @expectedException \AlibabaCloud\Client\Exception\ClientException
  76. * @expectedExceptionMessage AccessKey Secret must be a string
  77. * @throws ClientException
  78. */
  79. public function testAccessKeySecretFormat()
  80. {
  81. // Setup
  82. $accessKeyId = 'accessKeyId';
  83. $accessKeySecret = null;
  84. $securityToken = 'securityToken';
  85. new StsCredential($accessKeyId, $accessKeySecret, $securityToken);
  86. }
  87. }