Skip to content

Commit 97a6739

Browse files
author
Jamie Hannaford
committed
Merge pull request rackspace#646 from PatrickRose/working
Make sure container name is valid when retrieving
2 parents 57c2837 + b5b7011 commit 97a6739

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/OpenCloud/ObjectStore/Service.php

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public function listContainers(array $filter = array())
9292
*/
9393
public function getContainer($data = null)
9494
{
95+
if (is_string($data) || is_numeric($data)) {
96+
$this->checkContainerName($data);
97+
}
98+
9599
return new Container($this, $data);
96100
}
97101

tests/OpenCloud/Tests/ObjectStore/ServiceTest.php

+42
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,48 @@ public function test_Bad_Container_Name_Long()
9999
$this->service->createContainer(str_repeat('a', Service::MAX_CONTAINER_NAME_LENGTH + 1));
100100
}
101101

102+
/**
103+
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
104+
*/
105+
public function test_Get_Bad_Container_Name_Empty()
106+
{
107+
$this->service->getContainer('');
108+
}
109+
110+
/**
111+
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
112+
*/
113+
public function test_Get_Bad_Container_Name_Slashes()
114+
{
115+
$this->service->getContainer('foo/bar');
116+
}
117+
118+
/**
119+
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
120+
*/
121+
public function test_Get_Bad_Container_Name_Long()
122+
{
123+
$this->service->getContainer(str_repeat('a', Service::MAX_CONTAINER_NAME_LENGTH + 1));
124+
}
125+
126+
/**
127+
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
128+
*/
129+
public function test_Get_Bad_Container_Name_Float()
130+
{
131+
$this->service->getContainer(4.5);
132+
}
133+
134+
public function test_Get_Container_String()
135+
{
136+
$this->assertInstanceOf('OpenCloud\ObjectStore\Resource\Container', $this->service->getContainer('foo'));
137+
}
138+
139+
public function test_Get_Container_Integer()
140+
{
141+
$this->assertInstanceOf('OpenCloud\ObjectStore\Resource\Container', $this->service->getContainer(1));
142+
}
143+
102144
public function test_Bulk_Extract()
103145
{
104146
$response = $this->service->bulkExtract('fooBarContainer', 'CONTENT', UrlType::TAR);

0 commit comments

Comments
 (0)