Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit ccf6ae1

Browse files
Fix v3 🐞: UnknownError when API user specifies big numbers for quota limits
-Both mysql and postgres use ints to store these fields which have a max value of 2^31 -1. [finishes #172549179] Co-authored-by: Reid Mitchell <rmitchell@pivotal.io> Co-authored-by: Merric de Launey <mdelauney@pivotal.io>
1 parent 2bca16c commit ccf6ae1

7 files changed

Lines changed: 96 additions & 9 deletions

app/messages/base_message.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class BaseMessage
66
include ActiveModel::Model
77
include Validators
88

9+
MAX_DB_INT = 2**31 - 1
10+
911
attr_accessor :requested_keys, :extra_keys
1012

1113
def self.allowed_keys

app/messages/quotas_apps_message.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class QuotasAppsMessage < BaseMessage
88
validates_with NoAdditionalKeysValidator
99

1010
validates :total_memory_in_mb,
11-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
11+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
1212
allow_nil: true
1313

1414
validates :per_process_memory_in_mb,
15-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
15+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
1616
allow_nil: true
1717

1818
validates :total_instances,
19-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
19+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
2020
allow_nil: true
2121

2222
validates :per_app_tasks,
23-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
23+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
2424
allow_nil: true
2525
end
2626
end

app/messages/quotas_routes_message.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class QuotasRoutesMessage < BaseMessage
88
validates_with NoAdditionalKeysValidator
99

1010
validates :total_routes,
11-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
11+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
1212
allow_nil: true
1313

1414
validates :total_reserved_ports,
15-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
15+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
1616
allow_nil: true
1717
end
1818
end

app/messages/quotas_services_message.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class QuotasServicesMessage < BaseMessage
88
validates_with NoAdditionalKeysValidator
99

1010
validates :total_service_keys,
11-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
11+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
1212
allow_nil: true
1313

1414
validates :total_service_instances,
15-
numericality: { only_integer: true, greater_than_or_equal_to: 0 },
15+
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DB_INT },
1616
allow_nil: true
1717

1818
validates :paid_services_allowed,

spec/unit/messages/quotas_apps_message_spec.rb

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,18 @@ module VCAP::CloudController
5050
end
5151
end
5252

53-
context 'when the type is zero' do
53+
context 'when the value is greater than the maximum allowed value in the DB' do
54+
let(:params) do
55+
{ total_memory_in_mb: 1000000000000000000000000 }
56+
end
57+
58+
it 'is not valid' do
59+
expect(subject).to be_invalid
60+
expect(subject.errors).to contain_exactly('Total memory in mb must be less than or equal to 2147483647')
61+
end
62+
end
63+
64+
context 'when the value is zero' do
5465
let(:params) do
5566
{ total_memory_in_mb: 0 }
5667
end
@@ -112,6 +123,17 @@ module VCAP::CloudController
112123

113124
it { is_expected.to be_valid }
114125
end
126+
127+
context 'when the value is greater than the maximum allowed value in the DB' do
128+
let(:params) do
129+
{ per_process_memory_in_mb: 1000000000000000000000000 }
130+
end
131+
132+
it 'is not valid' do
133+
expect(subject).to be_invalid
134+
expect(subject.errors).to contain_exactly('Per process memory in mb must be less than or equal to 2147483647')
135+
end
136+
end
115137
end
116138

117139
describe 'total_instances' do
@@ -160,6 +182,17 @@ module VCAP::CloudController
160182

161183
it { is_expected.to be_valid }
162184
end
185+
186+
context 'when the value is greater than the maximum allowed value in the DB' do
187+
let(:params) do
188+
{ total_instances: 1000000000000000000000000 }
189+
end
190+
191+
it 'is not valid' do
192+
expect(subject).to be_invalid
193+
expect(subject.errors).to contain_exactly('Total instances must be less than or equal to 2147483647')
194+
end
195+
end
163196
end
164197

165198
describe 'per_app_tasks' do
@@ -211,6 +244,17 @@ module VCAP::CloudController
211244

212245
it { is_expected.to be_valid }
213246
end
247+
248+
context 'when the value is greater than the maximum allowed value in the DB' do
249+
let(:params) do
250+
{ per_app_tasks: 1000000000000000000000000 }
251+
end
252+
253+
it 'is not valid' do
254+
expect(subject).to be_invalid
255+
expect(subject.errors).to contain_exactly('Per app tasks must be less than or equal to 2147483647')
256+
end
257+
end
214258
end
215259
end
216260
end

spec/unit/messages/quotas_routes_message_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ module VCAP::CloudController
6565

6666
it { is_expected.to be_valid }
6767
end
68+
69+
context 'when the value is greater than the maximum allowed value in the DB' do
70+
let(:params) do
71+
{ total_routes: 1000000000000000000000000 }
72+
end
73+
74+
it 'is not valid' do
75+
expect(subject).to be_invalid
76+
expect(subject.errors).to contain_exactly('Total routes must be less than or equal to 2147483647')
77+
end
78+
end
6879
end
6980

7081
describe 'total_reserved_ports' do
@@ -116,6 +127,16 @@ module VCAP::CloudController
116127

117128
it { is_expected.to be_valid }
118129
end
130+
context 'when the value is greater than the maximum allowed value in the DB' do
131+
let(:params) do
132+
{ total_reserved_ports: 1000000000000000000000000 }
133+
end
134+
135+
it 'is not valid' do
136+
expect(subject).to be_invalid
137+
expect(subject.errors).to contain_exactly('Total reserved ports must be less than or equal to 2147483647')
138+
end
139+
end
119140
end
120141
end
121142
end

spec/unit/messages/quotas_services_message_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ module VCAP::CloudController
6262

6363
it { is_expected.to be_valid }
6464
end
65+
context 'when the value is greater than the maximum allowed value in the DB' do
66+
let(:params) do
67+
{ total_service_instances: 1000000000000000000000000 }
68+
end
69+
70+
it 'is not valid' do
71+
expect(subject).to be_invalid
72+
expect(subject.errors).to contain_exactly('Total service instances must be less than or equal to 2147483647')
73+
end
74+
end
6575
end
6676

6777
describe 'total_service_keys' do
@@ -110,6 +120,16 @@ module VCAP::CloudController
110120

111121
it { is_expected.to be_valid }
112122
end
123+
context 'when the value is greater than the maximum allowed value in the DB' do
124+
let(:params) do
125+
{ total_service_keys: 1000000000000000000000000 }
126+
end
127+
128+
it 'is not valid' do
129+
expect(subject).to be_invalid
130+
expect(subject.errors).to contain_exactly('Total service keys must be less than or equal to 2147483647')
131+
end
132+
end
113133
end
114134

115135
describe 'paid_services_allowed' do

0 commit comments

Comments
 (0)