Open Journal Systems
3.3.0
Md5ValidatorPluginTest.php
1
<?php
2
3
namespace
Guzzle\Tests\Plugin\Md5
;
4
5
use
Guzzle\Http\EntityBody
;
6
use
Guzzle\Http\Message\RequestFactory
;
7
use
Guzzle\Http\Message\Response
;
8
use
Guzzle\Plugin\Md5\Md5ValidatorPlugin
;
9
13
class
Md5ValidatorPluginTest
extends
\Guzzle\Tests\GuzzleTestCase
14
{
15
public
function
testValidatesMd5
()
16
{
17
$plugin =
new
Md5ValidatorPlugin
();
18
$request =
RequestFactory::getInstance
()->create(
'GET'
,
'http://www.test.com/'
);
19
$request->getEventDispatcher()->addSubscriber($plugin);
20
21
$body =
'abc'
;
22
$hash = md5($body);
23
$response =
new
Response
(200, array(
24
'Content-MD5'
=> $hash,
25
'Content-Length'
=> 3
26
),
'abc'
);
27
28
$request->dispatch(
'request.complete'
, array(
29
'response'
=> $response
30
));
31
32
// Try again with no Content-MD5
33
$response->removeHeader(
'Content-MD5'
);
34
$request->dispatch(
'request.complete'
, array(
35
'response'
=> $response
36
));
37
}
38
42
public
function
testThrowsExceptionOnInvalidMd5
()
43
{
44
$plugin =
new
Md5ValidatorPlugin
();
45
$request =
RequestFactory::getInstance
()->create(
'GET'
,
'http://www.test.com/'
);
46
$request->getEventDispatcher()->addSubscriber($plugin);
47
48
$request->dispatch(
'request.complete'
, array(
49
'response'
=>
new
Response
(200, array(
50
'Content-MD5'
=>
'foobar'
,
51
'Content-Length'
=> 3
52
),
'abc'
)
53
));
54
}
55
56
public
function
testSkipsWhenContentLengthIsTooLarge
()
57
{
58
$plugin =
new
Md5ValidatorPlugin
(
false
, 1);
59
$request =
RequestFactory::getInstance
()->create(
'GET'
,
'http://www.test.com/'
);
60
$request->getEventDispatcher()->addSubscriber($plugin);
61
62
$request->dispatch(
'request.complete'
, array(
63
'response'
=>
new
Response
(200, array(
64
'Content-MD5'
=>
'foobar'
,
65
'Content-Length'
=> 3
66
),
'abc'
)
67
));
68
}
69
70
public
function
testProperlyValidatesWhenUsingContentEncoding
()
71
{
72
$plugin =
new
Md5ValidatorPlugin
(
true
);
73
$request =
RequestFactory::getInstance
()->create(
'GET'
,
'http://www.test.com/'
);
74
$request->getEventDispatcher()->addSubscriber($plugin);
75
76
// Content-MD5 is the MD5 hash of the canonical content after all
77
// content-encoding has been applied. Because cURL will automatically
78
// decompress entity bodies, we need to re-compress it to calculate.
79
$body =
EntityBody::factory
(
'abc'
);
80
$body->compress();
81
$hash = $body->getContentMd5();
82
$body->uncompress();
83
84
$response =
new
Response
(200, array(
85
'Content-MD5'
=> $hash,
86
'Content-Encoding'
=>
'gzip'
87
),
'abc'
);
88
$request->dispatch(
'request.complete'
, array(
89
'response'
=> $response
90
));
91
$this->assertEquals(
'abc'
, $response->getBody(
true
));
92
93
// Try again with an unknown encoding
94
$response =
new
Response
(200, array(
95
'Content-MD5'
=> $hash,
96
'Content-Encoding'
=>
'foobar'
97
),
'abc'
);
98
$request->dispatch(
'request.complete'
, array(
99
'response'
=> $response
100
));
101
102
// Try again with compress
103
$body->compress(
'bzip2.compress'
);
104
$response =
new
Response
(200, array(
105
'Content-MD5'
=> $body->getContentMd5(),
106
'Content-Encoding'
=>
'compress'
107
),
'abc'
);
108
$request->dispatch(
'request.complete'
, array(
109
'response'
=> $response
110
));
111
112
// Try again with encoding and disabled content-encoding checks
113
$request->getEventDispatcher()->removeSubscriber($plugin);
114
$plugin =
new
Md5ValidatorPlugin
(
false
);
115
$request->getEventDispatcher()->addSubscriber($plugin);
116
$request->dispatch(
'request.complete'
, array(
117
'response'
=> $response
118
));
119
}
120
}
Guzzle\Tests\GuzzleTestCase
Definition:
GuzzleTestCase.php:22
Guzzle\Tests\Plugin\Md5\Md5ValidatorPluginTest\testSkipsWhenContentLengthIsTooLarge
testSkipsWhenContentLengthIsTooLarge()
Definition:
Md5ValidatorPluginTest.php:56
Guzzle\Http\EntityBody\factory
static factory($resource='', $size=null)
Definition:
EntityBody.php:36
Guzzle\Http\Message\Response
Definition:
lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php:17
Guzzle\Http\EntityBody
Definition:
EntityBody.php:13
Guzzle\Plugin\Md5\Md5ValidatorPlugin
Definition:
Md5ValidatorPlugin.php:14
Guzzle\Tests\Plugin\Md5\Md5ValidatorPluginTest
Definition:
Md5ValidatorPluginTest.php:13
Guzzle\Http\Message\RequestFactory
Definition:
lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestFactory.php:14
Guzzle\Tests\Plugin\Md5\Md5ValidatorPluginTest\testProperlyValidatesWhenUsingContentEncoding
testProperlyValidatesWhenUsingContentEncoding()
Definition:
Md5ValidatorPluginTest.php:70
Guzzle\Http\Message\RequestFactory\getInstance
static getInstance()
Definition:
lib/vendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestFactory.php:42
Guzzle\Tests\Plugin\Md5\Md5ValidatorPluginTest\testThrowsExceptionOnInvalidMd5
testThrowsExceptionOnInvalidMd5()
Definition:
Md5ValidatorPluginTest.php:42
Guzzle\Tests\Plugin\Md5
Definition:
CommandContentMd5PluginTest.php:3
Guzzle\Tests\Plugin\Md5\Md5ValidatorPluginTest\testValidatesMd5
testValidatesMd5()
Definition:
Md5ValidatorPluginTest.php:15
plugins
paymethod
paypal
lib
vendor
guzzle
guzzle
tests
Guzzle
Tests
Plugin
Md5
Md5ValidatorPluginTest.php
Generated on Fri Aug 28 2020 14:52:39 for Open Journal Systems by
1.8.17