[ARVADOS] updated: 9cd3ddf205cb4b0874c2b80bc200adac2598961d

git at public.curoverse.com git at public.curoverse.com
Mon Nov 17 11:05:03 EST 2014


Summary of changes:
 sdk/python/arvados/collection.py          |  2 +-
 services/api/app/models/collection.rb     | 10 ++++++++
 services/api/test/unit/collection_test.rb | 40 ++++++++++++++++++++++++++++---
 3 files changed, 48 insertions(+), 4 deletions(-)

       via  9cd3ddf205cb4b0874c2b80bc200adac2598961d (commit)
       via  4b20653d3f65c01661c6eae9cea25c0ab3c79aef (commit)
      from  e8dd6d95b4ab40e6f95b0faa51752599e27f6baf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 9cd3ddf205cb4b0874c2b80bc200adac2598961d
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Nov 17 11:04:54 2014 -0500

    4363: Accept unicode class, not just unicode type.

diff --git a/sdk/python/arvados/collection.py b/sdk/python/arvados/collection.py
index 0fe7b3e..fee6059 100644
--- a/sdk/python/arvados/collection.py
+++ b/sdk/python/arvados/collection.py
@@ -186,7 +186,7 @@ class CollectionReader(CollectionBase):
                     self._manifest_locator,
                     error_via_api,
                     error_via_keep))
-        if type(self._manifest_text) == unicode:
+        if isinstance(self._manifest_text, unicode):
             unicode_manifest = self._manifest_text
         else:
             unicode_manifest = self._manifest_text.decode('utf-8')

commit 4b20653d3f65c01661c6eae9cea25c0ab3c79aef
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Nov 17 11:01:49 2014 -0500

    4363: Validate utf-8 encoding of manifest_text.

diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index 28fc70e..89513fa 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -5,6 +5,7 @@ class Collection < ArvadosModel
   include KindAndEtag
   include CommonApiTemplate
 
+  before_validation :check_encoding
   before_validation :check_signatures
   before_validation :strip_manifest_text
   before_validation :set_portable_data_hash
@@ -106,6 +107,15 @@ class Collection < ArvadosModel
     true
   end
 
+  def check_encoding
+    if manifest_text.encoding.name == 'UTF-8' and manifest_text.valid_encoding?
+      true
+    else
+      errors.add :manifest_text, "must use UTF-8 encoding"
+      false
+    end
+  end
+
   def redundancy_status
     if redundancy_confirmed_as.nil?
       'unconfirmed'
diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb
index 4f73670..8853319 100644
--- a/services/api/test/unit/collection_test.rb
+++ b/services/api/test/unit/collection_test.rb
@@ -1,7 +1,41 @@
 require 'test_helper'
 
 class CollectionTest < ActiveSupport::TestCase
-  # test "the truth" do
-  #   assert true
-  # end
+  def create_collection name, enc=nil
+    txt = ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:#{name}.txt\n"
+    txt.force_encoding(enc) if enc
+    return Collection.create(manifest_text: txt)
+  end
+
+  test 'accept ASCII manifest_text' do
+    act_as_system_user do
+      c = create_collection 'foo'
+      assert c.valid?
+    end
+  end
+
+  test 'accept UTF-8 manifest_text' do
+    act_as_system_user do
+      c = create_collection "f\xc3\x98\xc3\x98"
+      assert c.valid?
+    end
+  end
+
+  test 'refuse manifest_text with invalid UTF-8 byte sequence' do
+    act_as_system_user do
+      c = create_collection "f\xc8o", Encoding::UTF_8
+      assert !c.valid?
+      assert_equal [:manifest_text], c.errors.messages.keys
+      assert_match /UTF-8/, c.errors.messages[:manifest_text].first
+    end
+  end
+
+  test 'refuse manifest_text with non-UTF-8 encoding' do
+    act_as_system_user do
+      c = create_collection "f\xc8o", Encoding::ASCII_8BIT
+      assert !c.valid?
+      assert_equal [:manifest_text], c.errors.messages.keys
+      assert_match /UTF-8/, c.errors.messages[:manifest_text].first
+    end
+  end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list