Skip to content

Commit 19dfe89

Browse files
committed
refine bucket https config api
1 parent 8bada8f commit 19dfe89

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

src/Models/CipherSuite.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AlibabaCloud\Oss\V2\Models;
6+
7+
use AlibabaCloud\Oss\V2\Types\Model;
8+
use AlibabaCloud\Oss\V2\Annotation\XmlElement;
9+
use AlibabaCloud\Oss\V2\Annotation\XmlRoot;
10+
11+
/**
12+
* Class CipherSuite
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
#[XmlRoot(name: 'CipherSuite')]
16+
final class CipherSuite extends Model
17+
{
18+
/**
19+
* @var bool|null
20+
*/
21+
#[XmlElement(rename: 'Enable', type: 'bool')]
22+
public ?bool $enable;
23+
24+
/**
25+
* @var bool|null
26+
*/
27+
#[XmlElement(rename: 'StrongCipherSuite', type: 'bool')]
28+
public ?bool $strongCipherSuite;
29+
30+
/**
31+
* @var array<string>|null
32+
*/
33+
#[XmlElement(rename: 'CustomCipherSuite', type: 'string')]
34+
public ?array $customCipherSuites;
35+
36+
/**
37+
* @var array<string>|null
38+
*/
39+
#[XmlElement(rename: 'TLS13CustomCipherSuite', type: 'string')]
40+
public ?array $tls13CustomCipherSuites;
41+
42+
/**
43+
* CipherSuite constructor.
44+
* @param bool|null $enable
45+
* @param bool|null $strongCipherSuite
46+
* @param array<string>|null $customCipherSuites
47+
* @param array<string>|null $tls13CustomCipherSuites
48+
*/
49+
public function __construct(
50+
?bool $enable = null,
51+
?bool $strongCipherSuite = null,
52+
?array $customCipherSuites = null,
53+
?array $tls13CustomCipherSuites = null
54+
)
55+
{
56+
$this->enable = $enable;
57+
$this->strongCipherSuite = $strongCipherSuite;
58+
$this->customCipherSuites = $customCipherSuites;
59+
$this->tls13CustomCipherSuites = $tls13CustomCipherSuites;
60+
}
61+
}

src/Models/HttpsConfiguration.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@ final class HttpsConfiguration extends Model
2222
#[XmlElement(rename: 'TLS', type: TLS::class)]
2323
public ?TLS $tls;
2424

25+
/**
26+
* @var CipherSuite|null
27+
*/
28+
#[XmlElement(rename: 'CipherSuite', type: CipherSuite::class)]
29+
public ?CipherSuite $cipherSuite;
2530

2631
/**
2732
* HttpsConfiguration constructor.
2833
* @param TLS|null $tls The container that stores TLS version configurations.
34+
* @param CipherSuite|null $cipherSuite
2935
*/
3036
public function __construct(
31-
?TLS $tls = null
37+
?TLS $tls = null,
38+
?CipherSuite $cipherSuite = null
3239
)
3340
{
3441
$this->tls = $tls;
42+
$this->cipherSuite = $cipherSuite;
3543
}
3644
}

tests/IntegrationTests/ClientBucketHttpsConfigTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@ public function testBucketHttpsConfig()
3636
$this->assertEquals('OK', $getResult->status);
3737
$this->assertEquals(True, count($getResult->headers) > 0);
3838
$this->assertEquals(24, strlen($getResult->requestId));
39+
40+
// PutBucketHttpsConfig
41+
$putResult = $client->putBucketHttpsConfig(new Oss\Models\PutBucketHttpsConfigRequest(
42+
$bucketName,
43+
new Oss\Models\HttpsConfiguration(
44+
tls: new Oss\Models\TLS(
45+
tlsVersions: ['TLSv1.2', 'TLSv1.3'],
46+
enable: true
47+
),
48+
cipherSuite: new Oss\Models\CipherSuite(
49+
enable: true,
50+
strongCipherSuite: false,
51+
customCipherSuites: ['ECDHE-ECDSA-AES128-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-ECDSA-AES256-CCM8'],
52+
tls13CustomCipherSuites: ['TLS_AES_256_GCM_SHA384', 'TLS_AES_128_GCM_SHA256', 'TLS_CHACHA20_POLY1305_SHA256'],
53+
)
54+
),
55+
));
56+
$this->assertEquals(200, $putResult->statusCode);
57+
$this->assertEquals('OK', $putResult->status);
58+
$this->assertEquals(True, count($putResult->headers) > 0);
59+
$this->assertEquals(24, strlen($putResult->requestId));
60+
61+
// GetBucketHttpsConfig
62+
$getResult = $client->getBucketHttpsConfig(new Oss\Models\GetBucketHttpsConfigRequest(
63+
$bucketName
64+
));
65+
$this->assertEquals(200, $getResult->statusCode);
66+
$this->assertEquals('OK', $getResult->status);
67+
$this->assertEquals(True, count($getResult->headers) > 0);
68+
$this->assertEquals(24, strlen($getResult->requestId));
3969
}
4070

4171
public function testBucketHttpsConfigFail()

tests/UnitTests/Transform/BucketHttpsConfigTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ public function testFromPutBucketHttpsConfig()
3939
$this->assertEquals('bucket-123', $input->getBucket());
4040
$xml = <<<BBB
4141
<?xml version="1.0" encoding="UTF-8"?><HttpsConfiguration><TLS><TLSVersion>TLSv1.2</TLSVersion><TLSVersion>TLSv1.3</TLSVersion><Enable>true</Enable></TLS></HttpsConfiguration>
42+
BBB;
43+
$this->assertEquals($xml, $this->cleanXml($input->getBody()->getContents()));
44+
45+
// demo2
46+
$request = new Models\PutBucketHttpsConfigRequest('bucket-123', new Models\HttpsConfiguration(
47+
tls: new Models\TLS(
48+
tlsVersions: ['TLSv1.2', 'TLSv1.3'],
49+
enable: true
50+
),
51+
cipherSuite: new Models\CipherSuite(
52+
enable: true,
53+
strongCipherSuite: false,
54+
customCipherSuites: ['ECDHE-ECDSA-AES128-SHA256', 'ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-ECDSA-AES256-CCM8'],
55+
tls13CustomCipherSuites: ['ECDHE-ECDSA-AES256-CCM8', 'ECDHE-ECDSA-AES256-CCM8', 'ECDHE-ECDSA-AES256-CCM8'],
56+
)
57+
));
58+
$input = BucketHttpsConfig::fromPutBucketHttpsConfig($request);
59+
$this->assertEquals('bucket-123', $input->getBucket());
60+
$xml = <<<BBB
61+
<?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>
4262
BBB;
4363
$this->assertEquals($xml, $this->cleanXml($input->getBody()->getContents()));
4464
}
@@ -118,6 +138,36 @@ public function testToGetBucketHttpsConfig()
118138
$this->assertEquals(2, count($result->httpsConfiguration->tls->tlsVersions));
119139
$this->assertEquals("TLSv1.2", $result->httpsConfiguration->tls->tlsVersions[0]);
120140
$this->assertEquals("TLSv1.3", $result->httpsConfiguration->tls->tlsVersions[1]);
141+
142+
$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>';
143+
$output = new OperationOutput(
144+
'OK',
145+
200,
146+
['x-oss-request-id' => '123', 'content-type' => 'application/xml'],
147+
Utils::streamFor($body)
148+
);
149+
$result = BucketHttpsConfig::toGetBucketHttpsConfig($output);
150+
$this->assertEquals('OK', $result->status);
151+
$this->assertEquals(200, $result->statusCode);
152+
$this->assertEquals('123', $result->requestId);
153+
$this->assertEquals(2, count($result->headers));
154+
$this->assertEquals('123', $result->headers['x-oss-request-id']);
155+
$this->assertEquals('application/xml', $result->headers['content-type']);
156+
$this->assertTrue($result->httpsConfiguration->tls->enable);
157+
$this->assertEquals(2, count($result->httpsConfiguration->tls->tlsVersions));
158+
$this->assertEquals("TLSv1.2", $result->httpsConfiguration->tls->tlsVersions[0]);
159+
$this->assertEquals("TLSv1.3", $result->httpsConfiguration->tls->tlsVersions[1]);
160+
161+
$this->assertTrue($result->httpsConfiguration->cipherSuite->enable);
162+
$this->assertFalse($result->httpsConfiguration->cipherSuite->strongCipherSuite);
163+
$this->assertEquals(3, count($result->httpsConfiguration->cipherSuite->customCipherSuites));
164+
$this->assertEquals('ECDHE-ECDSA-AES128-SHA256', $result->httpsConfiguration->cipherSuite->customCipherSuites[0]);
165+
$this->assertEquals('ECDHE-RSA-AES128-GCM-SHA256', $result->httpsConfiguration->cipherSuite->customCipherSuites[1]);
166+
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->customCipherSuites[2]);
167+
$this->assertEquals(3, count($result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites));
168+
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites[0]);
169+
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites[1]);
170+
$this->assertEquals('ECDHE-ECDSA-AES256-CCM8', $result->httpsConfiguration->cipherSuite->tls13CustomCipherSuites[2]);
121171
}
122172

123173
private function cleanXml($xml): array|string

0 commit comments

Comments
 (0)