Updated all unit tests to use IdentityServices.
This commit is contained in:
parent
ff8bed1d56
commit
4d02e28529
@ -19,6 +19,11 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
public static $ostore = NULL;
|
public static $ostore = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The IdentityServices instance.
|
||||||
|
*/
|
||||||
|
public static $ident;
|
||||||
|
|
||||||
|
|
||||||
//public function __construct(score $score = NULL, locale $locale = NULL, adapter $adapter = NULL) {
|
//public function __construct(score $score = NULL, locale $locale = NULL, adapter $adapter = NULL) {
|
||||||
public static function setUpBeforeClass() {
|
public static function setUpBeforeClass() {
|
||||||
@ -53,16 +58,66 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
|||||||
protected $containerFixture = NULL;
|
protected $containerFixture = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate to a Swift account.
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
protected function swiftAuth() {
|
protected function swiftAuth() {
|
||||||
|
|
||||||
if (empty(self::$ostore)) {
|
|
||||||
$user = self::$settings['hpcloud.swift.account'];
|
$user = self::$settings['hpcloud.swift.account'];
|
||||||
$key = self::$settings['hpcloud.swift.key'];
|
$key = self::$settings['hpcloud.swift.key'];
|
||||||
$url = self::$settings['hpcloud.swift.url'];
|
$url = self::$settings['hpcloud.swift.url'];
|
||||||
|
|
||||||
self::$ostore = \HPCloud\Storage\ObjectStorage::newFromSwiftAuth($user, $key, $url);
|
return \HPCloud\Storage\ObjectStorage::newFromSwiftAuth($user, $key, $url);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a handle to an IdentityServices object.
|
||||||
|
*
|
||||||
|
* Authentication is performed, and the returned
|
||||||
|
* service has its tenant ID set already.
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* <?php
|
||||||
|
* // Get the current token.
|
||||||
|
* $this->identity()->token();
|
||||||
|
* ?>
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
protected function identity($reset = FALSE) {
|
||||||
|
|
||||||
|
if ($reset || empty(self::$ident)) {
|
||||||
|
$user = self::conf('hpcloud.identity.username');
|
||||||
|
$pass = self::conf('hpcloud.identity.password');
|
||||||
|
$tenantId = self::conf('hpcloud.identity.tenantId');
|
||||||
|
$url = self::conf('hpcloud.identity.url');
|
||||||
|
|
||||||
|
$is = new \HPCloud\Services\IdentityServices($url);
|
||||||
|
|
||||||
|
$token = $is->authenticateAsUser($user, $pass, $tenantId);
|
||||||
|
|
||||||
|
self::$ident = $is;
|
||||||
|
|
||||||
|
}
|
||||||
|
return self::$ident;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function objectStore($reset = FALSE) {
|
||||||
|
|
||||||
|
if ($reset || empty(self::$ostore)) {
|
||||||
|
$ident = $this->identity($reset);
|
||||||
|
|
||||||
|
$services = $ident->serviceCatalog(\HPCloud\Storage\ObjectStorage::SERVICE_TYPE);
|
||||||
|
|
||||||
|
if (empty($services)) {
|
||||||
|
throw new \Exception('No object-store service found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
//$serviceURL = $services[0]['endpoints'][0]['adminURL'];
|
||||||
|
$serviceURL = $services[0]['endpoints'][0]['publicURL'];
|
||||||
|
|
||||||
|
$objStore = new \HPCloud\Storage\ObjectStorage($ident->token(), $serviceURL);
|
||||||
|
|
||||||
|
self::$ostore = $objStore;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +130,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
|||||||
protected function containerFixture() {
|
protected function containerFixture() {
|
||||||
|
|
||||||
if (empty($this->containerFixture)) {
|
if (empty($this->containerFixture)) {
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
$cname = self::$settings['hpcloud.swift.container'];
|
$cname = self::$settings['hpcloud.swift.container'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -107,7 +162,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
|||||||
* The name of the container.
|
* The name of the container.
|
||||||
*/
|
*/
|
||||||
protected function eradicateContainer($cname) {
|
protected function eradicateContainer($cname) {
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
try {
|
try {
|
||||||
$container = $store->container($cname);
|
$container = $store->container($cname);
|
||||||
}
|
}
|
||||||
@ -133,7 +188,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
|
|||||||
* This should be called in any method that uses containerFixture().
|
* This should be called in any method that uses containerFixture().
|
||||||
*/
|
*/
|
||||||
protected function destroyContainerFixture() {
|
protected function destroyContainerFixture() {
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
$cname = self::$settings['hpcloud.swift.container'];
|
$cname = self::$settings['hpcloud.swift.container'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -67,7 +67,7 @@ class ObjectTest extends \HPCloud\Tests\TestCase {
|
|||||||
public function testSwiftAuth() {
|
public function testSwiftAuth() {
|
||||||
// We know that the object works, so now we test whether it can
|
// We know that the object works, so now we test whether it can
|
||||||
// communicate with Swift.
|
// communicate with Swift.
|
||||||
$storage = $this->swiftAuth();
|
$storage = $this->objectStore();
|
||||||
|
|
||||||
$info = $storage->accountInfo();
|
$info = $storage->accountInfo();
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class ContainerTest extends \HPCloud\Tests\TestCase {
|
|||||||
|
|
||||||
const FNAME = 'testSave';
|
const FNAME = 'testSave';
|
||||||
const FCONTENT = 'This is a test.';
|
const FCONTENT = 'This is a test.';
|
||||||
const FTYPE = 'text/plain';
|
const FTYPE = 'application/x-monkey-file';
|
||||||
|
|
||||||
public function testSave() {
|
public function testSave() {
|
||||||
|
|
||||||
@ -334,7 +334,7 @@ class ContainerTest extends \HPCloud\Tests\TestCase {
|
|||||||
public function testCopyAcrossContainers() {
|
public function testCopyAcrossContainers() {
|
||||||
|
|
||||||
// Create a new container.
|
// Create a new container.
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
$cname = self::$settings['hpcloud.swift.container'] . 'COPY';
|
$cname = self::$settings['hpcloud.swift.container'] . 'COPY';
|
||||||
if ($store->hasContainer($cname)) {
|
if ($store->hasContainer($cname)) {
|
||||||
$this->eradicateContainer($cname);
|
$this->eradicateContainer($cname);
|
||||||
@ -377,7 +377,7 @@ class ContainerTest extends \HPCloud\Tests\TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testAcl() {
|
public function testAcl() {
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
$cname = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
|
$cname = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
|
||||||
|
|
||||||
if ($store->hasContainer($cname)) {
|
if ($store->hasContainer($cname)) {
|
||||||
|
@ -24,8 +24,9 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Swift-based authentication.
|
* Test Swift-based authentication.
|
||||||
* */
|
* @group deprecated
|
||||||
public function testAuthentication() {
|
*/
|
||||||
|
public function testSwiftAuthentication() {
|
||||||
|
|
||||||
$ostore = $this->swiftAuth();
|
$ostore = $this->swiftAuth();
|
||||||
|
|
||||||
@ -33,12 +34,27 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
$this->assertTrue(strlen($ostore->token()) > 0);
|
$this->assertTrue(strlen($ostore->token()) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group auth
|
||||||
|
*/
|
||||||
|
public function testConstructor() {
|
||||||
|
$ostore = $this->objectStore();
|
||||||
|
|
||||||
|
$this->assertInstanceOf('\HPCloud\Storage\ObjectStorage', $ostore);
|
||||||
|
$this->assertTrue(strlen($ostore->token()) > 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group auth
|
||||||
|
* @group acl
|
||||||
|
*/
|
||||||
public function testCreateContainer() {
|
public function testCreateContainer() {
|
||||||
$testCollection = self::$settings['hpcloud.swift.container'];
|
$testCollection = self::$settings['hpcloud.swift.container'];
|
||||||
|
|
||||||
$this->assertNotEmpty($testCollection, "Canary: container name must be in settings file.");
|
$this->assertNotEmpty($testCollection, "Canary: container name must be in settings file.");
|
||||||
|
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();//swiftAuth();
|
||||||
|
|
||||||
if ($store->hasContainer($testCollection)) {
|
if ($store->hasContainer($testCollection)) {
|
||||||
$store->deleteContainer($testCollection);
|
$store->deleteContainer($testCollection);
|
||||||
@ -52,29 +68,31 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @group auth
|
||||||
* @depends testCreateContainer
|
* @depends testCreateContainer
|
||||||
*/
|
*/
|
||||||
public function testAccountInfo () {
|
public function testAccountInfo () {
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
|
|
||||||
$info = $store->accountInfo();
|
$info = $store->accountInfo();
|
||||||
|
|
||||||
$this->assertTrue($info['count'] > 0);
|
$this->assertGreaterThan(0, $info['containers']);
|
||||||
$this->assertTrue($info['bytes'] > 0);
|
$this->assertGreaterThanOrEqual(0, $info['bytes']);
|
||||||
|
$this->assertGreaterThanOrEqual(0, $info['objects']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCreateContainer
|
* @depends testCreateContainer
|
||||||
*/
|
*/
|
||||||
public function testContainers() {
|
public function testContainers() {
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
$containers = $store->containers();
|
$containers = $store->containers();
|
||||||
|
|
||||||
$this->assertNotEmpty($containers);
|
$this->assertNotEmpty($containers);
|
||||||
|
|
||||||
//$first = array_shift($containers);
|
//$first = array_shift($containers);
|
||||||
|
|
||||||
$testCollection = self::$settings['hpcloud.swift.container'];
|
$testCollection = self::conf('hpcloud.swift.container');
|
||||||
$testContainer = $containers[$testCollection];
|
$testContainer = $containers[$testCollection];
|
||||||
$this->assertEquals($testCollection, $testContainer->name());
|
$this->assertEquals($testCollection, $testContainer->name());
|
||||||
$this->assertEquals(0, $testContainer->bytes());
|
$this->assertEquals(0, $testContainer->bytes());
|
||||||
@ -90,7 +108,7 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testContainer() {
|
public function testContainer() {
|
||||||
$testCollection = self::$settings['hpcloud.swift.container'];
|
$testCollection = self::$settings['hpcloud.swift.container'];
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
|
|
||||||
$container = $store->container($testCollection);
|
$container = $store->container($testCollection);
|
||||||
|
|
||||||
@ -108,7 +126,7 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testHasContainer() {
|
public function testHasContainer() {
|
||||||
$testCollection = self::$settings['hpcloud.swift.container'];
|
$testCollection = self::$settings['hpcloud.swift.container'];
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
|
|
||||||
$this->assertTrue($store->hasContainer($testCollection));
|
$this->assertTrue($store->hasContainer($testCollection));
|
||||||
$this->assertFalse($store->hasContainer('nihil'));
|
$this->assertFalse($store->hasContainer('nihil'));
|
||||||
@ -120,7 +138,7 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
public function testDeleteContainer() {
|
public function testDeleteContainer() {
|
||||||
$testCollection = self::$settings['hpcloud.swift.container'];
|
$testCollection = self::$settings['hpcloud.swift.container'];
|
||||||
|
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
//$ret = $store->createContainer($testCollection);
|
//$ret = $store->createContainer($testCollection);
|
||||||
//$this->assertTrue($store->hasContainer($testCollection));
|
//$this->assertTrue($store->hasContainer($testCollection));
|
||||||
|
|
||||||
@ -142,7 +160,7 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
|
|
||||||
$this->assertNotEmpty($testCollection);
|
$this->assertNotEmpty($testCollection);
|
||||||
|
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
$store->createContainer($testCollection);
|
$store->createContainer($testCollection);
|
||||||
|
|
||||||
$container = $store->container($testCollection);
|
$container = $store->container($testCollection);
|
||||||
@ -168,10 +186,11 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCreateContainer
|
* @depends testCreateContainer
|
||||||
|
* @group acl
|
||||||
*/
|
*/
|
||||||
public function testCreateContainerPublic() {
|
public function testCreateContainerPublic() {
|
||||||
$testCollection = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
|
$testCollection = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
if ($store->hasContainer($testCollection)) {
|
if ($store->hasContainer($testCollection)) {
|
||||||
$store->deleteContainer($testCollection);
|
$store->deleteContainer($testCollection);
|
||||||
}
|
}
|
||||||
@ -197,7 +216,7 @@ class ObjectStorageTest extends \HPCloud\Tests\TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testChangeContainerACL() {
|
public function testChangeContainerACL() {
|
||||||
$testCollection = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
|
$testCollection = self::$settings['hpcloud.swift.container'] . 'PUBLIC';
|
||||||
$store = $this->swiftAuth();
|
$store = $this->objectStore();
|
||||||
if ($store->hasContainer($testCollection)) {
|
if ($store->hasContainer($testCollection)) {
|
||||||
$store->deleteContainer($testCollection);
|
$store->deleteContainer($testCollection);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@ use \HPCloud\Storage\ObjectStorage\Container;
|
|||||||
class RemoteObjectTest extends \HPCloud\Tests\TestCase {
|
class RemoteObjectTest extends \HPCloud\Tests\TestCase {
|
||||||
|
|
||||||
const FNAME = 'RemoteObjectTest';
|
const FNAME = 'RemoteObjectTest';
|
||||||
const FTYPE = 'text/plain';
|
//const FTYPE = 'text/plain; charset=UTF-8';
|
||||||
|
const FTYPE = 'application/octet-stream; charset=UTF-8';
|
||||||
const FCONTENT = 'Rah rah ah ah ah. Roma roma ma. Gaga oh la la.';
|
const FCONTENT = 'Rah rah ah ah ah. Roma roma ma. Gaga oh la la.';
|
||||||
const FMETA_NAME = 'Foo';
|
const FMETA_NAME = 'Foo';
|
||||||
const FMETA_VALUE = 'Bar';
|
const FMETA_VALUE = 'Bar';
|
||||||
|
@ -50,8 +50,8 @@ class StreamWrapperTest extends \HPCloud\Tests\TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$params = $add + array(
|
$params = $add + array(
|
||||||
'token' => self::$ostore->token(),
|
'token' => $this->objectStore()->token(),
|
||||||
'swift_endpoint' => self::$ostore->url(),
|
'swift_endpoint' => $this->objectStore()->url(),
|
||||||
);
|
);
|
||||||
$cxt = array($scheme => $params);
|
$cxt = array($scheme => $params);
|
||||||
|
|
||||||
@ -60,12 +60,16 @@ class StreamWrapperTest extends \HPCloud\Tests\TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This performs authentication via context.
|
* This performs authentication via context.
|
||||||
|
*
|
||||||
|
* UPDATE: This now users IdentityServices instead of deprecated
|
||||||
|
* swauth.
|
||||||
*/
|
*/
|
||||||
protected function authSwiftContext($add = array(), $scheme = NULL) {
|
protected function authSwiftContext($add = array(), $scheme = NULL) {
|
||||||
$cname = self::$settings['hpcloud.swift.container'];
|
$cname = self::$settings['hpcloud.swift.container'];
|
||||||
$account = self::$settings['hpcloud.swift.account'];
|
$account = self::$settings['hpcloud.identity.account'];
|
||||||
$key = self::$settings['hpcloud.swift.key'];
|
$key = self::$settings['hpcloud.identity.secret'];
|
||||||
$baseURL = self::$settings['hpcloud.swift.url'];
|
$tenant = self::$settings['hpcloud.identity.tenantId'];
|
||||||
|
$baseURL = self::$settings['hpcloud.identity.url'];
|
||||||
|
|
||||||
if (empty($scheme)) {
|
if (empty($scheme)) {
|
||||||
$scheme = StreamWrapper::DEFAULT_SCHEME;
|
$scheme = StreamWrapper::DEFAULT_SCHEME;
|
||||||
@ -75,6 +79,7 @@ class StreamWrapperTest extends \HPCloud\Tests\TestCase {
|
|||||||
'account' => $account,
|
'account' => $account,
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'endpoint' => $baseURL,
|
'endpoint' => $baseURL,
|
||||||
|
'tenantid' => $tenant,
|
||||||
);
|
);
|
||||||
$cxt = array($scheme => $params);
|
$cxt = array($scheme => $params);
|
||||||
|
|
||||||
@ -82,6 +87,7 @@ class StreamWrapperTest extends \HPCloud\Tests\TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add additional params to the config.
|
* Add additional params to the config.
|
||||||
*
|
*
|
||||||
@ -92,11 +98,12 @@ class StreamWrapperTest extends \HPCloud\Tests\TestCase {
|
|||||||
*/
|
*/
|
||||||
protected function addBootstrapConfig() {
|
protected function addBootstrapConfig() {
|
||||||
$opts = array(
|
$opts = array(
|
||||||
'account' => self::$settings['hpcloud.swift.account'],
|
'account' => self::$settings['hpcloud.identity.account'],
|
||||||
'key' => self::$settings['hpcloud.swift.key'],
|
'key' => self::$settings['hpcloud.identity.secret'],
|
||||||
'endpoint' => self::$settings['hpcloud.swift.url'],
|
'endpoint' => self::$settings['hpcloud.identity.url'],
|
||||||
'token' => self::$ostore->token(),
|
'tenantit' => self::$settings['hpcloud.identity.tenantId'],
|
||||||
'swift_endpoint' => self::$ostore->url(),
|
'token' => $this->objectStore()->token(),
|
||||||
|
'swift_endpoint' => $this->objectStore()->url(),
|
||||||
);
|
);
|
||||||
\HPCloud\Bootstrap::setConfiguration($opts);
|
\HPCloud\Bootstrap::setConfiguration($opts);
|
||||||
|
|
||||||
@ -108,7 +115,7 @@ class StreamWrapperTest extends \HPCloud\Tests\TestCase {
|
|||||||
$array = stream_context_get_options($cxt);
|
$array = stream_context_get_options($cxt);
|
||||||
|
|
||||||
$opts = $array['swift'];
|
$opts = $array['swift'];
|
||||||
$endpoint = self::$settings['hpcloud.swift.url'];
|
$endpoint = self::conf('hpcloud.identity.url');
|
||||||
|
|
||||||
$this->assertEquals($endpoint, $opts['endpoint'], 'A UTF-8 encoding issue.');
|
$this->assertEquals($endpoint, $opts['endpoint'], 'A UTF-8 encoding issue.');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user