Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/models/runtime/process_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,16 @@ def permitted_users
def docker_run_action_user
return DEFAULT_USER unless docker?

docker_exec_metadata = Oj.load(execution_metadata)
container_user = docker_exec_metadata['user']
container_user = ''
if execution_metadata.present?
begin
docker_exec_metadata = Oj.load(execution_metadata)
container_user = docker_exec_metadata['user']
rescue EncodingError
container_user = ''
end
end

container_user.presence || 'root'
end

Expand Down
24 changes: 24 additions & 0 deletions spec/unit/models/runtime/process_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,30 @@ def act_as_cf_admin
expect(process.run_action_user).to eq('root')
end
end

context 'when the droplet execution metadata is an empty string' do
let(:droplet_execution_metadata) { '' }

it 'defaults the user to root' do
expect(process.run_action_user).to eq('root')
end
end

context 'when the droplet execution metadata is nil' do
let(:droplet_execution_metadata) { nil }

it 'defaults the user to root' do
expect(process.run_action_user).to eq('root')
end
end

context 'when the droplet execution metadata has invalid json' do
let(:droplet_execution_metadata) { '{' }

it 'defaults the user to root' do
expect(process.run_action_user).to eq('root')
end
end
end

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