代码同步
This commit is contained in:
@@ -133,6 +133,11 @@ class Common
|
||||
return OssClient::OSS_SIGNATURE_VERSION_V1;
|
||||
}
|
||||
|
||||
public static function getPathStyleBucket()
|
||||
{
|
||||
return getenv('OSS_TEST_PATHSTYLE_BUCKET');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool method, create a bucket
|
||||
*/
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Credentials\StaticCredentialsProvider;
|
||||
use OSS\Model\LifecycleConfig;
|
||||
use OSS\Model\LifecycleRule;
|
||||
use OSS\Model\LifecycleAction;
|
||||
use OSS\Http\RequestCore;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
@@ -18,12 +15,14 @@ class OssClientForcePathStyleTest extends TestOssClientBase
|
||||
{
|
||||
$config = array(
|
||||
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4,
|
||||
'hostType' => OssClient::OSS_HOST_TYPE_PATH_STYLE,
|
||||
'forcePathStyle' => true,
|
||||
);
|
||||
$this->ossClient = Common::getOssClient($config);
|
||||
|
||||
$pathStyleClient = Common::getOssClient($config);
|
||||
|
||||
try {
|
||||
$this->ossClient->getBucketInfo($this->bucket);
|
||||
$pathStyleClient->getBucketInfo($this->bucket);
|
||||
$this->assertTrue(false, "should not here");
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals($e->getErrorCode(), "SecondLevelDomainForbidden");
|
||||
$this->assertTrue(true);
|
||||
@@ -31,7 +30,8 @@ class OssClientForcePathStyleTest extends TestOssClientBase
|
||||
|
||||
try {
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$this->ossClient->putObject($this->bucket, $object, 'hi oss');
|
||||
$pathStyleClient->putObject($this->bucket, $object, 'hi oss');
|
||||
$this->assertTrue(false, "should not here");
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals($e->getErrorCode(), "SecondLevelDomainForbidden");
|
||||
$this->assertTrue(true);
|
||||
@@ -40,11 +40,85 @@ class OssClientForcePathStyleTest extends TestOssClientBase
|
||||
try {
|
||||
$endpoint = Common::getEndpoint();
|
||||
$endpoint = str_replace(array('http://', 'https://'), '', $endpoint);
|
||||
$strUrl = $this->bucket . '.' . $endpoint . "/" . $object;
|
||||
$signUrl = $this->ossClient->signUrl($this->bucket, $object, 3600);
|
||||
$strUrl = $endpoint . "/" . $this->bucket . '/' . $object;
|
||||
$signUrl = $pathStyleClient->signUrl($this->bucket, $object, 3600);
|
||||
$this->assertTrue(strpos($signUrl, $strUrl) !== false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testForcePathStyleOKV1()
|
||||
{
|
||||
$bucket = Common::getPathStyleBucket();
|
||||
|
||||
$this->assertFalse(empty($bucket), "path style bucket is not set.");
|
||||
|
||||
$config = array(
|
||||
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V1,
|
||||
'forcePathStyle' => true,
|
||||
);
|
||||
|
||||
$pathStyleClient = Common::getOssClient($config);
|
||||
|
||||
// bucket
|
||||
$info = $pathStyleClient->getBucketInfo($bucket);
|
||||
$this->assertEquals($bucket, $info->getName());
|
||||
|
||||
// object
|
||||
$object = "upload-test-object-name.txt";
|
||||
$pathStyleClient->putObject($bucket, $object, 'hi oss');
|
||||
$res = $pathStyleClient->getObject($bucket, $object);
|
||||
$this->assertEquals($res, 'hi oss');
|
||||
|
||||
//presign
|
||||
$signUrl = $pathStyleClient->signUrl($bucket, $object, 3600);
|
||||
|
||||
$httpCore = new RequestCore($signUrl);
|
||||
$httpCore->set_body("");
|
||||
$httpCore->set_method("GET");
|
||||
$httpCore->connect_timeout = 10;
|
||||
$httpCore->timeout = 10;
|
||||
$httpCore->add_header("Content-Type", "");
|
||||
$httpCore->send_request();
|
||||
$this->assertEquals(200, $httpCore->response_code);
|
||||
}
|
||||
|
||||
public function testForcePathStyleOKV4()
|
||||
{
|
||||
$bucket = Common::getPathStyleBucket();
|
||||
|
||||
$this->assertFalse(empty($bucket), "path style bucket is not set.");
|
||||
|
||||
$config = array(
|
||||
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4,
|
||||
'forcePathStyle' => true,
|
||||
);
|
||||
|
||||
$pathStyleClient = Common::getOssClient($config);
|
||||
|
||||
// bucket
|
||||
$info = $pathStyleClient->getBucketInfo($bucket);
|
||||
$this->assertEquals($bucket, $info->getName());
|
||||
|
||||
// object
|
||||
$object = "upload-test-object-name.txt";
|
||||
$pathStyleClient->putObject($bucket, $object, 'hi oss');
|
||||
$res = $pathStyleClient->getObject($bucket, $object);
|
||||
$this->assertEquals($res, 'hi oss');
|
||||
|
||||
//presign
|
||||
$signUrl = $pathStyleClient->signUrl($bucket, $object, 3600);
|
||||
|
||||
#print("signUrl" . $signUrl . "\n");
|
||||
|
||||
$httpCore = new RequestCore($signUrl);
|
||||
$httpCore->set_body("");
|
||||
$httpCore->set_method("GET");
|
||||
$httpCore->connect_timeout = 10;
|
||||
$httpCore->timeout = 10;
|
||||
$httpCore->add_header("Content-Type", "");
|
||||
$httpCore->send_request();
|
||||
$this->assertEquals(200, $httpCore->response_code);
|
||||
}
|
||||
}
|
||||
|
||||
70
Server/vendor/aliyuncs/oss-sdk-php/tests/OSS/Tests/OssClientPresignTest.php
vendored
Normal file
70
Server/vendor/aliyuncs/oss-sdk-php/tests/OSS/Tests/OssClientPresignTest.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Credentials\StaticCredentialsProvider;
|
||||
use OSS\Http\RequestCore;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientPresignTest extends TestOssClientBase
|
||||
{
|
||||
protected $stsOssClient;
|
||||
|
||||
public function testObjectWithSignV1()
|
||||
{
|
||||
$config = array(
|
||||
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V1
|
||||
);
|
||||
$this->bucket = Common::getBucketName() . '-' . time();
|
||||
$this->ossClient = Common::getOssClient($config);
|
||||
$this->ossClient->createBucket($this->bucket);
|
||||
Common::waitMetaSync();
|
||||
|
||||
$object = "a.file";
|
||||
$this->ossClient->putObject($this->bucket, $object, "hi oss");
|
||||
$timeout = 3600;
|
||||
$options = array(
|
||||
"response-content-disposition" => "inline"
|
||||
);
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, OssClient::OSS_HTTP_GET, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$this->assertStringContainsString("response-content-disposition=inline", $signedUrl);
|
||||
$options = array(
|
||||
"response-content-disposition" => "attachment",
|
||||
);
|
||||
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, OssClient::OSS_HTTP_GET, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$this->assertStringContainsString("response-content-disposition=attachment", $signedUrl);
|
||||
|
||||
$httpCore = new RequestCore($signedUrl);
|
||||
$httpCore->set_body("");
|
||||
$httpCore->set_method("GET");
|
||||
$httpCore->connect_timeout = 10;
|
||||
$httpCore->timeout = 10;
|
||||
$httpCore->add_header("Content-Type", "");
|
||||
$httpCore->send_request();
|
||||
$this->assertEquals(200, $httpCore->response_code);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->ossClient->deleteObject($this->bucket, "a.file");
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -305,6 +305,49 @@ class OssClientPresignV4Test extends TestOssClientBase
|
||||
}
|
||||
}
|
||||
|
||||
public function testObjectWithSignV4AndResponseQuery()
|
||||
{
|
||||
$config = array(
|
||||
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4
|
||||
);
|
||||
$this->bucket = Common::getBucketName() . '-' . time();
|
||||
$this->ossClient = Common::getOssClient($config);
|
||||
$this->ossClient->createBucket($this->bucket);
|
||||
Common::waitMetaSync();
|
||||
|
||||
$object = "a.file";
|
||||
$this->ossClient->putObject($this->bucket, $object, "hi oss");
|
||||
$timeout = 3600;
|
||||
$options = array(
|
||||
"response-content-disposition" => "inline"
|
||||
);
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, OssClient::OSS_HTTP_GET, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$this->assertStringContainsString("response-content-disposition=inline", $signedUrl);
|
||||
$options = array(
|
||||
"response-content-disposition" => "attachment"
|
||||
);
|
||||
|
||||
try {
|
||||
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, OssClient::OSS_HTTP_GET, $options);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
$this->assertStringContainsString("response-content-disposition=attachment", $signedUrl);
|
||||
|
||||
$httpCore = new RequestCore($signedUrl);
|
||||
$httpCore->set_body("");
|
||||
$httpCore->set_method("GET");
|
||||
$httpCore->connect_timeout = 10;
|
||||
$httpCore->timeout = 10;
|
||||
$httpCore->add_header("Content-Type", "");
|
||||
$httpCore->send_request();
|
||||
$this->assertEquals(200, $httpCore->response_code);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->ossClient->deleteObject($this->bucket, "a.file");
|
||||
|
||||
Reference in New Issue
Block a user