closes #9970
[arvados.git] / services / api / test / unit / log_test.rb
index 6bca80c7780ebc7f847aa24827ea12614b03a54b..632271e98c263efad7a5869e1831da69ceaf3b97 100644 (file)
@@ -9,7 +9,7 @@ class LogTest < ActiveSupport::TestCase
     :destroy => [nil, :assert_not_nil, :assert_nil],
   }
 
-  def setup
+  setup do
     @start_time = Time.now
     @log_count = 1
   end
@@ -56,10 +56,11 @@ class LogTest < ActiveSupport::TestCase
 
   def assert_logged_with_clean_properties(obj, event_type, excluded_attr)
     assert_logged(obj, event_type) do |props|
-      ['old_attributes', 'new_attributes'].map { |k| props[k] }.compact
-        .each do |attributes|
+      ['old_attributes', 'new_attributes'].map do |logattr|
+        attributes = props[logattr]
+        next if attributes.nil?
         refute_includes(attributes, excluded_attr,
-                        "log properties includes #{excluded_attr}")
+                        "log #{logattr} includes #{excluded_attr}")
       end
       yield props if block_given?
     end
@@ -252,7 +253,8 @@ class LogTest < ActiveSupport::TestCase
                                       :crunchstat_for_running_job] # log & job owned by active
 
     c = Log.readable_by(users(:spectator)).order("id asc").each.to_a
-    assert_log_result c, known_logs, [:admin_changes_specimen, # owned by spectator
+    assert_log_result c, known_logs, [:noop,                   # object_uuid is spectator
+                                      :admin_changes_specimen, # object_uuid is a specimen owned by spectator
                                       :system_adds_baz] # readable via 'all users' group
   end
 
@@ -270,9 +272,12 @@ class LogTest < ActiveSupport::TestCase
     end
   end
 
-  test "manifest_text not included in collection logs" do
+  test "non-empty configuration.unlogged_attributes" do
+    Rails.configuration.unlogged_attributes = ["manifest_text"]
+    txt = ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo\n"
+
     act_as_system_user do
-      coll = Collection.create(manifest_text: ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo\n")
+      coll = Collection.create(manifest_text: txt)
       assert_logged_with_clean_properties(coll, :create, 'manifest_text')
       coll.name = "testing"
       coll.save!
@@ -281,4 +286,25 @@ class LogTest < ActiveSupport::TestCase
       assert_logged_with_clean_properties(coll, :destroy, 'manifest_text')
     end
   end
+
+  test "empty configuration.unlogged_attributes" do
+    Rails.configuration.unlogged_attributes = []
+    txt = ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:foo\n"
+
+    act_as_system_user do
+      coll = Collection.create(manifest_text: txt)
+      assert_logged(coll, :create) do |props|
+        assert_equal(txt, props['new_attributes']['manifest_text'])
+      end
+      coll.update_attributes!(name: "testing")
+      assert_logged(coll, :update) do |props|
+        assert_equal(txt, props['old_attributes']['manifest_text'])
+        assert_equal(txt, props['new_attributes']['manifest_text'])
+      end
+      coll.destroy
+      assert_logged(coll, :destroy) do |props|
+        assert_equal(txt, props['old_attributes']['manifest_text'])
+      end
+    end
+  end
 end