Add a test to ensure that "nonexistent" AgenDAV users' shares are removed.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 5 Mar 2017 03:14:36 +0000 (22:14 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 5 Mar 2017 03:14:36 +0000 (22:14 -0500)
lib/common/agendav_plugin.rb
test/sql/agendav-fixtures.sql
test/test_rm.rb

index c5e7d7719178dd5035f46b39a2c8cf79c78399ae..d8ef6d60c8445fab529bf4560cae4c578904ff3c 100644 (file)
@@ -53,4 +53,27 @@ module AgendavPlugin
     return users.map{ |u| User.new(u) }
   end
 
+
+  # Count the number of rows in the "shares" table. Used only for
+  # testing.
+  #
+  # @return [Fixnum] the number of rows in the "shares" table.
+  #
+  def count_shares()
+    count = nil
+    connection = PG::Connection.new(@db_hash)
+
+    sql_query  = 'SELECT count(*) FROM shares;'
+    begin
+      connection.query(sql_query) do |result|
+        count = result.getvalue(0,0).to_i()
+      end
+    ensure
+      # Make sure the connection gets closed even if the query explodes.
+      connection.close()
+    end
+
+    return count
+  end
+
 end
index fe39f6ef014103ecea34a85381cba9f833fdfcd3..535f02333c23d70aad20198519a23393a5440bd7 100644 (file)
@@ -15,3 +15,20 @@ INSERT INTO shares (owner, calendar, "with", options, rw)
           '/carol%40example.net/',
          'a:0:{}',
          true);
+
+/* These two are missing a prefs entry to test the removal of "shares"
+ * entries in that situation.
+*/
+INSERT INTO shares (owner, calendar, "with", options, rw)
+  VALUES ('/caldav.php/stinky%40example.com/',
+         '/caldav.php/stinky%40example.com/calendar-default',
+          '/herp%40example.net/',
+         'a:0:{}',
+         true);
+
+INSERT INTO shares (owner, calendar, "with", options, rw)
+  VALUES ('/caldav.php/goober%40example.com/',
+         '/caldav.php/goober%40example.com/calendar-default',
+          '/derp%40example.net/',
+         'a:0:{}',
+         true);
index 24dacc3391f309ebdce6dfa63b710d109702dd5e..02de53d08f5a3b95f18875196f05ef73d7049d10 100644 (file)
@@ -42,6 +42,13 @@ class TestRm < MailshearsTest
     expected = [User.new('booger@example.com')]
     assert_equal(expected, actual)
 
+    # Only try to remove this guy from the agendav database, to ensure
+    # that "nonexistent" users have their shares removed.
+    arm.remove_user('stinky@example.com')
+    expected = 2
+    actual = arm.count_shares()
+    assert_equal(expected, actual)
+
     drm = DavicalRm.new(cfg)
     actual = drm.list_users()
     expected = [User.new('alice@example.com'), User.new('booger@example.com')]