3
3
namespace OSS \Tests ;
4
4
5
5
use OSS \Core \OssException ;
6
- use OSS \Credentials \StaticCredentialsProvider ;
7
- use OSS \Model \LifecycleConfig ;
8
- use OSS \Model \LifecycleRule ;
9
- use OSS \Model \LifecycleAction ;
6
+ use OSS \Http \RequestCore ;
10
7
use OSS \OssClient ;
11
8
12
9
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php ' ;
@@ -18,20 +15,23 @@ public function testForcePathStyle()
18
15
{
19
16
$ config = array (
20
17
'signatureVersion ' => OssClient::OSS_SIGNATURE_VERSION_V4 ,
21
- 'hostType ' => OssClient:: OSS_HOST_TYPE_PATH_STYLE ,
18
+ 'forcePathStyle ' => true ,
22
19
);
23
- $ this ->ossClient = Common::getOssClient ($ config );
20
+
21
+ $ pathStyleClient = Common::getOssClient ($ config );
24
22
25
23
try {
26
- $ this ->ossClient ->getBucketInfo ($ this ->bucket );
24
+ $ pathStyleClient ->getBucketInfo ($ this ->bucket );
25
+ $ this ->assertTrue (false , "should not here " );
27
26
} catch (OssException $ e ) {
28
27
$ this ->assertEquals ($ e ->getErrorCode (), "SecondLevelDomainForbidden " );
29
28
$ this ->assertTrue (true );
30
29
}
31
30
32
31
try {
33
32
$ object = "oss-php-sdk-test/upload-test-object-name.txt " ;
34
- $ this ->ossClient ->putObject ($ this ->bucket , $ object , 'hi oss ' );
33
+ $ pathStyleClient ->putObject ($ this ->bucket , $ object , 'hi oss ' );
34
+ $ this ->assertTrue (false , "should not here " );
35
35
} catch (OssException $ e ) {
36
36
$ this ->assertEquals ($ e ->getErrorCode (), "SecondLevelDomainForbidden " );
37
37
$ this ->assertTrue (true );
@@ -40,11 +40,85 @@ public function testForcePathStyle()
40
40
try {
41
41
$ endpoint = Common::getEndpoint ();
42
42
$ endpoint = str_replace (array ('http:// ' , 'https:// ' ), '' , $ endpoint );
43
- $ strUrl = $ this -> bucket . ' . ' . $ endpoint . " / " . $ object ;
44
- $ signUrl = $ this -> ossClient ->signUrl ($ this ->bucket , $ object , 3600 );
43
+ $ strUrl = $ endpoint . " / " . $ this -> bucket . ' / ' . $ object ;
44
+ $ signUrl = $ pathStyleClient ->signUrl ($ this ->bucket , $ object , 3600 );
45
45
$ this ->assertTrue (strpos ($ signUrl , $ strUrl ) !== false );
46
46
} catch (OssException $ e ) {
47
47
$ this ->assertFalse (true );
48
48
}
49
49
}
50
+
51
+ public function testForcePathStyleOKV1 ()
52
+ {
53
+ $ bucket = Common::getPathStyleBucket ();
54
+
55
+ $ this ->assertFalse (empty ($ bucket ), "path style bucket is not set. " );
56
+
57
+ $ config = array (
58
+ 'signatureVersion ' => OssClient::OSS_SIGNATURE_VERSION_V1 ,
59
+ 'forcePathStyle ' => true ,
60
+ );
61
+
62
+ $ pathStyleClient = Common::getOssClient ($ config );
63
+
64
+ // bucket
65
+ $ info = $ pathStyleClient ->getBucketInfo ($ bucket );
66
+ $ this ->assertEquals ($ bucket , $ info ->getName ());
67
+
68
+ // object
69
+ $ object = "upload-test-object-name.txt " ;
70
+ $ pathStyleClient ->putObject ($ bucket , $ object , 'hi oss ' );
71
+ $ res = $ pathStyleClient ->getObject ($ bucket , $ object );
72
+ $ this ->assertEquals ($ res , 'hi oss ' );
73
+
74
+ //presign
75
+ $ signUrl = $ pathStyleClient ->signUrl ($ bucket , $ object , 3600 );
76
+
77
+ $ httpCore = new RequestCore ($ signUrl );
78
+ $ httpCore ->set_body ("" );
79
+ $ httpCore ->set_method ("GET " );
80
+ $ httpCore ->connect_timeout = 10 ;
81
+ $ httpCore ->timeout = 10 ;
82
+ $ httpCore ->add_header ("Content-Type " , "" );
83
+ $ httpCore ->send_request ();
84
+ $ this ->assertEquals (200 , $ httpCore ->response_code );
85
+ }
86
+
87
+ public function testForcePathStyleOKV4 ()
88
+ {
89
+ $ bucket = Common::getPathStyleBucket ();
90
+
91
+ $ this ->assertFalse (empty ($ bucket ), "path style bucket is not set. " );
92
+
93
+ $ config = array (
94
+ 'signatureVersion ' => OssClient::OSS_SIGNATURE_VERSION_V4 ,
95
+ 'forcePathStyle ' => true ,
96
+ );
97
+
98
+ $ pathStyleClient = Common::getOssClient ($ config );
99
+
100
+ // bucket
101
+ $ info = $ pathStyleClient ->getBucketInfo ($ bucket );
102
+ $ this ->assertEquals ($ bucket , $ info ->getName ());
103
+
104
+ // object
105
+ $ object = "upload-test-object-name.txt " ;
106
+ $ pathStyleClient ->putObject ($ bucket , $ object , 'hi oss ' );
107
+ $ res = $ pathStyleClient ->getObject ($ bucket , $ object );
108
+ $ this ->assertEquals ($ res , 'hi oss ' );
109
+
110
+ //presign
111
+ $ signUrl = $ pathStyleClient ->signUrl ($ bucket , $ object , 3600 );
112
+
113
+ #print("signUrl" . $signUrl . "\n");
114
+
115
+ $ httpCore = new RequestCore ($ signUrl );
116
+ $ httpCore ->set_body ("" );
117
+ $ httpCore ->set_method ("GET " );
118
+ $ httpCore ->connect_timeout = 10 ;
119
+ $ httpCore ->timeout = 10 ;
120
+ $ httpCore ->add_header ("Content-Type " , "" );
121
+ $ httpCore ->send_request ();
122
+ $ this ->assertEquals (200 , $ httpCore ->response_code );
123
+ }
50
124
}
0 commit comments