Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/Models/CipherSuite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace AlibabaCloud\Oss\V2\Models;

use AlibabaCloud\Oss\V2\Types\Model;
use AlibabaCloud\Oss\V2\Annotation\XmlElement;
use AlibabaCloud\Oss\V2\Annotation\XmlRoot;

/**
* Class CipherSuite
* @package AlibabaCloud\Oss\V2\Models
*/
#[XmlRoot(name: 'CipherSuite')]
final class CipherSuite extends Model
{
/**
* @var bool|null
*/
#[XmlElement(rename: 'Enable', type: 'bool')]
public ?bool $enable;

/**
* @var bool|null
*/
#[XmlElement(rename: 'StrongCipherSuite', type: 'bool')]
public ?bool $strongCipherSuite;

/**
* @var array<string>|null
*/
#[XmlElement(rename: 'CustomCipherSuite', type: 'string')]
public ?array $customCipherSuites;

/**
* @var array<string>|null
*/
#[XmlElement(rename: 'TLS13CustomCipherSuite', type: 'string')]
public ?array $tls13CustomCipherSuites;

/**
* CipherSuite constructor.
* @param bool|null $enable
* @param bool|null $strongCipherSuite
* @param array<string>|null $customCipherSuites
* @param array<string>|null $tls13CustomCipherSuites
*/
public function __construct(
?bool $enable = null,
?bool $strongCipherSuite = null,
?array $customCipherSuites = null,
?array $tls13CustomCipherSuites = null
)
{
$this->enable = $enable;
$this->strongCipherSuite = $strongCipherSuite;
$this->customCipherSuites = $customCipherSuites;
$this->tls13CustomCipherSuites = $tls13CustomCipherSuites;
}
}
10 changes: 9 additions & 1 deletion src/Models/HttpsConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ final class HttpsConfiguration extends Model
#[XmlElement(rename: 'TLS', type: TLS::class)]
public ?TLS $tls;

/**
* @var CipherSuite|null
*/
#[XmlElement(rename: 'CipherSuite', type: CipherSuite::class)]
public ?CipherSuite $cipherSuite;

/**
* HttpsConfiguration constructor.
* @param TLS|null $tls The container that stores TLS version configurations.
* @param CipherSuite|null $cipherSuite
*/
public function __construct(
?TLS $tls = null
?TLS $tls = null,
?CipherSuite $cipherSuite = null
)
{
$this->tls = $tls;
$this->cipherSuite = $cipherSuite;
}
}
30 changes: 30 additions & 0 deletions tests/IntegrationTests/ClientBucketHttpsConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ public function testBucketHttpsConfig()
$this->assertEquals('OK', $getResult->status);
$this->assertEquals(True, count($getResult->headers) > 0);
$this->assertEquals(24, strlen($getResult->requestId));

// PutBucketHttpsConfig
$putResult = $client->putBucketHttpsConfig(new Oss\Models\PutBucketHttpsConfigRequest(
$bucketName,
new Oss\Models\HttpsConfiguration(
tls: new Oss\Models\TLS(
tlsVersions: ['TLSv1.2', 'TLSv1.3'],
enable: true
),
cipherSuite: new Oss\Models\CipherSuite(
enable: true,
strongCipherSuite: false,
customCipherSuites: ['ECDHE-ECDSA-AES128-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-ECDSA-AES256-CCM8'],
tls13CustomCipherSuites: ['TLS_AES_256_GCM_SHA384', 'TLS_AES_128_GCM_SHA256', 'TLS_CHACHA20_POLY1305_SHA256'],
)
),
));
$this->assertEquals(200, $putResult->statusCode);
$this->assertEquals('OK', $putResult->status);
$this->assertEquals(True, count($putResult->headers) > 0);
$this->assertEquals(24, strlen($putResult->requestId));

// GetBucketHttpsConfig
$getResult = $client->getBucketHttpsConfig(new Oss\Models\GetBucketHttpsConfigRequest(
$bucketName
));
$this->assertEquals(200, $getResult->statusCode);
$this->assertEquals('OK', $getResult->status);
$this->assertEquals(True, count($getResult->headers) > 0);
$this->assertEquals(24, strlen($getResult->requestId));
}

public function testBucketHttpsConfigFail()
Expand Down
50 changes: 50 additions & 0 deletions tests/UnitTests/Transform/BucketHttpsConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ public function testFromPutBucketHttpsConfig()
$this->assertEquals('bucket-123', $input->getBucket());
$xml = <<<BBB
<?xml version="1.0" encoding="UTF-8"?><HttpsConfiguration><TLS><TLSVersion>TLSv1.2</TLSVersion><TLSVersion>TLSv1.3</TLSVersion><Enable>true</Enable></TLS></HttpsConfiguration>
BBB;
$this->assertEquals($xml, $this->cleanXml($input->getBody()->getContents()));

// demo2
$request = new Models\PutBucketHttpsConfigRequest('bucket-123', new Models\HttpsConfiguration(
tls: new Models\TLS(
tlsVersions: ['TLSv1.2', 'TLSv1.3'],
enable: true
),
cipherSuite: new Models\CipherSuite(
enable: true,
strongCipherSuite: false,
customCipherSuites: ['ECDHE-ECDSA-AES128-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-ECDSA-AES256-CCM8'],
tls13CustomCipherSuites: ['ECDHE-ECDSA-AES256-CCM8', 'ECDHE-ECDSA-AES256-CCM8', 'ECDHE-ECDSA-AES256-CCM8'],
)
));
$input = BucketHttpsConfig::fromPutBucketHttpsConfig($request);
$this->assertEquals('bucket-123', $input->getBucket());
$xml = <<<BBB
<?xml version="1.0" encoding="UTF-8"?><HttpsConfiguration><TLS><TLSVersion>TLSv1.2</TLSVersion><TLSVersion>TLSv1.3</TLSVersion><Enable>true</Enable></TLS><CipherSuite><Enable>true</Enable><StrongCipherSuite>false</StrongCipherSuite><CustomCipherSuite>ECDHE-ECDSA-AES128-SHA256</CustomCipherSuite><CustomCipherSuite>ECDHE-RSA-AES128-GCM-SHA256</CustomCipherSuite><CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</CustomCipherSuite><TLS13CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</TLS13CustomCipherSuite><TLS13CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</TLS13CustomCipherSuite><TLS13CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</TLS13CustomCipherSuite></CipherSuite></HttpsConfiguration>
BBB;
$this->assertEquals($xml, $this->cleanXml($input->getBody()->getContents()));
}
Expand Down Expand Up @@ -118,6 +138,36 @@ public function testToGetBucketHttpsConfig()
$this->assertEquals(2, count($result->httpsConfiguration->tls->tlsVersions));
$this->assertEquals("TLSv1.2", $result->httpsConfiguration->tls->tlsVersions[0]);
$this->assertEquals("TLSv1.3", $result->httpsConfiguration->tls->tlsVersions[1]);

$body = '<?xml version="1.0" encoding="UTF-8"?><HttpsConfiguration><TLS><TLSVersion>TLSv1.2</TLSVersion><TLSVersion>TLSv1.3</TLSVersion><Enable>true</Enable></TLS><CipherSuite><Enable>true</Enable><StrongCipherSuite>false</StrongCipherSuite><CustomCipherSuite>ECDHE-ECDSA-AES128-SHA256</CustomCipherSuite><CustomCipherSuite>ECDHE-RSA-AES128-GCM-SHA256</CustomCipherSuite><CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</CustomCipherSuite><TLS13CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</TLS13CustomCipherSuite><TLS13CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</TLS13CustomCipherSuite><TLS13CustomCipherSuite>ECDHE-ECDSA-AES256-CCM8</TLS13CustomCipherSuite></CipherSuite></HttpsConfiguration>';
$output = new OperationOutput(
'OK',
200,
['x-oss-request-id' => '123', 'content-type' => 'application/xml'],
Utils::streamFor($body)
);
$result = BucketHttpsConfig::toGetBucketHttpsConfig($output);
$this->assertEquals('OK', $result->status);
$this->assertEquals(200, $result->statusCode);
$this->assertEquals('123', $result->requestId);
$this->assertEquals(2, count($result->headers));
$this->assertEquals('123', $result->headers['x-oss-request-id']);
$this->assertEquals('application/xml', $result->headers['content-type']);
$this->assertTrue($result->httpsConfiguration->tls->enable);
$this->assertEquals(2, count($result->httpsConfiguration->tls->tlsVersions));
$this->assertEquals("TLSv1.2", $result->httpsConfiguration->tls->tlsVersions[0]);
$this->assertEquals("TLSv1.3", $result->httpsConfiguration->tls->tlsVersions[1]);

$this->assertTrue($result->httpsConfiguration->cipherSuite->enable);
$this->assertFalse($result->httpsConfiguration->cipherSuite->strongCipherSuite);
$this->assertEquals(3, count($result->httpsConfiguration->cipherSuite->customCipherSuites));
$this->assertEquals('ECDHE-ECDSA-AES128-SHA256', $result->httpsConfiguration->cipherSuite->customCipherSuites[0]);
$this->assertEquals('ECDHE-RSA-AES128-GCM-SHA256', $result->httpsConfiguration->cipherSuite->customCipherSuites[1]);
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->customCipherSuites[2]);
$this->assertEquals(3, count($result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites));
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites[0]);
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites[1]);
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites[2]);
}

private function cleanXml($xml): array|string
Expand Down