diff --git a/src/bosh-director/lib/bosh/director/api/controllers/deployments_controller.rb b/src/bosh-director/lib/bosh/director/api/controllers/deployments_controller.rb index 9718542b7b0..d4245402410 100644 --- a/src/bosh-director/lib/bosh/director/api/controllers/deployments_controller.rb +++ b/src/bosh-director/lib/bosh/director/api/controllers/deployments_controller.rb @@ -161,11 +161,13 @@ def initialize(config) payload = json_decode(request.body.read) @resurrector_manager.set_pause_for_instance(deployment, params[:job], params[:index_or_id], payload['resurrection_paused']) + status(200) end put '/:deployment/instance_groups/:instancegroup/:id/ignore', consumes: :json do payload = json_decode(request.body.read) @instance_ignore_manager.set_ignore_state_for_instance(deployment, params[:instancegroup], params[:id], payload['ignore']) + status(200) end post '/:deployment/jobs/:job/:index_or_id/snapshots' do diff --git a/src/bosh-director/lib/bosh/director/api/controllers/events_controller.rb b/src/bosh-director/lib/bosh/director/api/controllers/events_controller.rb index 9f41ba398a5..782763ab6a4 100644 --- a/src/bosh-director/lib/bosh/director/api/controllers/events_controller.rb +++ b/src/bosh-director/lib/bosh/director/api/controllers/events_controller.rb @@ -112,6 +112,8 @@ class EventsController < BaseController error: error, context: context }) + + status(200) end private diff --git a/src/bosh-director/lib/bosh/director/api/controllers/packages_controller.rb b/src/bosh-director/lib/bosh/director/api/controllers/packages_controller.rb index 857a8380c23..13a94c82438 100644 --- a/src/bosh-director/lib/bosh/director/api/controllers/packages_controller.rb +++ b/src/bosh-director/lib/bosh/director/api/controllers/packages_controller.rb @@ -4,7 +4,7 @@ module Bosh::Director module Api::Controllers class PackagesController < BaseController post '/matches', :consumes => :yaml do - manifest = YAML.load(request.body) + manifest = YAML.load(request.body.read) unless manifest.is_a?(Hash) && manifest['packages'].is_a?(Array) raise BadManifest, "Manifest doesn't have a usable packages section" @@ -22,7 +22,7 @@ class PackagesController < BaseController end post '/matches_compiled', :consumes => :yaml do - manifest = YAML.load(request.body) + manifest = YAML.load(request.body.read) unless manifest.is_a?(Hash) && manifest['compiled_packages'].is_a?(Array) raise BadManifest, "Manifest doesn't have a usable packages section" diff --git a/src/bosh-director/spec/spec_helper.rb b/src/bosh-director/spec/spec_helper.rb index 6c239dc2f56..618236edb43 100644 --- a/src/bosh-director/spec/spec_helper.rb +++ b/src/bosh-director/spec/spec_helper.rb @@ -250,6 +250,13 @@ def check_event_log(task_id) end end +def linted_rack_app(app) + Rack::Builder.new do + use Rack::Lint + run app + end +end + module ManifestHelper class << self def default_deployment_manifest(overrides = {}) diff --git a/src/bosh-director/spec/unit/api/controllers/backups_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/backups_controller_spec.rb index 42bc11699ba..422c7139b93 100644 --- a/src/bosh-director/spec/unit/api/controllers/backups_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/backups_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::BackupsController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } let(:temp_dir) { Dir.mktmpdir} diff --git a/src/bosh-director/spec/unit/api/controllers/cleanup_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/cleanup_controller_spec.rb index c5a52c567ed..1b3d7384815 100644 --- a/src/bosh-director/spec/unit/api/controllers/cleanup_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/cleanup_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::CleanupController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } before do diff --git a/src/bosh-director/spec/unit/api/controllers/cloud_configs_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/cloud_configs_controller_spec.rb index f30434f010a..dcfef28a2d4 100644 --- a/src/bosh-director/spec/unit/api/controllers/cloud_configs_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/cloud_configs_controller_spec.rb @@ -6,7 +6,7 @@ module Bosh::Director describe Api::Controllers::CloudConfigsController do include Rack::Test::Methods - subject(:app) { Api::Controllers::CloudConfigsController.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) identity_provider = Support::TestIdentityProvider.new(config.get_uuid_provider) diff --git a/src/bosh-director/spec/unit/api/controllers/cpi_configs_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/cpi_configs_controller_spec.rb index 47fc64819a5..3d8378f0324 100644 --- a/src/bosh-director/spec/unit/api/controllers/cpi_configs_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/cpi_configs_controller_spec.rb @@ -6,7 +6,7 @@ module Bosh::Director describe Api::Controllers::CpiConfigsController do include Rack::Test::Methods - subject(:app) { Api::Controllers::CpiConfigsController.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) identity_provider = Support::TestIdentityProvider.new(config.get_uuid_provider) diff --git a/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb index 72ed54b1cd4..5f42ebbb67d 100644 --- a/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/deployments_controller_spec.rb @@ -7,7 +7,7 @@ module Api include IpUtil include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) @@ -307,7 +307,7 @@ def manifest_with_errand(deployment_name='errand') variable_set: Models::VariableSet.create(deployment: deployment) ) Models::PersistentDisk.create(instance: instance, disk_cid: 'disk_cid') - put "#{path}", manifest, {'CONTENT_TYPE' => 'text/yaml', 'CONTENT_LENGTH' => 0} + put "#{path}", manifest, {'CONTENT_TYPE' => 'text/yaml', 'CONTENT_LENGTH' => '0'} match = last_response.location.match(%r{/tasks/no_content_length}) expect(match).to_not be_nil end @@ -380,7 +380,7 @@ def manifest_with_errand(deployment_name='errand') create(:deployment => deployment, :job => 'dea', :index => '0', :state => 'started', :variable_set => Models::VariableSet.create(deployment: deployment)) - put '/foo/jobs/dea/0?state=started', "}}}i'm not really yaml, hah!", {'CONTENT_TYPE' => 'text/yaml', 'CONTENT_LENGTH' => 0} + put '/foo/jobs/dea/0?state=started', "}}}i'm not really yaml, hah!", {'CONTENT_TYPE' => 'text/yaml', 'CONTENT_LENGTH' => '0'} expect(last_response.status).to eq(302) end diff --git a/src/bosh-director/spec/unit/api/controllers/disks_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/disks_controller_spec.rb index 401a35cb07b..ac740650206 100644 --- a/src/bosh-director/spec/unit/api/controllers/disks_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/disks_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::DisksController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } let(:orphaned_at) { Time.now.utc } diff --git a/src/bosh-director/spec/unit/api/controllers/events_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/events_controller_spec.rb index 11c70a71a19..d3bf3cc9a1d 100644 --- a/src/bosh-director/spec/unit/api/controllers/events_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/events_controller_spec.rb @@ -8,7 +8,8 @@ module Api describe Controllers::EventsController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } + let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } let(:timestamp) { Time.now } @@ -502,6 +503,8 @@ def perform it 'stores event' do expect { perform }.not_to raise_exception + expect(last_response.status).to eq(200) + expect(last_response.body).to eq('') event = Models::Event.first expect(event.id).to eq(1) expect(event.parent_id).to eq(nil) diff --git a/src/bosh-director/spec/unit/api/controllers/info_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/info_controller_spec.rb index d4c9ca86456..b5b29654c06 100644 --- a/src/bosh-director/spec/unit/api/controllers/info_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/info_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::InfoController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(test_config) } let(:base_config) { SpecHelper.spec_get_director_config } let(:test_config) { base_config } diff --git a/src/bosh-director/spec/unit/api/controllers/jobs_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/jobs_controller_spec.rb index c54a695bf33..a77d1a23ded 100644 --- a/src/bosh-director/spec/unit/api/controllers/jobs_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/jobs_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::JobsController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) identity_provider = Support::TestIdentityProvider.new(config.get_uuid_provider) diff --git a/src/bosh-director/spec/unit/api/controllers/locks_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/locks_controller_spec.rb index 42a7a80a175..613ebc32dbf 100644 --- a/src/bosh-director/spec/unit/api/controllers/locks_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/locks_controller_spec.rb @@ -6,7 +6,7 @@ module Bosh::Director describe Api::Controllers::LocksController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) identity_provider = Support::TestIdentityProvider.new(config.get_uuid_provider) diff --git a/src/bosh-director/spec/unit/api/controllers/orphan_disks_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/orphan_disks_controller_spec.rb index d535551e5e9..dae970ab5b7 100644 --- a/src/bosh-director/spec/unit/api/controllers/orphan_disks_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/orphan_disks_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::OrphanDisksController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } let(:orphaned_at) { Time.now.utc } diff --git a/src/bosh-director/spec/unit/api/controllers/packages_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/packages_controller_spec.rb index e4c36db1bfa..04c94bbfb2e 100644 --- a/src/bosh-director/spec/unit/api/controllers/packages_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/packages_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::PackagesController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } before { allow(Api::ResourceManager).to receive(:new) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } diff --git a/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb index fc5a304c0c8..84d6882817b 100644 --- a/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/releases_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::ReleasesController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) identity_provider = Support::TestIdentityProvider.new(config.get_uuid_provider) diff --git a/src/bosh-director/spec/unit/api/controllers/resources_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/resources_controller_spec.rb index 0f68f966861..25dc437a5a8 100644 --- a/src/bosh-director/spec/unit/api/controllers/resources_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/resources_controller_spec.rb @@ -12,7 +12,7 @@ module Api let(:blobstore) { double('client') } let(:resource_manager) { ResourceManager.new(blobstore) } - subject(:app) { described_class.new(config, resource_manager) } + subject(:app) { linted_rack_app(described_class.new(config, resource_manager)) } let(:config) do config = SpecHelper.spec_get_director_config diff --git a/src/bosh-director/spec/unit/api/controllers/restore_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/restore_controller_spec.rb index a003e18cdfc..4eca71e02e2 100644 --- a/src/bosh-director/spec/unit/api/controllers/restore_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/restore_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::RestoreController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(test_config) } let(:test_config) do config = YAML.load(spec_asset('test-director-config.yml')) @@ -20,7 +20,11 @@ module Api config end - before { App.new(config) } + before do + allow(File).to receive(:read).and_call_original + allow(File).to receive(:read).with('/path/to/server_ca_path').and_return('whatever makes you happy') + App.new(config) + end it 'requires auth' do post '/', 'fake-data', { 'CONTENT_TYPE' => 'multipart/form-data' } diff --git a/src/bosh-director/spec/unit/api/controllers/resurrection_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/resurrection_controller_spec.rb index 706b200d17c..44b10395b18 100644 --- a/src/bosh-director/spec/unit/api/controllers/resurrection_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/resurrection_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::ResurrectionController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } before { basic_authorize 'admin', 'admin' } diff --git a/src/bosh-director/spec/unit/api/controllers/runtime_configs_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/runtime_configs_controller_spec.rb index e699bf78068..d5ac90eae8e 100644 --- a/src/bosh-director/spec/unit/api/controllers/runtime_configs_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/runtime_configs_controller_spec.rb @@ -6,7 +6,7 @@ module Bosh::Director describe Api::Controllers::RuntimeConfigsController do include Rack::Test::Methods - subject(:app) { Api::Controllers::RuntimeConfigsController.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) identity_provider = Support::TestIdentityProvider.new(config.get_uuid_provider) diff --git a/src/bosh-director/spec/unit/api/controllers/stemcells_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/stemcells_controller_spec.rb index 1cb1bbba60a..7d91be19bab 100644 --- a/src/bosh-director/spec/unit/api/controllers/stemcells_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/stemcells_controller_spec.rb @@ -5,7 +5,7 @@ module Bosh::Director describe Api::Controllers::StemcellsController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) do config = Config.load_hash(SpecHelper.spec_get_director_config) identity_provider = Support::TestIdentityProvider.new(config.get_uuid_provider) diff --git a/src/bosh-director/spec/unit/api/controllers/task_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/task_controller_spec.rb index 71e9d446c55..d0b59d28680 100644 --- a/src/bosh-director/spec/unit/api/controllers/task_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/task_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::TaskController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } it 'requires auth' do diff --git a/src/bosh-director/spec/unit/api/controllers/tasks_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/tasks_controller_spec.rb index 978b0c6c61f..c8e6a335c48 100644 --- a/src/bosh-director/spec/unit/api/controllers/tasks_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/tasks_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::TasksController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:temp_dir) { Dir.mktmpdir } diff --git a/src/bosh-director/spec/unit/api/controllers/vms_controller_spec.rb b/src/bosh-director/spec/unit/api/controllers/vms_controller_spec.rb index b44755c2807..990053c06b3 100644 --- a/src/bosh-director/spec/unit/api/controllers/vms_controller_spec.rb +++ b/src/bosh-director/spec/unit/api/controllers/vms_controller_spec.rb @@ -6,7 +6,7 @@ module Api describe Controllers::VmsController do include Rack::Test::Methods - subject(:app) { described_class.new(config) } + subject(:app) { linted_rack_app(described_class.new(config)) } let(:config) { Config.load_hash(SpecHelper.spec_get_director_config) } before do