-
Notifications
You must be signed in to change notification settings - Fork 368
Add validation for credentials in SB update to be not blank #2939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,18 +119,37 @@ module VCAP::CloudController | |
|
|
||
| context 'when authentication is not valid' do | ||
| let(:request_body) do | ||
| valid_body[:authentication] = valid_body[:authentication].except(:type) | ||
| valid_body | ||
| end | ||
|
|
||
| before do | ||
| allow_any_instance_of(VCAP::CloudController::Validators::AuthenticationValidator).to receive(:validate) do |_, record| | ||
| record.errors.add(:authentication, 'this authentication is not valid!') | ||
| end | ||
| it 'is not valid' do | ||
|
Comment on lines
120
to
+126
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a fix of a test which was wrong. |
||
| expect(message).not_to be_valid | ||
| expect(message.errors_on(:authentication)).to include('authentication.type must be one of ["basic"]') | ||
| end | ||
| end | ||
|
|
||
| context 'when username is an empty string' do | ||
| let(:request_body) do | ||
| valid_body[:authentication][:credentials][:username] = '' | ||
| valid_body | ||
| end | ||
|
|
||
| it 'is not valid' do | ||
| expect(message).not_to be_valid | ||
| expect(message.errors_on(:authentication)).to include(/Username can't be blank/) | ||
| end | ||
| end | ||
|
|
||
| context 'when password is an empty string' do | ||
| let(:request_body) do | ||
| valid_body[:authentication][:credentials][:password] = '' | ||
| valid_body | ||
| end | ||
|
|
||
| it 'is not valid' do | ||
| expect(message).not_to be_valid | ||
| expect(message.errors_on(:authentication)).to include('this authentication is not valid!') | ||
| expect(message.errors_on(:authentication)).to include(/Password can't be blank/) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,18 +149,37 @@ module VCAP::CloudController | |
|
|
||
| context 'when authentication is not valid' do | ||
| let(:request_body) do | ||
| valid_body[:authentication] = valid_body[:authentication].except(:type) | ||
| valid_body | ||
| end | ||
|
|
||
| before do | ||
| allow_any_instance_of(VCAP::CloudController::Validators::AuthenticationValidator).to receive(:validate) do |_, record| | ||
| record.errors.add(:authentication, 'this authentication is not valid!') | ||
| end | ||
| it 'is not valid' do | ||
| expect(message).not_to be_valid | ||
| expect(message.errors_on(:authentication)).to include('authentication.type must be one of ["basic"]') | ||
| end | ||
|
Comment on lines
150
to
+159
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same fix as in the other test file. |
||
| end | ||
|
|
||
| context 'when username is an empty string' do | ||
| let(:request_body) do | ||
| valid_body[:authentication][:credentials][:username] = '' | ||
| valid_body | ||
| end | ||
|
|
||
| it 'is not valid' do | ||
| expect(message).not_to be_valid | ||
| expect(message.errors_on(:authentication)).to include(/Username can't be blank/) | ||
| end | ||
| end | ||
|
|
||
| context 'when password is an empty string' do | ||
| let(:request_body) do | ||
| valid_body[:authentication][:credentials][:password] = '' | ||
| valid_body | ||
| end | ||
|
|
||
| it 'is not valid' do | ||
| expect(message).not_to be_valid | ||
| expect(message.errors_on(:authentication)).to include('this authentication is not valid!') | ||
| expect(message.errors_on(:authentication)).to include(/Password can't be blank/) | ||
| end | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far this test tested the only case in which the state of the SB could be reset to its previous state after a failed model validation. The broker update failed here. From then on the
brokerobject will still havestate = "AVAILABLE". In the rescue call, the broker's state will be explicitly set to the previous state and will overwrite the stateAVAILABLE, which caused the model violation to fail (see here).After changing the cause for the model violation to the name
new-name, the test failed. This is because thebroker.namewill still be set tonew-name, which previously caused the model violation. This leads to a failed broker.update in the rescue block as well. Therefore, the state cannot be reset to the previous state.