diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/models/integrations/harbor_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/models/integrations/harbor_spec.rb')
-rw-r--r-- | spec/models/integrations/harbor_spec.rb | 70 |
1 files changed, 7 insertions, 63 deletions
diff --git a/spec/models/integrations/harbor_spec.rb b/spec/models/integrations/harbor_spec.rb index 26b43fa3313..9ab37a92e89 100644 --- a/spec/models/integrations/harbor_spec.rb +++ b/spec/models/integrations/harbor_spec.rb @@ -7,7 +7,11 @@ RSpec.describe Integrations::Harbor do let(:project_name) { 'testproject' } let(:username) { 'harborusername' } let(:password) { 'harborpassword' } - let(:harbor_integration) { create(:harbor_integration) } + let(:harbor_integration) { build(:harbor_integration) } + + it_behaves_like Integrations::ResetSecretFields do + let(:integration) { described_class.new } + end describe "masked password" do subject { build(:harbor_integration) } @@ -66,6 +70,8 @@ RSpec.describe Integrations::Harbor do end context 'ci variables' do + let(:harbor_integration) { create(:harbor_integration) } + it 'returns vars when harbor_integration is activated' do ci_vars = [ { key: 'HARBOR_URL', value: url }, @@ -94,66 +100,4 @@ RSpec.describe Integrations::Harbor do end end end - - describe 'before_validation :reset_username_and_password' do - context 'when username/password was previously set' do - it 'resets username and password if url changed' do - harbor_integration.url = 'https://anotherharbor.com' - harbor_integration.valid? - - expect(harbor_integration.password).to be_nil - expect(harbor_integration.username).to be_nil - end - - it 'does not reset password if username changed' do - harbor_integration.username = 'newusername' - harbor_integration.valid? - - expect(harbor_integration.password).to eq('harborpassword') - end - - it 'does not reset username if password changed' do - harbor_integration.password = 'newpassword' - harbor_integration.valid? - - expect(harbor_integration.username).to eq('harborusername') - end - - it "does not reset password if new url is set together with password, even if it's the same password" do - harbor_integration.url = 'https://anotherharbor.com' - harbor_integration.password = 'harborpassword' - harbor_integration.valid? - - expect(harbor_integration.password).to eq('harborpassword') - expect(harbor_integration.username).to be_nil - expect(harbor_integration.url).to eq('https://anotherharbor.com') - end - - it "does not reset username if new url is set together with username, even if it's the same username" do - harbor_integration.url = 'https://anotherharbor.com' - harbor_integration.username = 'harborusername' - harbor_integration.valid? - - expect(harbor_integration.password).to be_nil - expect(harbor_integration.username).to eq('harborusername') - expect(harbor_integration.url).to eq('https://anotherharbor.com') - end - end - - it 'saves password if new url is set together with password when no password was previously set' do - harbor_integration.password = nil - harbor_integration.username = nil - - harbor_integration.url = 'https://anotherharbor.com' - harbor_integration.password = 'newpassword' - harbor_integration.username = 'newusername' - harbor_integration.save! - - expect(harbor_integration).to have_attributes( - url: 'https://anotherharbor.com', - password: 'newpassword', - username: 'newusername' - ) - end - end end |