Added tenantName support to Bootstrap::identity.

This commit is contained in:
Matt Farina 2012-06-13 15:37:13 -04:00
parent 5914dd1984
commit 7448eb5280
2 changed files with 36 additions and 3 deletions

View File

@ -356,14 +356,14 @@ class Bootstrap {
// Check if we have a username/password // Check if we have a username/password
if (!empty($user) && self::hasConfig('password')) { if (!empty($user) && self::hasConfig('password')) {
$is = new IdentityServices(self::config('endpoint')); $is = new IdentityServices(self::config('endpoint'));
$is->authenticateAsUser($user, self::config('password'), self::config('tenantid', NULL)); $is->authenticateAsUser($user, self::config('password'), self::config('tenantid', NULL), self::config('tenantname', NULL));
self::$identity = $is; self::$identity = $is;
} }
// Otherwise we go with access/secret keys // Otherwise we go with access/secret keys
elseif (!empty($account) && self::hasConfig('secret')) { elseif (!empty($account) && self::hasConfig('secret')) {
$is = new IdentityServices(self::config('endpoint')); $is = new IdentityServices(self::config('endpoint'));
$is->authenticateAsAccount($account, self::config('secret'), self::config('tenantid', NULL)); $is->authenticateAsAccount($account, self::config('secret'), self::config('tenantid', NULL), self::config('tenantname', NULL));
self::$identity = $is; self::$identity = $is;
} }

View File

@ -453,6 +453,12 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
*/ */
function testBootstrap() { function testBootstrap() {
// We need to save the config settings and reset the bootstrap to this.
// It does not remove the old settings. The means the identity fall through
// for different settings may not happen because of ordering. So, we cache
// and reset back to the default for each test.
$reset = Bootstrap::$config;
// Test authenticating as a user. // Test authenticating as a user.
$settings = array( $settings = array(
'username' => self::conf('hpcloud.identity.username'), 'username' => self::conf('hpcloud.identity.username'),
@ -465,10 +471,12 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
$is = Bootstrap::identity(TRUE); $is = Bootstrap::identity(TRUE);
$this->assertInstanceOf('\HPCloud\Services\IdentityServices', $is); $this->assertInstanceOf('\HPCloud\Services\IdentityServices', $is);
Bootstrap::$config = $reset;
// Test authenticating as an account. // Test authenticating as an account.
$settings = array( $settings = array(
'account' => self::conf('hpcloud.identity.account'), 'account' => self::conf('hpcloud.identity.account'),
'key' => self::conf('hpcloud.identity.secret'), 'secret' => self::conf('hpcloud.identity.secret'),
'endpoint' => self::conf('hpcloud.identity.url'), 'endpoint' => self::conf('hpcloud.identity.url'),
'tenantid' => self::conf('hpcloud.identity.tenantId'), 'tenantid' => self::conf('hpcloud.identity.tenantId'),
); );
@ -484,5 +492,30 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
// Test that forcing a refresh does so. // Test that forcing a refresh does so.
$is2 = Bootstrap::identity(TRUE); $is2 = Bootstrap::identity(TRUE);
$this->assertNotEquals($is, $is2); $this->assertNotEquals($is, $is2);
Bootstrap::$config = $reset;
// Test with tenant name
$settings = array(
'account' => self::conf('hpcloud.identity.account'),
'secret' => self::conf('hpcloud.identity.secret'),
'endpoint' => self::conf('hpcloud.identity.url'),
'tenantname' => self::conf('hpcloud.identity.tenantName'),
);
Bootstrap::setConfiguration($settings);
$is = Bootstrap::identity(TRUE);
$this->assertInstanceOf('\HPCloud\Services\IdentityServices', $is);
$settings = array(
'username' => self::conf('hpcloud.identity.username'),
'password' => self::conf('hpcloud.identity.password'),
'endpoint' => self::conf('hpcloud.identity.url'),
'tenantname' => self::conf('hpcloud.identity.tenantName'),
);
Bootstrap::setConfiguration($settings);
$is = Bootstrap::identity(TRUE);
$this->assertInstanceOf('\HPCloud\Services\IdentityServices', $is);
} }
} }