From: Michael Orlitzky Date: Sun, 5 Mar 2017 03:14:36 +0000 (-0500) Subject: Add a test to ensure that "nonexistent" AgenDAV users' shares are removed. X-Git-Tag: 0.0.3~1 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=commitdiff_plain;h=93f4125437702363b25b6825d6f20e98b1e319a9 Add a test to ensure that "nonexistent" AgenDAV users' shares are removed. --- diff --git a/lib/common/agendav_plugin.rb b/lib/common/agendav_plugin.rb index c5e7d77..d8ef6d6 100644 --- a/lib/common/agendav_plugin.rb +++ b/lib/common/agendav_plugin.rb @@ -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 diff --git a/test/sql/agendav-fixtures.sql b/test/sql/agendav-fixtures.sql index fe39f6e..535f023 100644 --- a/test/sql/agendav-fixtures.sql +++ b/test/sql/agendav-fixtures.sql @@ -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); diff --git a/test/test_rm.rb b/test/test_rm.rb index 24dacc3..02de53d 100644 --- a/test/test_rm.rb +++ b/test/test_rm.rb @@ -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')]