Skip to content
Browse files

Polishing the rawphoto changes, including adding some tests.

Squashed commit of the following:

commit 945316a
Author: Chad Parry <github@chad.parry.org>
Date:   Thu Jul 21 01:11:13 2011 -0600

    Add a test for the sunny-day scenario where a rule changes a data file's MIME type.

commit 4ee1ee0
Author: Chad Parry <github@chad.parry.org>
Date:   Thu Jul 21 00:49:47 2011 -0600

    Ensure that a third-party cannot swap out a legitimate photo with an unsafe file type.

commit 7dd0105
Author: Chad Parry <github@chad.parry.org>
Date:   Thu Jul 21 00:48:19 2011 -0600

    Update the MIME type and other meta-data when a new data file is provided.

commit 5a8844c
Author: Chad Parry <github@chad.parry.org>
Date:   Thu Jul 21 00:30:01 2011 -0600

    Remove a unit test that no longer applies. Replacement data files are allowed to have different MIME types.

commit 0de9c62
Author: Chad Parry <github@chad.parry.org>
Date:   Thu Jul 21 00:27:45 2011 -0600

    If one rule fails, then abort processing, rather than trying to proceed to subsequent rules.

commit 41d379c
Author: Chad Parry <github@chad.parry.org>
Date:   Thu Jul 21 00:10:10 2011 -0600

    Replace an overly-complicated regular expression with a simple in_array, at Bharat's suggestion.

commit 1b3f711
Merge: 8f7904a 403f64b
Author: Chad Parry <github@chad.parry.org>
Date:   Wed Jul 20 21:02:56 2011 -0600

    Merge branch 'master' into rawphoto

commit 8f7904a
Merge: e950573 771de0a
Author: Chad Parry <github@chad.parry.org>
Date:   Sat Jun 25 14:12:39 2011 -0600

    Merge branches 'master' and 'rawphoto' into rawphoto

commit e950573
Author: Chad Parry <github@chad.parry.org>
Date:   Wed Jun 15 20:24:18 2011 -0600

    Merge branches 'rawphoto-squash' and 'rawphoto' into rawphoto
  • Loading branch information...
1 parent fc32b9f commit 0672c8f83f068c546454bacefac123b5acb508cc @chadparry chadparry committed Jul 21, 2011
View
10 modules/gallery/helpers/graphics.php
@@ -170,14 +170,8 @@ static function generate($item) {
foreach (self::_get_rules($target) as $rule) {
$args = array($working_file, $output_file, unserialize($rule->args), $item);
- try {
- call_user_func_array($rule->operation, $args);
- $working_file = $output_file;
- } catch (Exception $e) {
- // Ignore this rule and move on.
- Kohana_Log::add("error", "Caught exception processing image: {$item->title}\n" .
- $e->getMessage() . "\n" . $e->getTraceAsString());
- }
+ call_user_func_array($rule->operation, $args);
+ $working_file = $output_file;
}
}
View
7 modules/gallery/models/item.php
@@ -420,6 +420,13 @@ public function save() {
if (!empty($extension) && strcmp($this->name, $new_name)) {
$this->name = $new_name;
}
+ if ($this->is_photo()) {
+ list ($this->width, $this->height, $this->mime_type, $extension) =
+ photo::get_file_metadata($this->data_file);
+ } else if ($this->is_movie()) {
+ list ($this->width, $this->height, $this->mime_type, $extension) =
+ movie::get_file_metadata($this->data_file);
+ }
}
if (array_intersect($this->changed, array("parent_id", "name", "slug"))) {
View
23 modules/gallery/tests/Item_Model_Test.php
@@ -394,15 +394,34 @@ public function replace_data_file_test() {
$this->assert_equal(20337, filesize($photo->file_path()));
}
- public function replacement_data_file_must_be_same_mime_type_test() {
+ public function replace_data_file_type_test() {
// Random photo is modules/gallery/tests/test.jpg
$photo = test::random_photo();
+ $this->assert_equal(1024, $photo->width);
+ $this->assert_equal(768, $photo->height);
+ $this->assert_equal(6232, filesize($photo->file_path()));
+ $this->assert_equal("image/jpeg", $photo->mime_type);
+ $orig_name = $photo->name;
+
+ // Random photo is gallery/images/graphicsmagick.png is 104x76 and 1486 bytes
$photo->set_data_file(MODPATH . "gallery/images/graphicsmagick.png");
+ $photo->save();
+
+ $this->assert_equal(104, $photo->width);
+ $this->assert_equal(76, $photo->height);
+ $this->assert_equal(1486, filesize($photo->file_path()));
+ $this->assert_equal("image/png", $photo->mime_type);
+ $this->assert_equal("png", pathinfo($photo->name, PATHINFO_EXTENSION));
+ $this->assert_equal(pathinfo($orig_name, PATHINFO_FILENAME), pathinfo($photo->name, PATHINFO_FILENAME));
+ }
+ public function unsafe_data_file_replacement_test() {
try {
+ $photo = test::random_photo();
+ $photo->set_data_file(MODPATH . "gallery/tests/Item_Model_Test.php");
$photo->save();
} catch (ORM_Validation_Exception $e) {
- $this->assert_same(array("name" => "cant_change_mime_type"), $e->validation->errors());
+ $this->assert_same(array("mime_type" => "invalid"), $e->validation->errors());
return; // pass
}
$this->assert_true(false, "Shouldn't get here");

0 comments on commit 0672c8f

Please sign in to comment.
Something went wrong with that request. Please try again.