Skip to content

Commit 3e45111

Browse files
pbuskomodulo11
andcommitted
Validate CNB lifecycle data
Co-authored-by: Johannes Dillmann <[email protected]>
1 parent aaffe50 commit 3e45111

File tree

7 files changed

+44
-3
lines changed

7 files changed

+44
-3
lines changed

app/messages/app_manifest_message.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def self.underscore_keys(hash)
7171
validate :validate_buildpack_and_buildpacks_combination!
7272
validate :validate_docker_enabled!
7373
validate :validate_cnb_enabled!
74+
validate :validate_cnb_buildpacks!, if: ->(record) { record.requested?(:cnb) }
7475
validate :validate_docker_buildpacks_combination!
7576
validate :validate_service_bindings_message!, if: ->(record) { record.requested?(:services) }
7677
validate :validate_env_update_message!, if: ->(record) { record.requested?(:env) }
@@ -481,6 +482,12 @@ def validate_cnb_enabled!
481482
errors.add(:base, e.message)
482483
end
483484

485+
def validate_cnb_buildpacks!
486+
return if requested?(:cnb) && (requested?(:buildpack) || requested?(:buildpacks))
487+
488+
errors.add(:base, 'Buildpack(s) must be specified when using Cloud Native Buildpacks')
489+
end
490+
484491
def validate_docker_buildpacks_combination!
485492
return unless requested?(:docker) && (requested?(:buildpack) || requested?(:buildpacks))
486493

app/messages/validators.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def validate(record)
184184
data_message_class_table = {
185185
lifecycles::BUILDPACK => VCAP::CloudController::BuildpackLifecycleDataMessage,
186186
lifecycles::DOCKER => VCAP::CloudController::EmptyLifecycleDataMessage,
187-
# FIXME: Do we want CNBLifecycleDataMessage ???
188187
lifecycles::CNB => VCAP::CloudController::BuildpackLifecycleDataMessage
189188
}
190189

lib/cloud_controller/diego/lifecycles/app_cnb_lifecycle.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def update_lifecycle_data_stack(app)
3232
end
3333

3434
def valid?
35-
true
35+
!buildpacks.empty?
3636
end
3737

3838
def errors

lib/tasks/spec.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace :spec do
2525
run_specs('spec/unit/messages/validators_spec.rb')
2626
run_specs('spec/unit/lib/cloud_controller/errands/rotate_database_key_spec.rb')
2727
run_specs('spec/unit/messages/app_create_message_spec.rb')
28+
run_specs('spec/unit/messages/app_manifest_message_spec.rb')
2829
run_specs('spec/unit/models/runtime/buildpack_lifecycle_buildpack_model_spec.rb')
2930
end
3031

spec/unit/lib/cloud_controller/diego/cnb/staging_action_builder_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module CNB
106106
::Diego::Bbs::Models::RunAction.new(
107107
path: '/tmp/lifecycle/builder',
108108
user: 'vcap',
109-
args: ["--buildpacks", "gcr.io/paketo-buildpacks/node-start", "--buildpacks", "gcr.io/paketo-buildpacks/node-engine"]
109+
args: ['--buildpack', 'gcr.io/paketo-buildpacks/node-start', '--buildpack', 'gcr.io/paketo-buildpacks/node-engine']
110110
)
111111
end
112112

spec/unit/lib/cloud_controller/diego/lifecycles/app_cnb_lifecycle_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,23 @@ module VCAP::CloudController
9494
expect(data_model.stack).to eq('sweetness')
9595
end
9696
end
97+
98+
describe '#validation' do
99+
context 'with no buildpacks' do
100+
let(:lifecycle_request_data) { {} }
101+
102+
it 'invalid' do
103+
expect(lifecycle.valid?).to be(false)
104+
end
105+
end
106+
107+
context 'with buildpacks' do
108+
let(:lifecycle_request_data) { { buildpacks: %w[foo bar] } }
109+
110+
it 'valid' do
111+
expect(lifecycle.valid?).to be(true)
112+
end
113+
end
114+
end
97115
end
98116
end

spec/unit/messages/app_manifest_message_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,22 @@ module VCAP::CloudController
11141114
expect(message.errors.full_messages).to match_array(error_messages)
11151115
end
11161116
end
1117+
1118+
context 'when cnb: true and no buildpacks provided' do
1119+
before do
1120+
FeatureFlag.make(name: 'diego_cnb', enabled: true, error_message: nil)
1121+
end
1122+
1123+
let(:params_from_yaml) { { name: 'eugene', cnb: true } }
1124+
1125+
it 'is not valid' do
1126+
message = AppManifestMessage.create_from_yml(params_from_yaml)
1127+
1128+
expect(message).not_to be_valid
1129+
expect(message.errors).to have(1).items
1130+
expect(message.errors.full_messages).to include('Buildpack(s) must be specified when using Cloud Native Buildpacks')
1131+
end
1132+
end
11171133
end
11181134

11191135
describe '.create_from_yml' do

0 commit comments

Comments
 (0)