Esempio n. 1
0
 public function testConstructor()
 {
     $curl = new CURLTransport();
     // This is prone to failure because instance() caches
     // the class.
     $trans = '\\HPCloud\\Transport\\CURLTransport';
     \HPCloud\Bootstrap::setConfiguration(array('transport' => $trans));
     // Need to test getting instance from Bootstrap.
     $this->assertInstanceOf($trans, Transport::instance());
 }
Esempio n. 2
0
 public static function setUpBeforeClass()
 {
     global $bootstrap_settings;
     if (!isset($bootstrap_settings)) {
         $bootstrap_settings = array();
     }
     self::$settings = $bootstrap_settings;
     //$this->setTestNamespace('Tests\Units');
     if (file_exists('test/settings.ini')) {
         self::$settings += parse_ini_file('test/settings.ini');
     } else {
         throw new \Exception('Could not access test/settings.ini');
     }
     \HPCloud\Bootstrap::useAutoloader();
     \HPCloud\Bootstrap::setConfiguration(self::$settings);
     //parent::__construct($score, $locale, $adapter);
 }
<?php

require_once __DIR__ . '/../src/HPCloud/Bootstrap.php';
use HPCloud\Bootstrap;
Bootstrap::useAutoloader();
Bootstrap::useStreamWrappers();
$ini = parse_ini_file(getenv('HOME') . '/.hpcloud.ini');
$settings = array('username' => $ini['username'], 'password' => $ini['password'], 'tenantid' => $ini['tenantId'], 'endpoint' => $ini['url']);
Bootstrap::setConfiguration($settings);
// Create a new file and write it to the object store.
$newfile = fopen('swift://Example/my_file.txt', 'w');
fwrite($newfile, "Good Morning!");
fclose($newfile);
// Check for an object:
if (file_exists('swift://Example/my_file.txt')) {
    print "Found my_file.txt." . PHP_EOL;
}
// Get an entire object at once:
$file = file_get_contents('swift://Example/my_file.txt');
print 'File: ' . $file . PHP_EOL;
$cxt = stream_context_create(array('swift' => array('account' => $ini['account'], 'key' => $ini['secret'], 'tenantid' => $ini['tenantId'], 'endpoint' => $ini['url'])));
print file_get_contents('swift://Example/my_file.txt', FALSE, $cxt);
Esempio n. 4
0
 public function testStreamContext()
 {
     // Reset this in case something else left its
     // auth token lying around.
     \HPCloud\Bootstrap::setConfiguration(array('token' => NULL));
     $cxt = $this->authSwiftContext();
     $array = stream_context_get_options($cxt);
     $opts = $array['swift'];
     $endpoint = self::conf('hpcloud.identity.url');
     $this->assertEquals($endpoint, $opts['endpoint'], 'A UTF-8 encoding issue.');
 }
 /**
  * Testing the account options separately since they are only in HP Helion
  * Public Cloud and may be skipped.
  *
  * @depends testAuthenticateAsAccount
  */
 function testBootstrapAsAccount()
 {
     $reset = Bootstrap::$config;
     // Test authenticating as an account.
     $settings = array('account' => self::conf('hpcloud.identity.account'), 'secret' => self::conf('hpcloud.identity.secret'), 'endpoint' => self::conf('hpcloud.identity.url'), 'tenantid' => self::conf('hpcloud.identity.tenantId'));
     Bootstrap::setConfiguration($settings);
     $is = Bootstrap::identity(TRUE);
     $this->assertInstanceOf('\\HPCloud\\Services\\IdentityServices', $is);
     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);
 }
 public function testStreamContext()
 {
     // Clear old values.
     \HPCloud\Bootstrap::setConfiguration(array('token' => NULL));
     $cxt = $this->authSwiftContext();
     $array = stream_context_get_options($cxt);
     $opts = $array['swiftfs'];
     $endpoint = self::conf('hpcloud.identity.url');
     $this->assertEquals($endpoint, $opts['endpoint'], 'A UTF-8 encoding issue.');
 }
Esempio n. 7
0
 * @file
 * A commandline demonstration of the PHP API.
 */
// Name of the container to test. It must have
// CDN enabled. Using the one you use for standard
// tests is ill advised.
define('TEST_CONTAINER', 'mycontainer');
$base = __DIR__ . '/../src';
require_once $base . '/HPCloud/Bootstrap.php';
\HPCloud\Bootstrap::useAutoloader();
$inifile = __DIR__ . '/settings.ini';
if (!is_readable($inifile)) {
    die('Could not find ' . $inifile);
}
$ini = parse_ini_file($inifile, FALSE);
\HPCloud\Bootstrap::setConfiguration($ini);
\HPCloud\Bootstrap::useStreamWrappers();
$id = new \HPCloud\Services\IdentityServices($ini['hpcloud.identity.url']);
//$token = $id->authenticateAsAccount($ini['hpcloud.identity.account'], $ini['hpcloud.identity.secret'], $ini['hpcloud.identity.tenantId']);
$token = $id->authenticateAsUser($ini['hpcloud.identity.username'], $ini['hpcloud.identity.password'], $ini['hpcloud.identity.tenantId']);
$objstore = \HPCloud\Storage\ObjectStorage::newFromServiceCatalog($id->serviceCatalog(), $token);
$cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($id->serviceCatalog(), $token);
$objstore->useCDN($cdn);
//var_dump($cdn->containers());
// Check that the container has CDN.
$cname = TEST_CONTAINER;
//$ini['hpcloud.swift.container'];
$isEnabled = FALSE;
$cdnData = $cdn->container($cname);
print "***** TESTING CDN ENABLED" . PHP_EOL;
if ($cdnData['cdn_enabled'] != 1) {
Esempio n. 8
0
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
============================================================================ */
/**
 * @file
 * This is a simple command-line test for authentication.
 *
 * You can run the test with `php test/AuthTest.php username key`.
 */
$base = dirname(__DIR__);
require_once $base . '/src/HPCloud/Bootstrap.php';
use HPCloud\Storage\ObjectStorage;
use HPCloud\Services\IdentityServices;
$config = array('transport' => '\\HPCloud\\Transport\\CURLTransport', 'transport.timeout' => 240, 'transport.ssl.verify' => 0);
\HPCloud\Bootstrap::useAutoloader();
\HPCloud\Bootstrap::setConfiguration($config);
$help = "Authenticate against HPCloud Identity Services.\n\nYou can authenticate either by account number and access key, or (by using the\n-u flag) by username, password.\n\nWhile Tenant ID is optional, it is recommended.\n\nIn both cases, you must supply a URL to the Identity Services endpoint.\n";
$usage = "php {$argv[0]} [-u] ID SECRET URL [TENANT_ID]";
if ($argc > 1 && $argv[1] == '--help') {
    print PHP_EOL . "\t" . $usage . PHP_EOL;
    print PHP_EOL . $help . PHP_EOL;
    exit(1);
} elseif ($argc < 4) {
    print 'ID, Key, and URL are all required.' . PHP_EOL;
    print $usage . PHP_EOL;
    exit(1);
}
$asUser = FALSE;
$offset = 0;
if ($argv[1] == '-u') {
    $asUser = TRUE;
Esempio n. 9
0
<?php

require_once $this->getBaseDir() . "/HPCloud/Bootstrap.php";
\HPCloud\Bootstrap::useAutoloader();
\HPCloud\Bootstrap::useStreamWrappers();
\HPCloud\Bootstrap::setConfiguration(array('username' => $this->repository->getOption("USERNAME"), 'password' => $this->repository->getOption("PASSWORD"), 'tenantid' => $this->repository->getOption("TENANT_ID"), 'endpoint' => $this->repository->getOption("ENDPOINT"), 'transport.ssl.verify' => false));