Skip to content

Commit 36cb096

Browse files
committed
swift metadata header case
1 parent 38a6860 commit 36cb096

File tree

9 files changed

+76
-27
lines changed

9 files changed

+76
-27
lines changed

src/ObjectStore/v1/Models/MetadataTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function parseMetadata(ResponseInterface $response): array
1313
$metadata = [];
1414

1515
foreach ($response->getHeaders() as $header => $value) {
16-
if (0 === strpos($header, static::METADATA_PREFIX)) {
16+
if (0 === stripos($header, static::METADATA_PREFIX)) {
1717
$name = substr($header, strlen(static::METADATA_PREFIX));
1818
$metadata[$name] = $response->getHeader($header)[0];
1919
}

tests/unit/ObjectStore/v1/Fixtures/GET_Container.resp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Content-Length: 341
33
X-Container-Object-Count: 2
44
Accept-Ranges: bytes
55
X-Container-Meta-Book: TomSawyer
6+
X-CONTAINER-META-UPPERCASE: UPPERCASE
7+
x-container-meta-lowercase: lowercase
68
X-Timestamp: 1389727543.65372
79
X-Container-Bytes-Used: 26
810
Content-Type: application/json; charset=utf-8

tests/unit/ObjectStore/v1/Fixtures/GET_Object.resp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Last-Modified: Wed, 15 Jan 2014 16:41:49 GMT
55
Etag: 451e372e48e0f6b1114fa0724aa79fa1
66
X-Timestamp: 1389804109.39027
77
X-Object-Meta-Orig-Filename: goodbyeworld.txt
8+
X-OBJECT-META-UPPERCASE: UPPERCASE
9+
x-object-meta-lowercase: lowercase
810
Content-Type: text/plain
911
X-Trans-Id: tx8145a190241f4cf6b05f5-0052d82a34
1012
Date: Thu, 16 Jan 2014 18:51:32 GMT

tests/unit/ObjectStore/v1/Fixtures/HEAD_Account.resp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Content-Length: 0
33
X-Account-Object-Count: 1
44
X-Account-Meta-Book: MobyDick
55
X-Account-Meta-Genre: Fiction
6+
X-ACCOUNT-META-UPPERCASE: UPPERCASE
7+
x-account-meta-lowercase: lowercase
68
X-Timestamp: 1389453423.35964
79
X-Account-Bytes-Used: 14
810
X-Account-Container-Count: 2

tests/unit/ObjectStore/v1/Fixtures/HEAD_Container.resp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ X-Container-Object-Count: 1
44
Accept-Ranges: bytes
55
X-Container-Meta-Book: TomSawyer
66
X-Container-Meta-Author: SamuelClemens
7+
X-CONTAINER-META-UPPERCASE: UPPERCASE
8+
x-container-meta-lowercase: lowercase
79
X-Timestamp: 1389727543.65372
810
X-Container-Bytes-Used: 14
911
Content-Type: text/plain; charset=utf-8

tests/unit/ObjectStore/v1/Fixtures/HEAD_Object.resp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Etag: 451e372e48e0f6b1114fa0724aa79fa1
66
X-Timestamp: 1389906751.73463
77
X-Object-Meta-Book: GoodbyeColumbus
88
X-Object-Meta-Manufacturer: Acme
9+
X-OBJECT-META-UPPERCASE: UPPERCASE
10+
x-object-meta-lowercase: lowercase
911
Content-Type: application/octet-stream
1012
X-Trans-Id: tx37ea34dcd1ed48ca9bc7d-0052d84b6f
1113
Date: Thu, 16 Jan 2014 21:13:19 GMT

tests/unit/ObjectStore/v1/Models/AccountTest.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ public function test_Response_Populates_Model()
2626
$this->account->populateFromResponse($response);
2727

2828
self::assertEquals(1, $this->account->objectCount);
29-
self::assertEquals(['Book' => 'MobyDick', 'Genre' => 'Fiction'], $this->account->metadata);
29+
self::assertEquals(
30+
[
31+
'Book' => 'MobyDick',
32+
'Genre' => 'Fiction',
33+
'UPPERCASE' => 'UPPERCASE',
34+
'lowercase' => 'lowercase',
35+
],
36+
$this->account->metadata
37+
);
3038
self::assertEquals(14, $this->account->bytesUsed);
3139
self::assertEquals(2, $this->account->containerCount);
3240
}
@@ -43,7 +51,15 @@ public function test_Retrieve()
4351
public function test_Get_Metadata()
4452
{
4553
$this->mockRequest('HEAD', '', 'HEAD_Account', null, []);
46-
self::assertEquals(['Book' => 'MobyDick', 'Genre' => 'Fiction'], $this->account->getMetadata());
54+
self::assertEquals(
55+
[
56+
'Book' => 'MobyDick',
57+
'Genre' => 'Fiction',
58+
'UPPERCASE' => 'UPPERCASE',
59+
'lowercase' => 'lowercase',
60+
],
61+
$this->account->getMetadata()
62+
);
4763
}
4864

4965
public function test_Merge_Metadata()
@@ -60,9 +76,11 @@ public function test_Reset_Metadata()
6076
$this->mockRequest('HEAD', '', 'HEAD_Account', null, []);
6177

6278
$headers = [
63-
'X-Account-Meta-Book' => 'Middlesex',
64-
'X-Account-Meta-Author' => 'Jeffrey Eugenides',
65-
'X-Remove-Account-Meta-Genre' => 'True',
79+
'X-Account-Meta-Book' => 'Middlesex',
80+
'X-Account-Meta-Author' => 'Jeffrey Eugenides',
81+
'X-Remove-Account-Meta-Genre' => 'True',
82+
'X-Remove-Account-Meta-UPPERCASE' => 'True',
83+
'X-Remove-Account-Meta-lowercase' => 'True',
6684
];
6785

6886
$this->mockRequest('POST', '', 'NoContent', [], $headers);

tests/unit/ObjectStore/v1/Models/ContainerTest.php

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ public function test_Populate_From_Response()
3535
$this->container->populateFromResponse($response);
3636

3737
self::assertEquals(1, $this->container->objectCount);
38-
self::assertEquals(['Book' => 'TomSawyer', 'Author' => 'SamuelClemens'], $this->container->metadata);
38+
self::assertEquals(
39+
[
40+
'Book' => 'TomSawyer',
41+
'Author' => 'SamuelClemens',
42+
'UPPERCASE' => 'UPPERCASE',
43+
'lowercase' => 'lowercase',
44+
],
45+
$this->container->metadata
46+
);
3947
self::assertEquals(14, $this->container->bytesUsed);
4048
}
4149

@@ -51,7 +59,16 @@ public function test_Get_Metadata()
5159
{
5260
$this->mockRequest('HEAD', self::NAME, 'HEAD_Container', null, []);
5361

54-
self::assertEquals(['Book' => 'TomSawyer', 'Author' => 'SamuelClemens'], $this->container->getMetadata());
62+
self::assertEquals(
63+
[
64+
'Book' => 'TomSawyer',
65+
'Author' => 'SamuelClemens',
66+
'UPPERCASE' => 'UPPERCASE',
67+
'lowercase' => 'lowercase',
68+
69+
],
70+
$this->container->getMetadata()
71+
);
5572
}
5673

5774
public function test_Merge_Metadata()
@@ -70,6 +87,8 @@ public function test_Reset_Metadata()
7087
$headers = [
7188
'X-Container-Meta-Book' => 'Middlesex',
7289
'X-Remove-Container-Meta-Author' => 'True',
90+
'X-Remove-Container-Meta-UPPERCASE' => 'True',
91+
'X-Remove-Container-Meta-lowercase' => 'True',
7392
];
7493

7594
$this->mockRequest('POST', self::NAME, 'NoContent', [], $headers);
@@ -141,29 +160,27 @@ public function test_it_lists_objects()
141160

142161
$expected = [
143162
[
144-
'name' => 'goodbye',
163+
'name' => 'goodbye',
145164
'contentLength' => '14',
146-
'lastModified' => new \DateTimeImmutable('2014-01-15T16:41:49.390270'),
147-
'contentType' => 'application/octet-stream',
148-
'hash' => '451e372e48e0f6b1114fa0724aa79fa1'
165+
'lastModified' => new \DateTimeImmutable('2014-01-15T16:41:49.390270'),
166+
'contentType' => 'application/octet-stream',
167+
'hash' => '451e372e48e0f6b1114fa0724aa79fa1',
149168
],
150169
[
151-
'name' => 'helloworld.json',
170+
'name' => 'helloworld.json',
152171
'contentLength' => '12',
153-
'lastModified' => new \DateTimeImmutable('2014-01-15T16:37:43.427570'),
154-
'contentType' => 'application/json',
155-
'hash' => 'ed076287532e86365e841e92bfc50d8c'
172+
'lastModified' => new \DateTimeImmutable('2014-01-15T16:37:43.427570'),
173+
'contentType' => 'application/json',
174+
'hash' => 'ed076287532e86365e841e92bfc50d8c',
156175
],
157176
];
158177

159-
for ($i = 0; $i < count($objects); $i++)
160-
{
178+
for ($i = 0; $i < count($objects); $i++) {
161179
$exp = $expected[$i];
162180
/** @var StorageObject $obj */
163181
$obj = $objects[$i];
164182

165-
foreach ($exp as $attr => $attrVal)
166-
{
183+
foreach ($exp as $attr => $attrVal) {
167184
self::assertEquals($attrVal, $obj->{$attr});
168185
}
169186
}
@@ -194,7 +211,7 @@ public function test_other_exceptions_are_thrown()
194211
$e->setResponse(new Response(500));
195212

196213
$this->mockRequest('HEAD', 'test/bar', $e);
197-
$this->expectException(BadResponseError::class);
214+
$this->expectException(BadResponseError::class);
198215

199216
$this->container->objectExists('bar');
200217
}
@@ -214,11 +231,11 @@ public function test_it_chunks_according_to_provided_segment_size()
214231
: \GuzzleHttp\Psr7\Utils::streamFor(implode('', range('A', 'X')));
215232

216233
$data = [
217-
'name' => 'object',
218-
'stream' => $stream,
219-
'segmentSize' => 10,
220-
'segmentPrefix' => 'objectPrefix',
221-
'segmentContainer' => 'segments',
234+
'name' => 'object',
235+
'stream' => $stream,
236+
'segmentSize' => 10,
237+
'segmentPrefix' => 'objectPrefix',
238+
'segmentContainer' => 'segments',
222239
'segmentIndexFormat' => '%03d',
223240
];
224241

tests/unit/ObjectStore/v1/Models/ObjectTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function test_Get_Metadata()
6969
self::assertEquals([
7070
'Book' => 'GoodbyeColumbus',
7171
'Manufacturer' => 'Acme',
72+
'UPPERCASE' => 'UPPERCASE',
73+
'lowercase' => 'lowercase',
7274
], $this->object->getMetadata());
7375
}
7476

@@ -80,6 +82,8 @@ public function test_Merge_Metadata()
8082
'X-Object-Meta-Author' => 'foo',
8183
'X-Object-Meta-Book' => 'GoodbyeColumbus',
8284
'X-Object-Meta-Manufacturer' => 'Acme',
85+
'X-Object-Meta-UPPERCASE' => 'UPPERCASE',
86+
'X-Object-Meta-lowercase' => 'lowercase',
8387
];
8488

8589
$this->mockRequest('POST', self::CONTAINER . '/' . self::NAME, 'NoContent', null, $headers);
@@ -120,7 +124,7 @@ public function test_It_Copies()
120124
$this->mockRequest('COPY', $path, 'Created', null, $headers);
121125

122126
$this->object->copy([
123-
'destination' => $headers['Destination']
127+
'destination' => $headers['Destination'],
124128
]);
125129
}
126130

0 commit comments

Comments
 (0)