Skip to content

Commit d3de2a2

Browse files
authored
added correct user to stop_sync drop of subscription (#183)
* added user to subscription drop * added privilege tests * updating tests to leverage no_sup user
1 parent f6164aa commit d3de2a2

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

lib/pg_easy_replicate/orchestrate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def drop_subscription(group_name:, target_conn_string:)
167167
Query.run(
168168
query: "DROP SUBSCRIPTION IF EXISTS #{subscription_name(group_name)}",
169169
connection_url: target_conn_string,
170+
user: db_user(target_conn_string),
170171
transaction: false,
171172
)
172173
rescue => e

spec/pg_easy_replicate/orchestrate_spec.rb

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@
5151

5252
expect(pg_publications(connection_url: connection_url)).to eq([])
5353
end
54+
55+
it "raises an error when user does not have sufficient privileges" do
56+
# Use a limited user for this test case
57+
restricted_user = "no_sup"
58+
restricted_user_connection_url = connection_url(restricted_user)
59+
60+
described_class.create_publication(
61+
group_name: "cluster1",
62+
conn_string: connection_url,
63+
)
64+
65+
expect do
66+
described_class.drop_publication(
67+
group_name: "cluster1",
68+
conn_string: restricted_user_connection_url,
69+
)
70+
end.to raise_error(RuntimeError) { |e|
71+
expect(e.message).to include("Unable to drop publication")
72+
}
73+
expect(pg_publications(connection_url: connection_url)).not_to eq([])
74+
end
5475
end
5576

5677
describe ".add_tables_to_publication" do
@@ -190,18 +211,9 @@
190211
describe ".drop_subscription" do
191212
before do
192213
PgEasyReplicate.bootstrap({ group_name: "cluster1" })
193-
194-
described_class.create_publication(
195-
group_name: "cluster1",
196-
conn_string: connection_url,
197-
)
198214
end
199215

200216
after do
201-
described_class.drop_publication(
202-
group_name: "cluster1",
203-
conn_string: connection_url,
204-
)
205217
PgEasyReplicate.cleanup({ everything: true, group_name: "cluster1" })
206218
end
207219

@@ -218,6 +230,28 @@
218230

219231
expect(pg_subscriptions(connection_url: target_connection_url)).to eq([])
220232
end
233+
234+
it "raises an error when user does not have sufficient privileges" do
235+
# Use a limited user for this test case
236+
restricted_user = "no_sup"
237+
restricted_user_target_connection_url = target_connection_url(restricted_user)
238+
239+
described_class.create_subscription(
240+
group_name: "cluster1",
241+
source_conn_string: docker_compose_source_connection_url,
242+
target_conn_string: target_connection_url,
243+
)
244+
245+
expect do
246+
described_class.drop_subscription(
247+
group_name: "cluster1",
248+
target_conn_string: restricted_user_target_connection_url,
249+
)
250+
end.to raise_error(RuntimeError) { |e|
251+
expect(e.message).to include("Unable to drop subscription")
252+
}
253+
expect(pg_subscriptions(connection_url: target_connection_url)).not_to eq([])
254+
end
221255
end
222256

223257
describe ".start_sync" do

0 commit comments

Comments
 (0)