debian-mirror-gitlab/spec/models/integrations/harbor_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
3.1 KiB
Ruby
Raw Normal View History

2022-05-07 20:08:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::Harbor do
let(:url) { 'https://demo.goharbor.io' }
let(:project_name) { 'testproject' }
let(:username) { 'harborusername' }
let(:password) { 'harborpassword' }
2022-11-25 23:54:43 +05:30
let(:harbor_integration) { build(:harbor_integration) }
it_behaves_like Integrations::ResetSecretFields do
let(:integration) { described_class.new }
end
2022-05-07 20:08:51 +05:30
describe "masked password" do
subject { build(:harbor_integration) }
it { is_expected.not_to allow_value('hello').for(:password) }
it { is_expected.not_to allow_value('hello world').for(:password) }
it { is_expected.not_to allow_value('hello$VARIABLEworld').for(:password) }
it { is_expected.not_to allow_value('hello\rworld').for(:password) }
it { is_expected.to allow_value('helloworld').for(:password) }
end
2022-08-13 15:12:31 +05:30
describe 'url' do
subject { build(:harbor_integration) }
it { is_expected.not_to allow_value('https://192.168.1.1').for(:url) }
it { is_expected.not_to allow_value('https://127.0.0.1').for(:url) }
2022-08-27 11:52:29 +05:30
it { is_expected.to allow_value('https://demo.goharbor.io').for(:url) }
2022-08-13 15:12:31 +05:30
end
2022-10-11 01:57:18 +05:30
describe 'hostname' do
it 'returns the host of the integration url' do
expect(harbor_integration.hostname).to eq('demo.goharbor.io')
end
end
2022-05-07 20:08:51 +05:30
describe '#fields' do
it 'returns custom fields' do
expect(harbor_integration.fields.pluck(:name)).to eq(%w[url project_name username password])
end
end
describe '#test' do
let(:test_response) { "pong" }
before do
allow_next_instance_of(Gitlab::Harbor::Client) do |client|
allow(client).to receive(:ping).and_return(test_response)
end
end
it 'gets response from Gitlab::Harbor::Client#ping' do
expect(harbor_integration.test).to eq(test_response)
end
end
describe '#help' do
it 'renders prompt information' do
expect(harbor_integration.help).not_to be_empty
end
end
describe '.to_param' do
it 'returns the name of the integration' do
expect(described_class.to_param).to eq('harbor')
end
end
context 'ci variables' do
2022-11-25 23:54:43 +05:30
let(:harbor_integration) { create(:harbor_integration) }
2022-05-07 20:08:51 +05:30
it 'returns vars when harbor_integration is activated' do
ci_vars = [
{ key: 'HARBOR_URL', value: url },
2022-08-27 11:52:29 +05:30
{ key: 'HARBOR_HOST', value: 'demo.goharbor.io' },
{ key: 'HARBOR_OCI', value: 'oci://demo.goharbor.io' },
2022-05-07 20:08:51 +05:30
{ key: 'HARBOR_PROJECT', value: project_name },
{ key: 'HARBOR_USERNAME', value: username },
{ key: 'HARBOR_PASSWORD', value: password, public: false, masked: true }
]
expect(harbor_integration.ci_variables).to match_array(ci_vars)
end
it 'returns [] when harbor_integration is inactive' do
harbor_integration.update!(active: false)
expect(harbor_integration.ci_variables).to match_array([])
end
2022-07-23 23:45:48 +05:30
context 'with robot username' do
it 'returns username variable with $$' do
harbor_integration.username = 'robot$project+user'
expect(harbor_integration.ci_variables).to include(
{ key: 'HARBOR_USERNAME', value: 'robot$$project+user' }
)
end
end
2022-05-07 20:08:51 +05:30
end
end