diff --git a/ee/app/models/geo_node.rb b/ee/app/models/geo_node.rb index 7234f15f2904164474e5ea14ea3af3d7adf0a391..5186584081936fa98a7eff9c4b7d7156f84c166f 100644 --- a/ee/app/models/geo_node.rb +++ b/ee/app/models/geo_node.rb @@ -9,7 +9,7 @@ class GeoNode < ActiveRecord::Base # Array of repository storages to synchronize for selective sync by shards serialize :selective_sync_shards, Array # rubocop:disable Cop/ActiveRecordSerialize - belongs_to :oauth_application, class_name: 'Doorkeeper::Application', dependent: :destroy # rubocop: disable Cop/ActiveRecordDependent + belongs_to :oauth_application, class_name: 'Doorkeeper::Application', dependent: :destroy, autosave: true # rubocop: disable Cop/ActiveRecordDependent has_many :geo_node_namespace_links has_many :namespaces, through: :geo_node_namespace_links diff --git a/ee/changelogs/unreleased/mk-geo-node-autosave-oauth-application.yml b/ee/changelogs/unreleased/mk-geo-node-autosave-oauth-application.yml new file mode 100644 index 0000000000000000000000000000000000000000..c356db9b3005b25ac351749591677d808dde0631 --- /dev/null +++ b/ee/changelogs/unreleased/mk-geo-node-autosave-oauth-application.yml @@ -0,0 +1,5 @@ +--- +title: 'Geo: Persist OAuth callback changes for Alternate URL' +merge_request: 10358 +author: +type: fixed diff --git a/ee/spec/models/geo_node_spec.rb b/ee/spec/models/geo_node_spec.rb index 17e8faeaefe98f26d4afcedbb9b1c0d4dd747829..c482f057d38d458b632feda7743efd810a0b0c1f 100644 --- a/ee/spec/models/geo_node_spec.rb +++ b/ee/spec/models/geo_node_spec.rb @@ -16,7 +16,7 @@ let(:api_version) { API::API.version } context 'associations' do - it { is_expected.to belong_to(:oauth_application).dependent(:destroy) } + it { is_expected.to belong_to(:oauth_application).class_name('Doorkeeper::Application').dependent(:destroy).autosave(true) } it { is_expected.to have_many(:geo_node_namespace_links) } it { is_expected.to have_many(:namespaces).through(:geo_node_namespace_links) } @@ -196,6 +196,51 @@ end end end + + context 'when saving' do + let(:oauth_application) { node.oauth_application } + + context 'when url is changed' do + it "updates the associated OAuth application's redirect_uri" do + node.update!(url: 'http://modified-url') + + expect(oauth_application.reload.redirect_uri).to eq('http://modified-url/oauth/geo/callback') + end + end + + context 'when alternate_url is added' do + it "adds a callback URL to the associated OAuth application's redirect_uri" do + expected_redirect_uri = "#{oauth_application.redirect_uri}\nhttp://alternate-url/oauth/geo/callback" + + node.update!(alternate_url: 'http://alternate-url') + + expect(oauth_application.reload.redirect_uri).to eq(expected_redirect_uri) + end + end + + context 'when alternate_url is modified' do + it "updates the alternate callback URL in the associated OAuth application's redirect_uri" do + node.update!(alternate_url: 'http://alternate-url') + oauth_application.update!(redirect_uri: "#{node.oauth_callback_url}\nhttp://alternate-url/oauth/geo/callback") + expected_redirect_uri = "#{node.oauth_callback_url}\nhttp://modified-alternate-url/oauth/geo/callback" + + node.update!(alternate_url: 'http://modified-alternate-url') + + expect(oauth_application.reload.redirect_uri).to eq(expected_redirect_uri) + end + end + + context 'when alternate_url is cleared' do + it "removes the alternate callback URL in the associated OAuth application's redirect_uri" do + expected_redirect_uri = oauth_application.redirect_uri + oauth_application.update!(redirect_uri: "#{node.oauth_callback_url}\nhttp://alternate-url/oauth/geo/callback") + + node.update!(alternate_url: nil) + + expect(oauth_application.reload.redirect_uri).to eq(expected_redirect_uri) + end + end + end end context 'cache expiration' do