forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisableDistributionS3Test.php
More file actions
182 lines (165 loc) · 5.53 KB
/
Copy pathDisableDistributionS3Test.php
File metadata and controls
182 lines (165 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/*
Relies on PHPUnit to test the functionality in ./DisableDistributionS3.php.
Related custom constants are defined in ./phpunit.xml.
Example PHPUnit run command from this file's parent directory:
./vendor/bin/phpunit --testsuite cloudfront-disabledistribution
*/
namespace Cloudfront;
use Aws\CloudFront\CloudFrontClient;
use Aws\MockHandler;
use Aws\Result;
use PHPUnit\Framework\TestCase;
class DisableDistributionTest extends TestCase
{
public static function setUpBeforeClass(): void
{
require(__DIR__ . '/../DisableDistributionS3.php');
}
protected function setUp(): void
{
global $cloudFrontClient;
global $distributionId;
global $eTag;
global $distributionConfig;
$distributionId = CLOUDFRONT_DISTRIBUTION_ID;
$eTag = CLOUDFRONT_DISTRIBUTION_ETAG;
$distributionConfig = [
'CacheBehaviors' => [
'Quantity' => 0
],
'CallerReference' => 'my-',
'Comment' => '',
'DefaultCacheBehavior' => [
'TargetOriginId' => 'my-target-origin-id',
'ForwardedValues' => [
'Cookies' => [
'Forward' => 'none'
],
'Headers' => [
'Quantity' => 0
],
'QueryString' => false,
'QueryStringCacheKeys' => [
'Quantity' => 0
]
],
'ViewerProtocolPolicy' => 'allow-all',
'MinTTL' => '0',
'AllowedMethods' => [
'CachedMethods' => [
'Items' => ['HEAD', 'GET'],
'Quantity' => 2
],
'Items' => ['HEAD', 'GET'],
'Quantity' => 2
],
'SmoothStreaming' => false,
'DefaultTTL' => '86400',
'MaxTTL' => '31536000',
'Compress' => false,
'LambdaFunctionAssociations' => [
'Quantity' => 0
],
'FieldLevelEncryptionId' => '',
'TrustedSigners' => [
'Enabled' => false,
'Quantity' => 0
]
],
'DefaultRootObject' => '',
'Enabled' => false,
'Origins' => [
'Items' => [
[
'DomainName' => 'amzn-s3-demo-bucket.s3.amazonaws.com',
'Id' => 'my-unique-origin-name',
'OriginPath' => '',
'CustomHeaders' => [
'Quantity' => 0
],
'S3OriginConfig' => [
'OriginAccessIdentity' => ''
]
]
],
'Quantity' => 1
],
'Aliases' => [
'Quantity' => 0
],
'CustomErrorResponses' => [
'Quantity' => 0
],
'HttpVersion' => 'http2',
'Logging' => [
'Enabled' => false,
'IncludeCookies' => false,
'Bucket' => '',
'Prefix' => ''
],
'PriceClass' => 'PriceClass_All',
'Restrictions' => [
'GeoRestriction' => [
'RestrictionType' => 'none',
'Quantity' => 0
]
],
'ViewerCertificate' => [
'CloudFrontDefaultCertificate' => true,
'MinimumProtocolVersion' => 'TLSv1',
'CertificateSource' => 'cloudfront',
'WebACLId' => ''
]
];
$mock = new MockHandler();
$mock->append(new Result(array(true)));
$cloudFrontClient = new CloudFrontClient([
'profile' => AWS_PROFILE,
'version' => CLOUDFRONT_VERSION,
'region' => AWS_REGION,
'handler' => $mock
]);
}
protected function tearDown(): void
{
unset($GLOBALS['cloudFrontClient']);
}
public function testDisablesADistribution()
{
$result = disableDistribution(
$GLOBALS['cloudFrontClient'],
$GLOBALS['distributionId'],
$GLOBALS['distributionConfig'],
$GLOBALS['eTag']
);
$this->assertStringContainsString(
'https://cloudfront.amazonaws.com/' .
CLOUDFRONT_VERSION . '/distribution/' .
CLOUDFRONT_DISTRIBUTION_ID . '/config',
$result
);
}
public function testGetsADistributionConfig()
{
$result = getDistributionConfig(
$GLOBALS['cloudFrontClient'],
$GLOBALS['distributionId']
);
$this->assertContains('https://cloudfront.amazonaws.com/' .
CLOUDFRONT_VERSION . '/distribution/' .
CLOUDFRONT_DISTRIBUTION_ID, $result);
}
public function testGetsADistributionETag()
{
$result = getDistributionETag(
$GLOBALS['cloudFrontClient'],
$GLOBALS['distributionId']
);
$this->assertContains('https://cloudfront.amazonaws.com/' .
CLOUDFRONT_VERSION . '/distribution/' .
CLOUDFRONT_DISTRIBUTION_ID, $result);
}
}