Skip to content

Commit 5975542

Browse files
committed
Ensure config[:addons] is reasonable when deploy is present
We should drop non-Hash addons config when a top-level deploy key is present. When the top-level deploy key is present, while normalizing, an addons value that is not a Hash will be sent `#[]`, which is raises `NoMethodError`.
1 parent c2748cd commit 5975542

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/travis/model/job.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ def normalize_config(config)
178178

179179
if config[:deploy]
180180
config[:addons] ||= {}
181-
config[:addons][:deploy] = config.delete(:deploy)
181+
if config[:addons].is_a? Hash
182+
config[:addons][:deploy] = config.delete(:deploy)
183+
else
184+
config.delete(:addons)
185+
config[:addons] = { deploy: config.delete(:deploy) }
186+
end
182187
end
183188

184189
config

spec/travis/model/job_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
rvm: '1.8.7',
157157
}
158158
end
159+
159160
context 'when job has secure env disabled' do
160161
let :job do
161162
job = Job.new(repository: Factory(:repository))
@@ -434,6 +435,22 @@
434435
}
435436
}
436437
end
438+
439+
it 'removes addons config if it is an array and deploy is present' do
440+
config = { rvm: '1.8.7',
441+
addons: ["foo"],
442+
deploy: { foo: 'bar'}
443+
}
444+
job.config = config
445+
446+
job.decrypted_config.should == {
447+
rvm: '1.8.7',
448+
addons: {
449+
deploy: { foo: 'bar' }
450+
}
451+
}
452+
end
453+
437454
end
438455
end
439456

0 commit comments

Comments
 (0)