Merge branch 'develop' of github.hpcloud.net:butchema/HPCloud-PHP into develop
This commit is contained in:
commit
70dc429d0d
@ -356,14 +356,14 @@ class Bootstrap {
|
||||
// Check if we have a username/password
|
||||
if (!empty($user) && self::hasConfig('password')) {
|
||||
$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;
|
||||
}
|
||||
|
||||
// Otherwise we go with access/secret keys
|
||||
elseif (!empty($account) && self::hasConfig('secret')) {
|
||||
$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;
|
||||
}
|
||||
|
||||
|
@ -451,6 +451,28 @@ class Object {
|
||||
return $this->additionalHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove headers.
|
||||
*
|
||||
* This takes an array of header names, and removes
|
||||
* any matching headers. Typically, only headers set
|
||||
* by setAdditionalHeaders() are removed from an Object.
|
||||
* (RemoteObject works differently).
|
||||
*
|
||||
* @attention
|
||||
* Many headers are generated automatically, such as
|
||||
* Content-Type and Content-Length. Removing these
|
||||
* will simply result in their being regenerated.
|
||||
*
|
||||
* @param array $keys
|
||||
* The header names to be removed.
|
||||
*/
|
||||
public function removeHeaders($keys) {
|
||||
foreach ($keys as $k) {
|
||||
unset($this->additionalHeaders[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This object should be transmitted in chunks.
|
||||
*
|
||||
|
@ -125,7 +125,8 @@ class RemoteObject extends Object {
|
||||
public static function newFromHeaders($name, $headers, $token, $url, $cdnUrl = NULL, $cdnSslUrl = NULL) {
|
||||
$object = new RemoteObject($name);
|
||||
|
||||
$object->allHeaders = $headers;
|
||||
//$object->allHeaders = $headers;
|
||||
$object->setHeaders($headers);
|
||||
|
||||
//throw new \Exception(print_r($headers, TRUE));
|
||||
|
||||
@ -259,6 +260,16 @@ class RemoteObject extends Object {
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
public function setHeaders($headers) {
|
||||
$this->allHeaders = array();
|
||||
|
||||
foreach ($headers as $name => $value) {
|
||||
if (strpos($name, Container::METADATA_HEADER_PREFIX) !== 0) {
|
||||
$this->allHeaders[$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP headers sent by the server.
|
||||
*
|
||||
@ -274,6 +285,41 @@ class RemoteObject extends Object {
|
||||
return $this->allHeaders;
|
||||
}
|
||||
|
||||
public function additionalHeaders() {
|
||||
// Any additional headers will be set. Note that $this->headers will contain
|
||||
// some headers that are NOT additional. But we do not know which headers are
|
||||
// additional and which are from Swift because Swift does not commit to using
|
||||
// a specific set of headers.
|
||||
$additionalHeaders = parent::additionalHeaders() + $this->headers;
|
||||
|
||||
return $additionalHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array of header names.
|
||||
*
|
||||
* This will remove the given headers from the existing headers.
|
||||
* Both additional headers and the original headers from the
|
||||
* server are affected here.
|
||||
*
|
||||
* Note that you cannot remove metadata through this mechanism,
|
||||
* as it is managed using the metadata() methods.
|
||||
*
|
||||
* @attention
|
||||
* Many headers are generated automatically, such as
|
||||
* Content-Type and Content-Length. Removing these
|
||||
* will simply result in their being regenerated.
|
||||
*
|
||||
* @param array $keys
|
||||
* The header names to be removed.
|
||||
*/
|
||||
public function removeHeaders($keys) {
|
||||
foreach ($keys as $key) {
|
||||
unset($this->allHeaders[$key]);
|
||||
unset($this->additionalHeaders[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of this object.
|
||||
*
|
||||
|
@ -453,6 +453,12 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
|
||||
*/
|
||||
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.
|
||||
$settings = array(
|
||||
'username' => self::conf('hpcloud.identity.username'),
|
||||
@ -465,10 +471,12 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
|
||||
$is = Bootstrap::identity(TRUE);
|
||||
$this->assertInstanceOf('\HPCloud\Services\IdentityServices', $is);
|
||||
|
||||
Bootstrap::$config = $reset;
|
||||
|
||||
// Test authenticating as an account.
|
||||
$settings = array(
|
||||
'account' => self::conf('hpcloud.identity.account'),
|
||||
'key' => self::conf('hpcloud.identity.secret'),
|
||||
'secret' => self::conf('hpcloud.identity.secret'),
|
||||
'endpoint' => self::conf('hpcloud.identity.url'),
|
||||
'tenantid' => self::conf('hpcloud.identity.tenantId'),
|
||||
);
|
||||
@ -484,5 +492,30 @@ class IdentityServicesTest extends \HPCloud\Tests\TestCase {
|
||||
// Test that forcing a refresh does so.
|
||||
$is2 = Bootstrap::identity(TRUE);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
@ -131,4 +131,24 @@ class ObjectTest extends \HPCloud\Tests\TestCase {
|
||||
$this->assertEquals('Leibniz', $got['Gottfried']);
|
||||
|
||||
}
|
||||
|
||||
public function testAdditionalHeaders() {
|
||||
$o = $this->basicObjectFixture();
|
||||
|
||||
$extra = array(
|
||||
'a' => 'b',
|
||||
'aaa' => 'bbb',
|
||||
'ccc' => 'bbb',
|
||||
);
|
||||
$o->setAdditionalHeaders($extra);
|
||||
|
||||
$got = $o->additionalHeaders();
|
||||
$this->assertEquals(3, count($got));
|
||||
|
||||
$o->removeHeaders(array('ccc'));
|
||||
|
||||
|
||||
$got = $o->additionalHeaders();
|
||||
$this->assertEquals(2, count($got));
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,10 @@ class RemoteObjectTest extends \HPCloud\Tests\TestCase {
|
||||
$object->setMetadata(array(self::FMETA_NAME => self::FMETA_VALUE));
|
||||
$object->setDisposition(self::FDISPOSITION);
|
||||
$object->setEncoding(self::FENCODING);
|
||||
$object->setAdditionalHeaders(array(
|
||||
'Access-Control-Allow-Origin' => 'http://example.com',
|
||||
'Access-control-allow-origin' => 'http://example.com',
|
||||
));
|
||||
|
||||
// Need some headers that Swift actually stores and returns. This
|
||||
// one does not seem to be returned ever.
|
||||
@ -146,6 +150,15 @@ class RemoteObjectTest extends \HPCloud\Tests\TestCase {
|
||||
$headers = $obj->headers();
|
||||
$this->assertTrue(count($headers) > 1);
|
||||
|
||||
fwrite(STDOUT, print_r($headers, TRUE));
|
||||
|
||||
$this->assertNotEmpty($headers['Date']);
|
||||
|
||||
$obj->removeHeaders(array('Date'));
|
||||
|
||||
$headers = $obj->headers();
|
||||
$this->assertFalse(isset($headers['Date']));
|
||||
|
||||
// Swift doesn't return CORS headers even though it is supposed to.
|
||||
//$this->assertEquals(self::FCORS_VALUE, $headers[self::FCORS_NAME]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user