Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once BASE_PATH . "lib/crypt/AES.php";
- DEFINE ("AES_256_CBC_KEYSIZE", 32);
- DEFINE ("AES_256_CBC_IVSIZE", 16);
- class CloudTest extends PHPUnit_Framework_TestCase {
- protected $f3;
- protected $oca_base_url;
- protected $oca_username;
- protected $oca_password;
- protected $user_id;
- function setUp() {
- $this->f3 = base::instance();
- $this->oca_base_url = $this->f3->get('cloud_service');
- $this->oca_username = $this->f3->get('cloud_username');
- $this->oca_password = $this->f3->get('cloud_password');
- $this->user_id= "guest_user_id";
- }
- /** return expiration time .. should be better */
- function giveExpire() {
- return (string)(time()+3600);
- }
- /** return a key from a truncated SHA1 hexhash */
- function giveKey() {
- return substr(sha1($this->oca_password), 0, AES_256_CBC_KEYSIZE);
- }
- /** return an Auth Token for OpenNebula
- */
- function getAuthToken() {
- $key = $this->giveKey();
- $data = $this->oca_username . ":" . $this->user_id. ":" . $this->giveExpire();
- $cipher = new Crypt_AES();
- $cipher->setKey($key);
- // WARNING: OpenNebula does not set any IV
- return $this->oca_username . ":" . $this->user_id. ":" . base64_encode($cipher->encrypt($data));
- }
- /**
- * @group XMLRPC
- */
- function test_request_rpc_1() {
- // build userAuth
- $userAuth = $this->getAuthToken();
- $request = xmlrpc_encode_request("one.vmpool.info", array($userAuth, -2, -1, -1 , -1));
- $content = stream_context_create(array(
- "http" => array("method" => "POST",
- "header" => "Content-Type: text/xml",
- "content" => $request
- )
- ));
- $file = file_get_contents($this->oca_base_url, false, $content);
- $response = xmlrpc_decode($file);
- $this->assertTrue(isset($response), "Unset reply from RPCServer");
- $this->assertTrue($response[0], "Invalid reply from RPCServer");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement