Differential D17625 Diff 42394 src/applications/files/format/__tests__/PhabricatorFileStorageFormatTestCase.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/format/__tests__/PhabricatorFileStorageFormatTestCase.php
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | public function testAES256Storage() { | ||||
// the decrypted file. | // the decrypted file. | ||||
$iterator = $file->getFileDataIterator(4, 14); | $iterator = $file->getFileDataIterator(4, 14); | ||||
$raw_data = ''; | $raw_data = ''; | ||||
foreach ($iterator as $data_chunk) { | foreach ($iterator as $data_chunk) { | ||||
$raw_data .= $data_chunk; | $raw_data .= $data_chunk; | ||||
} | } | ||||
$this->assertEqual('cow jumped', $raw_data); | $this->assertEqual('cow jumped', $raw_data); | ||||
} | } | ||||
public function testStorageTampering() { | |||||
$engine = new PhabricatorTestStorageEngine(); | |||||
$good = 'The cow jumped over the full moon.'; | |||||
$evil = 'The cow slept quietly, honoring the glorious dictator.'; | |||||
$params = array( | |||||
'name' => 'message.txt', | |||||
'storageEngines' => array( | |||||
$engine, | |||||
), | |||||
); | |||||
// First, write the file normally. | |||||
$file = PhabricatorFile::newFromFileData($good, $params); | |||||
$this->assertEqual($good, $file->loadFileData()); | |||||
// As an adversary, tamper with the file. | |||||
$engine->tamperWithFile($file->getStorageHandle(), $evil); | |||||
// Attempts to read the file data should now fail the integrity check. | |||||
$caught = null; | |||||
try { | |||||
$file->loadFileData(); | |||||
} catch (PhabricatorFileIntegrityException $ex) { | |||||
$caught = $ex; | |||||
} | |||||
$this->assertTrue($caught instanceof PhabricatorFileIntegrityException); | |||||
} | |||||
} | } |