OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix backup job not looking for user config property
Oliver Günther07caac7d916a
diff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rbindex c5040584a8c..be738609709 100644--- a/app/workers/backup_job.rb+++ b/app/workers/backup_job.rb@@ -249,23 +249,30 @@ class BackupJob < ::ApplicationJobenddef pg_env- config = ActiveRecord::Base.connection_db_config.configuration_hashentries = pg_env_to_connection_config.map do |key, config_key|- value = config[config_key].to_s+ possible_keys = Array(config_key)+ value = possible_keys+ .lazy+ .filter_map { |key| database_config[key] }+ .first- [key.to_s, value] if value.present?+ [key.to_s, value.to_s] if value.present?endentries.compact.to_hend+ def database_config+ @database_config ||= ActiveRecord::Base.connection_db_config.configuration_hash+ end+### Maps the PG env variable name to the key in the AR connection config.def pg_env_to_connection_config{PGHOST: :host,PGPORT: :port,- PGUSER: :username,+ PGUSER: %i[username user],PGPASSWORD: :password,PGDATABASE: :database}diff --git a/spec/workers/backup_job_spec.rb b/spec/workers/backup_job_spec.rbindex ab8f1a1bd94..e2c3b6c1edc 100644--- a/spec/workers/backup_job_spec.rb+++ b/spec/workers/backup_job_spec.rb@@ -69,7 +69,7 @@ describe BackupJob, type: :model doallow(job).to receive(:arguments).and_return argumentsallow(job).to receive(:job_id).and_return job_id- expect(Open3).to receive(:capture3).and_return [nil, "Dump failed", db_dump_process_status]+ allow(Open3).to receive(:capture3).and_return [nil, "Dump failed", db_dump_process_status]allow_any_instance_of(BackupJob).to receive(:tmp_file_name).with("openproject", ".sql").and_return("/tmp/openproject.sql")@@ -85,6 +85,31 @@ describe BackupJob, type: :model dojob.perform **arguments.firstend+ describe '#pg_env' do+ subject { job.pg_env }++ context 'when config has user reference, not username (regression #44251)' do+ let(:config_double) do+ {+ adapter: :postgresql,+ password: "blabla",+ database: "test",+ user: "foobar"+ }+ end++ before do+ allow(job).to receive(:database_config).and_return(config_double)+ end++ it 'still sets a PGUSER' do+ expect(subject['PGUSER']).to eq 'foobar'+ expect(subject['PGPASSWORD']).to eq 'blabla'+ expect(subject['PGDATABASE']).to eq 'test'+ end+ end+ end+context "with a failed database dump" dolet(:db_dump_success) { false }@@ -175,7 +200,7 @@ describe BackupJob, type: :model doallow_any_instance_of(LocalFileUploader).to receive(:cached?).and_return(true)allow_any_instance_of(LocalFileUploader).to receive(:local_file)- .and_return(File.new(dummy_path))+ .and_return(File.new(dummy_path))endafter do