Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
philippthun committed Jul 25, 2024
1 parent b7d4cee commit 1e235ca
Show file tree
Hide file tree
Showing 68 changed files with 530 additions and 638 deletions.
27 changes: 10 additions & 17 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-07-25 13:38:50 UTC using RuboCop version 1.65.0.
# on 2024-07-25 14:07:39 UTC using RuboCop version 1.65.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -79,11 +79,12 @@ Lint/UnusedMethodArgument:
- 'lib/services/service_brokers/v2/response_parser.rb'
- 'spec/support/fakes/fake_service_broker_v2_client.rb'

# Offense count: 1
# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect.
Lint/UselessAssignment:
Exclude:
- 'spec/request/spaces_spec.rb'
- 'spec/support/matchers/have_queried_db_times.rb'

# Offense count: 4
Expand Down Expand Up @@ -172,7 +173,7 @@ RSpec/BeforeAfterAll:
- 'spec/unit/lib/vcap/rest_api/event_query_spec.rb'
- 'spec/unit/lib/vcap/rest_api/query_spec.rb'

# Offense count: 6
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: NegatedMatcher.
RSpec/ChangeByZero:
Expand Down Expand Up @@ -340,6 +341,12 @@ RSpec/PredicateMatcher:
Exclude:
- 'spec/unit/lib/cloud_controller/errands/rotate_database_key_spec.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
RSpec/ReceiveMessages:
Exclude:
- 'spec/unit/lib/cloud_controller/errands/rotate_database_key_spec.rb'

# Offense count: 44
RSpec/RepeatedDescription:
Exclude:
Expand Down Expand Up @@ -399,20 +406,6 @@ RSpec/RepeatedExampleGroupDescription:
- 'spec/unit/models/runtime/security_group_spec.rb'
- 'spec/unit/presenters/v3/role_presenter_spec.rb'

# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: and_return, block
RSpec/ReturnFromStub:
Exclude:
- 'spec/unit/lib/cloud_controller/errands/rotate_database_key_spec.rb'

# Offense count: 202
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AutoCorrect.
RSpec/ScatteredLet:
Enabled: false

# Offense count: 32
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
# Include: **/*_spec.rb
Expand Down
18 changes: 8 additions & 10 deletions spec/logcache/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module Logcache

describe 'when logcache is unavailable' do
let(:instance_count) { 0 }
let(:client) do
Logcache::Client.new(host:, port:, client_ca_path:,
client_cert_path:, client_key_path:, tls_subject_name:)
end
let(:bad_status) { GRPC::BadStatus.new(14) }
let!(:process) { VCAP::CloudController::ProcessModel.make(instances: instance_count) }

Expand All @@ -75,11 +79,6 @@ module Logcache
allow(logcache_service).to receive(:read).and_raise(bad_status)
end

let(:client) do
Logcache::Client.new(host:, port:, client_ca_path:,
client_cert_path:, client_key_path:, tls_subject_name:)
end

it 'retries the request three times and raises an exception' do
expect do
client.container_metrics(source_guid: process.guid, envelope_limit: 1000, start_time: 100, end_time: 101)
Expand All @@ -91,6 +90,10 @@ module Logcache

describe 'when logcache does not respond in a reasonable amount of time' do
let(:instance_count) { 0 }
let(:client) do
Logcache::Client.new(host:, port:, client_ca_path:,
client_cert_path:, client_key_path:, tls_subject_name:)
end
let(:timeout_status) { GRPC::DeadlineExceeded.new }
let!(:process) { VCAP::CloudController::ProcessModel.make(instances: instance_count) }

Expand All @@ -106,11 +109,6 @@ module Logcache
allow(logcache_service).to receive(:read).and_raise(timeout_status)
end

let(:client) do
Logcache::Client.new(host:, port:, client_ca_path:,
client_cert_path:, client_key_path:, tls_subject_name:)
end

it 'raises an exception' do
expect do
client.container_metrics(source_guid: process.guid, envelope_limit: 1000, start_time: 100, end_time: 101)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe 'backfill status_value for deployments', isolation: :truncation, type: :migration do
let(:tmp_migrations_dir) { Dir.mktmpdir }
let(:app) { VCAP::CloudController::AppModel.make }

before do
FileUtils.cp(
Expand All @@ -10,8 +11,6 @@
)
end

let(:app) { VCAP::CloudController::AppModel.make }

context 'when a deployment has state DEPLOYED' do
let!(:deployment_with_state_deployed) do
VCAP::CloudController::DeploymentModel.create(
Expand Down
27 changes: 13 additions & 14 deletions spec/request/app_manifests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,6 @@
docker_username: 'xXxMyL1ttlePwnyxXx'
)
end

let(:droplet) do
VCAP::CloudController::DropletModel.make app: app_model, package: docker_package
end

let(:app_model) do
VCAP::CloudController::AppModel.make(:docker, space: space, environment_variables: { 'one' => 'tomato', 'two' => 'potato' })
end

before do
app_model.update(droplet:)
process.update(log_rate_limit: -1)
end

let(:expected_yml_manifest) do
{
'applications' => [
Expand Down Expand Up @@ -250,6 +236,19 @@
}.to_yaml
end

let(:droplet) do
VCAP::CloudController::DropletModel.make app: app_model, package: docker_package
end

let(:app_model) do
VCAP::CloudController::AppModel.make(:docker, space: space, environment_variables: { 'one' => 'tomato', 'two' => 'potato' })
end

before do
app_model.update(droplet:)
process.update(log_rate_limit: -1)
end

it 'retrieves an app manifest for the app' do
get "/v3/apps/#{app_model.guid}/manifest", nil, user_header

Expand Down
36 changes: 16 additions & 20 deletions spec/request/deployments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1005,47 +1005,27 @@

context 'with an admin who can see all deployments' do
let(:admin_user_header) { headers_for(user, scopes: %w[cloud_controller.admin]) }

let(:droplet2) { VCAP::CloudController::DropletModel.make(guid: 'droplet2') }
let(:droplet3) { VCAP::CloudController::DropletModel.make(guid: 'droplet3') }
let(:droplet4) { VCAP::CloudController::DropletModel.make(guid: 'droplet4') }
let(:droplet5) { VCAP::CloudController::DropletModel.make(guid: 'droplet5') }
let(:app2) { droplet2.app }
let(:app3) { droplet3.app }
let(:app4) { droplet4.app }
let(:app5) { droplet5.app }

before do
app2.update(space:)
app3.update(space:)
app4.update(space:)
app5.update(space:)
end

let!(:deployment2) do
VCAP::CloudController::DeploymentModelTestFactory.make(app: app2, droplet: droplet2,
previous_droplet: droplet2,
status_value: VCAP::CloudController::DeploymentModel::ACTIVE_STATUS_VALUE,
state: VCAP::CloudController::DeploymentModel::CANCELING_STATE,
status_reason: VCAP::CloudController::DeploymentModel::CANCELING_STATUS_REASON)
end

let!(:deployment3) do
VCAP::CloudController::DeploymentModelTestFactory.make(app: app3, droplet: droplet3,
previous_droplet: droplet3,
status_value: VCAP::CloudController::DeploymentModel::FINALIZED_STATUS_VALUE,
state: VCAP::CloudController::DeploymentModel::DEPLOYED_STATE,
status_reason: VCAP::CloudController::DeploymentModel::DEPLOYED_STATUS_REASON)
end

let!(:deployment4) do
VCAP::CloudController::DeploymentModelTestFactory.make(app: app4, droplet: droplet4,
previous_droplet: droplet4,
status_value: VCAP::CloudController::DeploymentModel::FINALIZED_STATUS_VALUE,
state: VCAP::CloudController::DeploymentModel::CANCELED_STATE,
status_reason: VCAP::CloudController::DeploymentModel::CANCELED_STATUS_REASON)
end

let!(:deployment5) do
VCAP::CloudController::DeploymentModelTestFactory.make(app: app5, droplet: droplet5,
previous_droplet: droplet5,
Expand All @@ -1054,6 +1034,22 @@
status_reason: VCAP::CloudController::DeploymentModel::SUPERSEDED_STATUS_REASON)
end

let(:droplet2) { VCAP::CloudController::DropletModel.make(guid: 'droplet2') }
let(:droplet3) { VCAP::CloudController::DropletModel.make(guid: 'droplet3') }
let(:droplet4) { VCAP::CloudController::DropletModel.make(guid: 'droplet4') }
let(:droplet5) { VCAP::CloudController::DropletModel.make(guid: 'droplet5') }
let(:app2) { droplet2.app }
let(:app3) { droplet3.app }
let(:app4) { droplet4.app }
let(:app5) { droplet5.app }

before do
app2.update(space:)
app3.update(space:)
app4.update(space:)
app5.update(space:)
end

def json_for_deployment(deployment, app_model, droplet, status_value, status_reason, cancel_link=true)
{
guid: deployment.guid,
Expand Down
90 changes: 41 additions & 49 deletions spec/request/domains_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,35 +711,32 @@

context 'when querying with only port' do
let(:router_group) { VCAP::CloudController::RoutingApi::RouterGroup.new({ 'type' => 'tcp', 'reservable_ports' => '123' }) }
let(:domain) { VCAP::CloudController::SharedDomain.make(router_group_guid: 'some-router-group', name: 'my.domain') }
let(:routing_api_client) { instance_double(VCAP::CloudController::RoutingApi::Client) }

before do
TestConfig.override(
kubernetes: { host_url: nil },
external_domain: 'api2.vcap.me',
external_protocol: 'https'
)
allow_any_instance_of(CloudController::DependencyLocator).to receive(:routing_api_client).and_return(routing_api_client)
allow(routing_api_client).to receive_messages(enabled?: true, router_group: router_group)
end

let!(:other_route) { VCAP::CloudController::Route.make(host: '', space: space, domain: domain, port: 123) }
let(:api_call) { ->(user_headers) { get "/v3/domains/#{domain.guid}/route_reservations?port=123", nil, user_headers } }

let(:matching_route_json) do
{
matching_route: true
}
end

let(:expected_codes_and_responses) do
h = Hash.new(
code: 200,
response_object: matching_route_json
)
h
end
let(:domain) { VCAP::CloudController::SharedDomain.make(router_group_guid: 'some-router-group', name: 'my.domain') }
let(:routing_api_client) { instance_double(VCAP::CloudController::RoutingApi::Client) }

before do
TestConfig.override(
kubernetes: { host_url: nil },
external_domain: 'api2.vcap.me',
external_protocol: 'https'
)
allow_any_instance_of(CloudController::DependencyLocator).to receive(:routing_api_client).and_return(routing_api_client)
allow(routing_api_client).to receive_messages(enabled?: true, router_group: router_group)
end

it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS

Expand Down Expand Up @@ -1552,6 +1549,23 @@

describe 'when the user does not have read permissions for the domain' do
let(:org1) { VCAP::CloudController::Organization.make(guid: 'org1') }
let(:api_call) { ->(user_headers) { post "/v3/domains/#{unreadable_domain.guid}/relationships/shared_organizations", unreadable_domain_params.to_json, user_headers } }
let(:expected_codes_and_responses) do
h = Hash.new(
code: 404
)
h['admin'] = {
code: 200,
response_object: domain_shared_orgs
}
h['admin_read_only'] = {
code: 403
}
h['global_auditor'] = {
code: 403
}
h
end
let(:org2) { VCAP::CloudController::Organization.make(guid: 'org2') }
let!(:shared_domain) { VCAP::CloudController::SharedDomain.make }
let(:unreadable_domain) { VCAP::CloudController::PrivateDomain.make(owning_organization: org1) }
Expand All @@ -1572,25 +1586,6 @@
org2.add_manager(user)
end

let(:api_call) { ->(user_headers) { post "/v3/domains/#{unreadable_domain.guid}/relationships/shared_organizations", unreadable_domain_params.to_json, user_headers } }

let(:expected_codes_and_responses) do
h = Hash.new(
code: 404
)
h['admin'] = {
code: 200,
response_object: domain_shared_orgs
}
h['admin_read_only'] = {
code: 403
}
h['global_auditor'] = {
code: 403
}
h
end

it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
end
Expand Down Expand Up @@ -2038,15 +2033,6 @@

context 'when the domain has been shared with another organization' do
let!(:non_visible_org) { VCAP::CloudController::Organization.make }
let!(:user_visible_org) { VCAP::CloudController::Organization.make }

let(:private_domain) { VCAP::CloudController::PrivateDomain.make(owning_organization: org) }

before do
non_visible_org.add_private_domain(private_domain)
user_visible_org.add_private_domain(private_domain)
end

let(:private_domain_json) do
{
guid: private_domain.guid,
Expand Down Expand Up @@ -2078,23 +2064,29 @@
}
}
end

let(:api_call) { ->(user_headers) { get "/v3/domains/#{private_domain.guid}", nil, user_headers } }
let!(:user_visible_org) { VCAP::CloudController::Organization.make }

context 'when the user can read in the shared organization' do
let(:shared_organizations) { [{ guid: user_visible_org.guid }] }
let(:private_domain) { VCAP::CloudController::PrivateDomain.make(owning_organization: org) }

before do
user_visible_org.add_manager(user)
end
before do
non_visible_org.add_private_domain(private_domain)
user_visible_org.add_private_domain(private_domain)
end

context 'when the user can read in the shared organization' do
let(:shared_organizations) { [{ guid: user_visible_org.guid }] }
let(:expected_codes_and_responses) do
Hash.new(
code: 200,
response_object: private_domain_json
)
end

before do
user_visible_org.add_manager(user)
end

it_behaves_like 'permissions for single object endpoint', LOCAL_ROLES
end

Expand Down
Loading

0 comments on commit 1e235ca

Please sign in to comment.