Skip to content

Commit 903f90d

Browse files
authored
Fix GET Process endpoint for unstaged docker apps (#4415)
- The user field was added in #4407 - This failed for unstaged Docker apps since they do not have JSON-parseable execution metadata - This fix updates the code to treat empty and unparseable execution metadata the same as an empty JSON object
1 parent 384b017 commit 903f90d

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

app/models/runtime/process_model.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,16 @@ def permitted_users
579579
def docker_run_action_user
580580
return DEFAULT_USER unless docker?
581581

582-
docker_exec_metadata = Oj.load(execution_metadata)
583-
container_user = docker_exec_metadata['user']
582+
container_user = ''
583+
if execution_metadata.present?
584+
begin
585+
docker_exec_metadata = Oj.load(execution_metadata)
586+
container_user = docker_exec_metadata['user']
587+
rescue EncodingError
588+
container_user = ''
589+
end
590+
end
591+
584592
container_user.presence || 'root'
585593
end
586594

spec/unit/models/runtime/process_model_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,30 @@ def act_as_cf_admin
708708
expect(process.run_action_user).to eq('root')
709709
end
710710
end
711+
712+
context 'when the droplet execution metadata is an empty string' do
713+
let(:droplet_execution_metadata) { '' }
714+
715+
it 'defaults the user to root' do
716+
expect(process.run_action_user).to eq('root')
717+
end
718+
end
719+
720+
context 'when the droplet execution metadata is nil' do
721+
let(:droplet_execution_metadata) { nil }
722+
723+
it 'defaults the user to root' do
724+
expect(process.run_action_user).to eq('root')
725+
end
726+
end
727+
728+
context 'when the droplet execution metadata has invalid json' do
729+
let(:droplet_execution_metadata) { '{' }
730+
731+
it 'defaults the user to root' do
732+
expect(process.run_action_user).to eq('root')
733+
end
734+
end
711735
end
712736

713737
context 'when the process DOES NOT belong to a Docker lifecycle app' do

0 commit comments

Comments
 (0)