Skip to content

Commit

Permalink
release 1.3.0 (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
宋神宗 authored Apr 18, 2019
1 parent c3ddbd0 commit 5145cf5
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 13 deletions.
30 changes: 18 additions & 12 deletions src/Request/RoaRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,15 @@ private function resolveContentType()
*/
private function resolveSecurityToken()
{
if ($this->credential() instanceof StsCredential && $this->credential()->getSecurityToken()) {
$this->options['headers']['x-acs-security-token'] = $this->credential()->getSecurityToken();
if (!$this->credential() instanceof StsCredential) {
return;
}

if (!$this->credential()->getSecurityToken()) {
return;
}

$this->options['headers']['x-acs-security-token'] = $this->credential()->getSecurityToken();
}

/**
Expand All @@ -202,16 +208,16 @@ private function signature()
/**
* @var AccessKeyCredential $credential
*/
$credential = $this->credential();
$accessKeyId = $credential->getAccessKeyId();
$signature = $this->httpClient()
->getSignature()
->sign(
$this->stringToSign(),
$credential->getAccessKeySecret()
);

return "acs $accessKeyId:$signature";
$credential = $this->credential();
$access_key_id = $credential->getAccessKeyId();
$signature = $this->httpClient()
->getSignature()
->sign(
$this->stringToSign(),
$credential->getAccessKeySecret()
);

return "acs $access_key_id:$signature";
}

/**
Expand Down
92 changes: 92 additions & 0 deletions tests/Unit/Filter/HttpFilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace AlibabaCloud\Client\Tests\Unit\Filter;

use PHPUnit\Framework\TestCase;
use AlibabaCloud\Client\Filter\HttpFilter;
use AlibabaCloud\Client\Exception\ClientException;

class HttpFilterTest extends TestCase
{
/**
* @dataProvider contentType
*
* @param $expected
* @param $contentType
* @param $exceptionMessage
*/
public function testContentType($expected, $contentType, $exceptionMessage)
{
try {
self::assertEquals($expected, HttpFilter::contentType($contentType));
} catch (ClientException $exception) {
self::assertEquals($exceptionMessage, $exception->getMessage());
}
}

/**
* @return array
*/
public function contentType()
{
return [
[
'',
'',
'Content-Type cannot be empty',
],
[
1,
1,
'Content-Type must be a string',
],
[
'a',
'a',
'a',
],
];
}


/**
* @dataProvider accept
*
* @param $expected
* @param $contentType
* @param $exceptionMessage
*/
public function testAccept($expected, $contentType, $exceptionMessage)
{
try {
self::assertEquals($expected, HttpFilter::accept($contentType));
} catch (ClientException $exception) {
self::assertEquals($exceptionMessage, $exception->getMessage());
}
}


/**
* @return array
*/
public function accept()
{
return [
[
'',
'',
'Accept cannot be empty',
],
[
1,
1,
'Accept must be a string',
],
[
'a',
'a',
'a',
],
];
}
}
21 changes: 21 additions & 0 deletions tests/Unit/Request/RoaRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,25 @@ public function testResolveSecurityToken()
// Assert
self::assertEquals('token', $request->options['headers']['x-acs-security-token']);
}

/**
* @covers \AlibabaCloud\Client\Request\RoaRequest::resolveSecurityToken
* @throws ReflectionException
* @throws ClientException
*/
public function testNoSecurityToken()
{
// Setup
$request = AlibabaCloud::roa();
$object = new ReflectionObject($request);
AlibabaCloud::stsClient('foo', 'bar')->asDefaultClient();

// Test
$method = $object->getMethod('resolveSecurityToken');
$method->setAccessible(true);
$method->invoke($request);

// Assert
self::assertFalse(isset($request->options['headers']['x-acs-security-token']));
}
}
21 changes: 21 additions & 0 deletions tests/Unit/Request/RpcRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,25 @@ public function testResolveSecurityToken()
// Assert
self::assertEquals('token', $request->options['query']['SecurityToken']);
}

/**
* @covers \AlibabaCloud\Client\Request\RoaRequest::resolveSecurityToken
* @throws ReflectionException
* @throws ClientException
*/
public function testNoSecurityToken()
{
// Setup
$request = AlibabaCloud::rpc();
$object = new ReflectionObject($request);
AlibabaCloud::stsClient('foo', 'bar')->asDefaultClient();

// Test
$method = $object->getMethod('resolveSecurityToken');
$method->setAccessible(true);
$method->invoke($request);

// Assert
self::assertFalse(isset($request->options['query']['SecurityToken']));
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Request/Traits/ClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testHttpClientWithCustomChain()
$name = 'testHttpClientWithCustomChain';
AlibabaCloud::flush();
CredentialsProvider::chain(
static function() use ($name) {
static function () use ($name) {
AlibabaCloud::ecsRamRoleClient('role')->name($name);
}
);
Expand Down

0 comments on commit 5145cf5

Please sign in to comment.