Пример #1
0
 /**
  * @depends testPutAndListObjects
  */
 public function testGetObjectAcl()
 {
     self::log("Getting the object's ACL");
     $model = $this->client->getObjectAcl(array('Bucket' => $this->bucket, 'Key' => self::TEST_KEY));
     $data = array();
     foreach (Acp::fromArray($model->toArray()) as $grant) {
         $grantee = $grant->getGrantee();
         $data[$grantee->getGroupUri()] = array($grantee->getType(), $grant->getPermission());
     }
     $this->assertEquals(2, count($data));
     $this->assertArrayHasKey('http://acs.amazonaws.com/groups/global/AllUsers', $data);
     $this->assertArrayHasKey('http://acs.amazonaws.com/groups/global/AuthenticatedUsers', $data);
     $this->assertEquals(array('Group', 'READ_ACP'), $data['http://acs.amazonaws.com/groups/global/AllUsers']);
     $this->assertEquals(array('Group', 'READ'), $data['http://acs.amazonaws.com/groups/global/AuthenticatedUsers']);
 }
Пример #2
0
 /**
  * Write a string to a file
  *
  * @param  string  $path     file path
  * @param  string  $content  new file content
  * @return bool
  * */
 protected function _filePutContents($path, $content)
 {
     $oldSettings = $this->getFile($path);
     $settings = array("Bucket" => $this->bucket, "Key" => $path, "ACL" => $this->options['acl'], "Body" => $content);
     if ($oldSettings) {
         $settings['Metadata'] = $oldSettings['Metadata'];
         $settings['ContentType'] = $oldSettings['ContentType'];
         $settings['ACP'] = \Aws\S3\Model\Acp::fromArray($this->s3->getObjectAcl(array('Bucket' => $this->bucket, 'Key' => $path))->toArray());
         unset($settings['ACL']);
     }
     return $this->s3->putObject($settings);
 }
Пример #3
0
 public function testUploadFile()
 {
     $this->migrate();
     $this->login();
     // Preparation: Create an image entry.
     $image = $this->app->createModel('image', array('position' => 0));
     R::store($image);
     $this->assertNotEmpty($image->getID());
     // upload to aws s3
     $filename = 'original.jpg';
     $filepath = realpath(__DIR__ . '/' . $filename);
     $_SERVER['REQUEST_METHOD'] = "POST";
     $params = array('image_id' => $image->getID(), 'data' => '{ "id": ' . $image->getID() . ', "type": "uploadOnce", "settingName": "multiple_many_types" }', 'settingName' => 'multiple_many_types', 'uploadOnce' => 1);
     $size = filesize($filepath);
     $_FILES = array('file-0' => array('name' => $filename, 'type' => 'image/jpeg', 'tmp_name' => $filepath, 'error' => 0, 'size' => $size));
     ob_start();
     $this->app->runControllerFromRawUrl('admin/cRUDImages/uploadImage', $params);
     $output = ob_get_clean();
     echo "\nOutput of uploadImage:\n";
     echo $output;
     $output_r = json_decode($output);
     print_r($output_r);
     $this->assertFalse(property_exists($output_r[0], 'error'));
     // See if file uploaded successfully.
     echo "\nFind image with id " . $image->getID();
     $imageBean = R::findOne('image', 'id = ?', array($image->getID()));
     $this->assertNotEmpty($imageBean);
     echo "\n...Found!";
     $data = json_decode($imageBean['multiple_many_types']);
     echo "\nUploaded images:\n";
     print_r($data);
     $this->assertEquals(1, count($data));
     // Uploaded data must contain 'images/Image/1/original-smartphone'
     $this->assertNotEquals(-1, strpos(SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone), 'public/images/Image/' . $image->getID() . '/original-smartphone'));
     // Now see if file does exist in Amazon S3 repository.
     $amazonS3Config = $this->app->config('amazonS3');
     $client = \Aws\S3\S3Client::factory($amazonS3Config['settings']);
     $result = $client->getObject(array('Bucket' => $amazonS3Config['bucket'], 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone)));
     $this->assertNotEmpty($result['Body']);
     //        $this->app->getLogger()->log("result get object : " . print_r($result, true));
     // TEST ACL
     $resultAcl = $client->getObjectAcl(array('Bucket' => $amazonS3Config['bucket'], 'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone)));
     //        $this->app->getLogger()->log("result get object ACL : " . print_r($resultAcl, true));
     $this->assertNotEmpty($resultAcl["Grants"]);
     $dataAcl = array();
     foreach (\Aws\S3\Model\Acp::fromArray($resultAcl->toArray()) as $grant) {
         $grantee = $grant->getGrantee();
         $dataAcl[$grantee->getGroupUri()] = array($grantee->getType(), $grant->getPermission());
     }
     $this->assertEquals(2, count($dataAcl));
     $this->assertArrayHasKey('http://acs.amazonaws.com/groups/global/AllUsers', $dataAcl);
     $this->assertEquals(array('Group', 'READ'), $dataAcl['http://acs.amazonaws.com/groups/global/AllUsers']);
     // ---- end of test ACL ----
     // Local file must have been deleted.
     $filepath = \Skully\App\Helpers\FileHelper::replaceSeparators($this->app->getTheme()->getBasePath() . $data[0]->smartphone);
     echo "\nChecking if file {$filepath} is deleted...";
     $this->assertFalse(file_exists($filepath));
     echo "\nYep";
     // Delete Models
     try {
         R::trash($imageBean);
     } catch (\Exception $e) {
         echo 'failed to delete image bean. reason: ' . $e->getMessage();
     }
     //        // Cleanup by removing files in bucket.
     //        $client->deleteObject(array(
     //            'Bucket' => $amazonS3Config['bucket'],
     //            'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone))
     //        );
     //
     //        $client->deleteObject(array(
     //            'Bucket' => $amazonS3Config['bucket'],
     //            'Key' => SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->desktop))
     //        );
     // Check existence of deleted files on s3 server
     $result = $client->doesObjectExist($amazonS3Config['bucket'], SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->smartphone));
     $this->assertFalse($result);
     $result = $client->doesObjectExist($amazonS3Config['bucket'], SkullyAwsS3\Helpers\S3Helpers::key($this->app->config('publicDir'), $data[0]->desktop));
     $this->assertFalse($result);
 }
Пример #4
0
 public function testAssumesGrantTypesFromContext()
 {
     $data = array('Owner' => array('ID' => 'foo', 'DisplayName' => 'foo'), 'Grants' => array(array('Grantee' => array('ID' => 'baz', 'DisplayName' => 'baz'), 'Permission' => 'READ'), array('Grantee' => array('URI' => Group::AUTHENTICATED_USERS), 'Permission' => 'READ'), array('Grantee' => array('EmailAddress' => '*****@*****.**'), 'Permission' => 'WRITE')));
     $acp = Acp::fromArray($data);
     $this->assertEquals(array('Owner' => array('ID' => 'foo', 'DisplayName' => 'foo'), 'Grants' => array(array('Grantee' => array('Type' => 'CanonicalUser', 'ID' => 'baz', 'DisplayName' => 'baz'), 'Permission' => 'READ'), array('Grantee' => array('Type' => 'Group', 'URI' => 'http://acs.amazonaws.com/groups/global/AuthenticatedUsers'), 'Permission' => 'READ'), array('Grantee' => array('Type' => 'AmazonCustomerByEmail', 'EmailAddress' => '*****@*****.**'), 'Permission' => 'WRITE'))), $acp->toArray());
 }