Skip to content

Commit 9bab49f

Browse files
committed
Validate Apple config key account
1 parent 9c390aa commit 9bab49f

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

app/models/apple/config.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Config < ApplicationRecord
1010
validate :podcast_has_one_apple_config
1111
validate :not_default_feed
1212
validate :show_feed_binding_matches_podcast
13+
validate :key_belongs_to_podcast_account
1314

1415
# backwards-compatible "key" getters
1516
delegate :provider_id, to: :key
@@ -90,6 +91,13 @@ def show_feed_binding_matches_podcast
9091
errors.add(:show_feed_binding, "must belong to the same podcast as feed")
9192
end
9293

94+
def key_belongs_to_podcast_account
95+
return unless key && podcast
96+
return if key.account_id == podcast.account_id
97+
98+
errors.add(:key, "must belong to the podcast's PRX account")
99+
end
100+
93101
def assign_key_account
94102
key.account_id = podcast&.account_id if key&.new_record?
95103
end

test/models/apple/config_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@
5858
refute c1.valid?
5959
assert_equal ["cannot use default feed"], c1.errors[:feed]
6060
end
61+
62+
it "requires a persisted key to belong to the podcast account" do
63+
podcast = create(:podcast, prx_account_uri: "/api/v1/accounts/456")
64+
key = create(:apple_key, account_id: 123)
65+
config = build(:apple_config, feed: create(:private_feed, podcast: podcast), key: key)
66+
67+
refute config.valid?
68+
assert_equal ["must belong to the podcast's PRX account"], config.errors[:key]
69+
end
6170
end
6271

6372
it "assigns a new key to the podcast account" do

0 commit comments

Comments
 (0)