Añade plugin Redmine Git Hosting 4.0.2
This commit is contained in:
parent
472cb1ea76
commit
bdd66d941f
494 changed files with 36768 additions and 0 deletions
|
@ -0,0 +1,258 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe GitolitePublicKey do
|
||||
SSH_KEY_0 = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpqFJzsx3wTi3t3X/eOizU6rdtNQoqg5uSjL89F+Ojjm2/sah3ouzx+3E461FDYaoJL58Qs9eRhL+ev0BY7khYXph8nIVDzNEjhLqjevX+YhpaW9Ll7V807CwAyvMNm08aup/NrrlI/jO+At348/ivJrfO7ClcPhq4+Id9RZfvbrKaitGOURD7q6Bd7xjUjELUN8wmYxu5zvx/2n/5woVdBUMXamTPxOY5y6DxTNJ+EYzrCr+bNb7459rWUvBHUQGI2fXDGmFpGiv6ShKRhRtwob1JHI8QC9OtxonrIUesa2dW6RFneUaM7tfRfffC704Uo7yuSswb7YK+p1A9QIt5 nicolas@tchoum'
|
||||
SSH_KEY_1 = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz0pLXcQWS4gLUimUSLwDOvEmQF8l8EKoj0LjxOyM3y2dpLsn0aiqS0ecA0G/ROomaawop8EZGFetoJKJM468OZlx2aKoQemzvFIq0Mn1ZhcrlA1alAsDYqzZI8iHO4JIS3YbeLLkVGAlYA+bmA5enXN9mGhC9cgoMC79EZiLD9XvOw4iXDjqXaCzFZHU1shMWwaJfpyxBm+Mxs2vtZzwETDqeu9rohNMl60dODf6+JoXYiahP+B+P2iKlL7ORb1YsAH/4ZMsVgRckj8snb4uc3XgwLRNNw+oB78ApZGr0j3Zc32U9rpmulbHIroWO07OV4Xsplnu8lhGvfodA2gjb nicolas@tchoum'
|
||||
SSH_KEY_2 = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5+JfM82k03J98GWL6ghJ4TYM8DbvDnVh1s1rUDNlM/1U5rwbgXHOR4xV3lulgYEYRtYeMoL3rt4ZpEyXWkOreOVsUlkW66SZJR5aGVTNJOLX7HruEDqj7RWlt0u0MH6DgBVAJimQrxYN50jYD4XnDUjb/qv55EhPvbJ3jcAb3zuyRXMKZYGNVzVFLUagbvVaOwR23csWSLDTsAEI9JzaxMKvCNRwk3jFepiCovXbw+g0iyvJdp0+AJpC57ZupyxHeX9J2oz7im2UaHHqLa2qUZL6c4PNV/D2p0Bts4Tcnn3OFPL90RF/ao0tjiUFxM3ti8pRHOqRcZHcOgIhKiaLX nicolas@tchoum'
|
||||
SSH_KEY_3 = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/pSRh11xbadAh24fQlc0i0dneG0lI+DCkng+bVmumgRvfD0w79vcJ2U1qir2ChjpNvi2n96HUGIEGNV60/VG05JY70mEb//YVBmQ3w0QPO7toEWNms9SQlwR0PN6tarATumFik4MI+8M23P6W8O8OYwsnMmYwaiEU5hDopH88x74MQKjPiRSrhMkGiThMZhLVK6j8yfNPoj9yUxPBWc7zsMCC2uAOfR5Fg6hl2TKGxTi0vecTh1csDcO2agXx42RRiZeIQbv9j0IJjVL8KhXvbndVnJRjGGbxQFAedicw8OrPH7jz6NimmaTooqU9SwaPInK/x3omd297/zzcQm3p nicolas@tchoum'
|
||||
SSH_KEY_4 = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCScLGus1vrZ9OyzOj3TtYa+IHUp5V+2hwcMW7pphGIAPRi5Pe6GwSbSV5GnanerOH9ucmEREaCIdGOzO2zVI35e3RD6wTeW28Ck7JN1r2LSgSvXGvxGyzu0H4Abf66Kajt+lN0/71tbFtoTaJTGSYE3W0rNU6OQBvHf1o4wIyBEFm3cu+e2OrmW/nVIqk8hCN2cU/0OutOWT+vaRLbIU3VQmHftqa4NVxdc4OG48vpZxlJwKexqAHj8Ok/sn3k4CIo8zR0vRaeGPqAmOpm84uEfRWoA71NNS4tIhENlikuD5SJIdyXE9d8CwGTth4jP9/BNT0y4C8cGYljjUWkx3v nicolas@tchoum'
|
||||
|
||||
before(:all) do
|
||||
@user1 = create_user('git_user1')
|
||||
@user2 = create_user('git_user2')
|
||||
end
|
||||
|
||||
# There is an isolation issue in tests.
|
||||
# Try to workaround it...
|
||||
def test_user
|
||||
'redmine_git_user1_12'
|
||||
end
|
||||
|
||||
describe 'Valid SSH key build' do
|
||||
before(:each) do
|
||||
@ssh_key = build_ssh_key(title: 'test-key')
|
||||
end
|
||||
|
||||
subject { @ssh_key }
|
||||
|
||||
## Relations
|
||||
it { is_expected.to belong_to(:user) }
|
||||
it { is_expected.to have_many(:repository_deployment_credentials) }
|
||||
|
||||
## Validations
|
||||
it { is_expected.to be_valid }
|
||||
|
||||
it { is_expected.to validate_presence_of(:title) }
|
||||
it { is_expected.to validate_presence_of(:user_id) }
|
||||
it { is_expected.to validate_presence_of(:key) }
|
||||
it { is_expected.to validate_presence_of(:key_type) }
|
||||
|
||||
it { is_expected.to validate_numericality_of(:key_type) }
|
||||
|
||||
it { is_expected.to validate_inclusion_of(:key_type).in_array(%w[0 1]) }
|
||||
|
||||
it { is_expected.to ensure_length_of(:title).is_at_most(60) }
|
||||
|
||||
it { is_expected.not_to allow_value('toto@toto', 'ma_clé').for(:title) }
|
||||
|
||||
it { is_expected.to respond_to(:identifier) }
|
||||
it { is_expected.to respond_to(:fingerprint) }
|
||||
it { is_expected.to respond_to(:owner) }
|
||||
it { is_expected.to respond_to(:location) }
|
||||
it { is_expected.to respond_to(:gitolite_path) }
|
||||
it { is_expected.to respond_to(:data_for_destruction) }
|
||||
|
||||
## Attributes content
|
||||
it 'can render as string' do
|
||||
expect(@ssh_key.to_s).to eq 'test-key'
|
||||
end
|
||||
|
||||
it 'has a title' do
|
||||
expect(@ssh_key.title).to eq 'test-key'
|
||||
end
|
||||
|
||||
it 'is a user key' do
|
||||
expect(@ssh_key.user_key?).to be true
|
||||
end
|
||||
|
||||
it 'is not a deploy key' do
|
||||
expect(@ssh_key.deploy_key?).to be false
|
||||
end
|
||||
|
||||
it 'must be deleted when unused' do
|
||||
expect(@ssh_key.delete_when_unused?).to be true
|
||||
end
|
||||
|
||||
## Test data integrity
|
||||
it 'should not truncate key' do
|
||||
expect(@ssh_key.key.length).to be == SSH_KEY_0.length
|
||||
end
|
||||
|
||||
## Test change validation
|
||||
describe 'when delete_when_unused is false' do
|
||||
it 'should not be deleted when unused' do
|
||||
@ssh_key.delete_when_unused = false
|
||||
expect(@ssh_key.delete_when_unused?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when delete_when_unused is true' do
|
||||
it 'should be deleted when unused' do
|
||||
@ssh_key.delete_when_unused = true
|
||||
expect(@ssh_key.delete_when_unused?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Valid SSH key creation' do
|
||||
let(:ssh_key) { create_ssh_key(user_id: @user1.id, title: 'test-key') }
|
||||
|
||||
subject { ssh_key }
|
||||
|
||||
it 'has an identifier' do
|
||||
expect(ssh_key.identifier).to eq "#{test_user}@redmine_test_key"
|
||||
end
|
||||
|
||||
it 'has a fingerprint' do
|
||||
expect(ssh_key.fingerprint).to eq "SHA256:VgXjWgUbURtD6go5HV7Eop2UqVjmIAI68shaB66yv+c"
|
||||
end
|
||||
|
||||
it 'has a owner' do
|
||||
expect(ssh_key.owner).to eq test_user
|
||||
end
|
||||
|
||||
it 'has a location' do
|
||||
expect(ssh_key.location).to eq 'redmine_test_key'
|
||||
end
|
||||
|
||||
it 'has a gitolite_path' do
|
||||
expect(ssh_key.gitolite_path).to eq "keydir/redmine_git_hosting/#{test_user}/redmine_test_key/#{test_user}.pub"
|
||||
end
|
||||
|
||||
it 'it has data hash for destruction' do
|
||||
valid_hash = { key: SSH_KEY_0, location: 'redmine_test_key', owner: test_user, title: "#{test_user}@redmine_test_key" }
|
||||
expect(ssh_key.data_for_destruction).to eq valid_hash
|
||||
end
|
||||
|
||||
context 'when identifier is changed' do
|
||||
before { ssh_key.identifier = 'foo' }
|
||||
|
||||
it { is_expected.not_to be_valid }
|
||||
end
|
||||
|
||||
context 'when key is changed' do
|
||||
before { ssh_key.key = 'foo' }
|
||||
|
||||
it { is_expected.not_to be_valid }
|
||||
end
|
||||
|
||||
context 'when user_id is changed' do
|
||||
before { ssh_key.user_id = @user2.id }
|
||||
|
||||
it { is_expected.not_to be_valid }
|
||||
end
|
||||
|
||||
context 'when key_type is changed' do
|
||||
before { ssh_key.key_type = 1 }
|
||||
|
||||
it { is_expected.not_to be_valid }
|
||||
end
|
||||
|
||||
# Test reset_identifiers
|
||||
context 'when identifiers are reset' do
|
||||
before do
|
||||
@old_identifier = ssh_key.identifier
|
||||
@old_fingerprint = ssh_key.fingerprint
|
||||
|
||||
ssh_key.reset_identifiers
|
||||
end
|
||||
|
||||
it { is_expected.to be_valid }
|
||||
|
||||
it 'should have the same identifier' do
|
||||
expect(ssh_key.identifier).to eq @old_identifier
|
||||
end
|
||||
|
||||
it 'should have the same fingerprint' do
|
||||
expect(ssh_key.fingerprint).to eq @old_fingerprint
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Valid SSH key format' do
|
||||
describe 'when ssh key format is valid' do
|
||||
ssh_keys = [
|
||||
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/Ec2gummukPxlpPHZ7K96iBdG5n8v0PJEDvTVZRRFlS0QYa407gj9HuMrPjwEfVHqy+3KZmvKLWQBsSlf0Fn+eAPgnoqwVfZaJnfgkSxJiAzRraKQZX1m2wx2SVMfjw7/1j59zV60UhFiwEQ3Eqlg3xjQmjvrwDM+SoshrWB+TeqwO/K+QEP1ZbURYoCxc92GrLYWKixsAov/zr0loXqul9fydZcWwJE3H/BWC7PTtn4jfjG9+9F+SZ0OMwQvSGKhVlj3GBDtaDBnsuoHGh/CA2W240nwpQysG2BJ5DWXu6vKbjNn6uV91wXeKDEDpuWqv5Vi2XAxGTWKc5lF0IJ5 nicolas@tchoum',
|
||||
'ssh-dss AAAAB3NzaC1kc3MAAACBAKscxrmjRgXtb0ZUaaBUteBtF2cI0vStnni9KVQd94L8qqxvKLbDl5JTKjUvG2s7rD4sVRzBoTkuDGb7OZLf56wJyF3k+k8uNRJzvH/CZbkKM2hjuRVYVort1EwcH7JiEQr7bCLe7MRaltuo/M1vhapwy7fhKxAo9YoYVWiGoFTVAAAAFQDPywT8yFDahFvxtt/95Q9Emq8R7QAAAIBHYnvt3hT9NYy+nOuZG+cQTz0hnVzUIWuj0XF2iyx52s2eSmF0HxIsZ0D9g2A0L1Xr/vlkWBMq/zJZJgJw2Ifys8L47HzjhL8K0Skdm23Z6rQR9hlOEZ5Rcank98U6VRYPWpYk7OLdRDruwXb+Ms5YhIztxsGO3YfRBdSBrW4DMAAAAIAJmmwivw3XoFP6C97LB+tJAjWRYJHpiDwOWNDKu0dZewUzUAo40NuHNgKJS2nsxW0sphaeMtf70IbvDsFQG45I+G2dlt+s19t4YCbVcz7xrw7LceEz+f0UR2/Z+LIK2GPIIoyymOq/kIIxni3xgKDl4mvvt45TTsQzs0zhkmEy/g== nicolas@tchoum',
|
||||
'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLIcYw8NbJc28tDsC+8sf/o14hQmQfdC31OFP0eb5qFVRgEjMJ9mwolqWIW+AcbIAhX2GJVdTLZoUJj6T5PiUtM= nicolas@tchoum'
|
||||
]
|
||||
|
||||
ssh_keys.each do |valid_key|
|
||||
it 'should be valid' do
|
||||
expect(build_ssh_key(key: valid_key)).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'when SSH key already exist' do
|
||||
before { create_ssh_key(user_id: @user1.id, title: 'test-key2') }
|
||||
|
||||
## Test uniqueness validation
|
||||
context 'and title is already taken' do
|
||||
it { expect(build_ssh_key(user_id: @user1.id, title: 'test-key2', key: SSH_KEY_1)).not_to be_valid }
|
||||
end
|
||||
|
||||
context 'and is already taken by someone' do
|
||||
it { expect(build_ssh_key(user_id: @user1.id, title: 'foo')).not_to be_valid }
|
||||
end
|
||||
|
||||
context 'and is already taken by current user' do
|
||||
it 'should_not be_valid' do
|
||||
User.current = @user1
|
||||
expect(build_ssh_key(user_id: @user1.id, title: 'foo')).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'and is already taken by other user and current user is admin' do
|
||||
it 'should_not be_valid' do
|
||||
@user2.admin = true
|
||||
User.current = @user2
|
||||
expect(build_ssh_key(user_id: @user1.id, title: 'foo')).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'and is already taken by other user and current user is not admin' do
|
||||
it 'should_not be_valid' do
|
||||
User.current = @user2
|
||||
expect(build_ssh_key(user_id: @user1.id, title: 'foo')).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Gitolite Admin ssh key is reused' do
|
||||
it 'should not be valid' do
|
||||
expect(build_ssh_key(user_id: @user1.id, title: 'foo', key: File.read(RedmineGitHosting::Config.gitolite_ssh_public_key))).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'when many keys are saved' do
|
||||
before do
|
||||
create_ssh_key(user: @user1, title: 'active1', key: SSH_KEY_1, key_type: 1)
|
||||
create_ssh_key(user: @user1, title: 'active2', key: SSH_KEY_2, key_type: 1)
|
||||
create_ssh_key(user: @user2, title: 'active3', key: SSH_KEY_3)
|
||||
create_ssh_key(user: @user2, title: 'active4', key: SSH_KEY_4)
|
||||
end
|
||||
|
||||
it 'should have 6 keys' do
|
||||
expect(GitolitePublicKey.all.length).to be == 5
|
||||
end
|
||||
|
||||
it 'should have 2 user keys' do
|
||||
expect(GitolitePublicKey.user_key.length).to be == 2
|
||||
end
|
||||
|
||||
it 'should have 4 deploy keys' do
|
||||
expect(GitolitePublicKey.deploy_key.length).to be == 3
|
||||
end
|
||||
|
||||
it 'user1 should have 2 keys' do
|
||||
expect(@user1.gitolite_public_keys.length).to be == 2
|
||||
end
|
||||
|
||||
it 'user2 should have 2 keys' do
|
||||
expect(@user2.gitolite_public_keys.length).to be == 2
|
||||
end
|
||||
end
|
||||
end
|
10
plugins/redmine_git_hosting/spec/models/group_spec.rb
Normal file
10
plugins/redmine_git_hosting/spec/models/group_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require File.expand_path('../spec_helper', __dir__)
|
||||
|
||||
describe Group do
|
||||
subject { group }
|
||||
|
||||
let(:group) { build(:group) }
|
||||
|
||||
it { is_expected.to have_many(:protected_branches_members).dependent(:destroy) }
|
||||
it { is_expected.to have_many(:protected_branches).through(:protected_branches_members) }
|
||||
end
|
38
plugins/redmine_git_hosting/spec/models/project_spec.rb
Normal file
38
plugins/redmine_git_hosting/spec/models/project_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe Project do
|
||||
|
||||
before(:all) do
|
||||
@project = create(:project)
|
||||
@git_repo_1 = create_git_repository(project: @project, is_default: true)
|
||||
@git_repo_2 = create_git_repository(project: @project, identifier: 'git-repo-test')
|
||||
@svn_repo_1 = create_svn_repository(project: @project, identifier: 'svn-repo-test', url: 'http://svn-repo-test')
|
||||
end
|
||||
|
||||
subject { @project }
|
||||
|
||||
## Test relations
|
||||
it { should respond_to(:gitolite_repos) }
|
||||
it { should respond_to(:repo_blank_ident) }
|
||||
|
||||
it 'should have 1 repository with blank ident' do
|
||||
expect(@project.repo_blank_ident).to eq @git_repo_1
|
||||
end
|
||||
|
||||
it 'should have 2 Git repositories' do
|
||||
expect(@project.gitolite_repos).to include @git_repo_1, @git_repo_2
|
||||
end
|
||||
|
||||
it 'should have 3 repositories' do
|
||||
expect(@project.repositories).to include @git_repo_1, @git_repo_2, @svn_repo_1
|
||||
end
|
||||
|
||||
it 'should not match existing repository identifier' do
|
||||
expect(build(:project, identifier: 'git-repo-test')).to be_invalid
|
||||
end
|
||||
|
||||
it 'should not match Gitolite Admin repository identifier' do
|
||||
expect(build(:project, identifier: 'gitolite-admin')).to be_invalid
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,70 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe RepositoryDeploymentCredential do
|
||||
|
||||
DEPLOY_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz0pLXcQWS4gLUimUSLwDOvEmQF8l8EKoj0LjxOyM3y2dpLsn0aiqS0ecA0G/ROomaawop8EZGFetoJKJM468OZlx2aKoQemzvFIq0Mn1ZhcrlA1alAsDYqzZI8iHO4JIS3YbeLLkVGAlYA+bmA5enXN9mGhC9cgoMC79EZiLD9XvOw4iXDjqXaCzFZHU1shMWwaJfpyxBm+Mxs2vtZzwETDqeu9rohNMl60dODf6+JoXYiahP+B+P2iKlL7ORb1YsAH/4ZMsVgRckj8snb4uc3XgwLRNNw+oB78ApZGr0j3Zc32U9rpmulbHIroWO07OV4Xsplnu8lhGvfodA2gjb nicolas@tchoum'
|
||||
USER_KEY = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5+JfM82k03J98GWL6ghJ4TYM8DbvDnVh1s1rUDNlM/1U5rwbgXHOR4xV3lulgYEYRtYeMoL3rt4ZpEyXWkOreOVsUlkW66SZJR5aGVTNJOLX7HruEDqj7RWlt0u0MH6DgBVAJimQrxYN50jYD4XnDUjb/qv55EhPvbJ3jcAb3zuyRXMKZYGNVzVFLUagbvVaOwR23csWSLDTsAEI9JzaxMKvCNRwk3jFepiCovXbw+g0iyvJdp0+AJpC57ZupyxHeX9J2oz7im2UaHHqLa2qUZL6c4PNV/D2p0Bts4Tcnn3OFPL90RF/ao0tjiUFxM3ti8pRHOqRcZHcOgIhKiaLX nicolas@tchoum'
|
||||
|
||||
before(:all) do
|
||||
users = create_list(:user, 2)
|
||||
@user1 = users[0]
|
||||
@user2 = users[1]
|
||||
|
||||
@deploy_key = create(:gitolite_public_key, user: @user1, key_type: 1, title: 'foo1', key: DEPLOY_KEY)
|
||||
@user_key = create(:gitolite_public_key, user: @user1, key_type: 0, title: 'foo2', key: USER_KEY)
|
||||
end
|
||||
|
||||
|
||||
def build_deployment_credential(opts = {})
|
||||
build(:repository_deployment_credential, opts)
|
||||
end
|
||||
|
||||
|
||||
describe 'Valid RepositoryDeploymentCredential creation' do
|
||||
before(:each) do
|
||||
@deployment_credential = build_deployment_credential(user: @user1, gitolite_public_key: @deploy_key)
|
||||
end
|
||||
|
||||
subject { @deployment_credential }
|
||||
|
||||
## Relations
|
||||
it { should belong_to(:repository) }
|
||||
it { should belong_to(:gitolite_public_key) }
|
||||
it { should belong_to(:user) }
|
||||
|
||||
## Validations
|
||||
it { should be_valid }
|
||||
|
||||
it { should validate_presence_of(:repository_id) }
|
||||
it { should validate_presence_of(:gitolite_public_key_id) }
|
||||
it { should validate_presence_of(:user_id) }
|
||||
it { should validate_presence_of(:perm) }
|
||||
|
||||
it { should validate_inclusion_of(:perm).in_array(%w(R RW+)) }
|
||||
|
||||
## Attributes content
|
||||
it 'is a active credential' do
|
||||
expect(@deployment_credential.active?).to be true
|
||||
end
|
||||
|
||||
describe 'when active is false' do
|
||||
before { @deployment_credential.active = false }
|
||||
it 'shoud be inactive' do
|
||||
expect(@deployment_credential.active?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when key is not a deployment key' do
|
||||
it 'should not be valid' do
|
||||
expect(build_deployment_credential(user: @user1, gitolite_public_key: @user_key)).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user id is not the owner of deployment key' do
|
||||
it 'should not be valid' do
|
||||
expect(build_deployment_credential(user: @user2, gitolite_public_key: @user_key)).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
|
||||
describe RepositoryGitConfigKey::GitConfig do
|
||||
before(:each) do
|
||||
@git_config_key = build(:repository_git_config_key)
|
||||
end
|
||||
|
||||
subject { @git_config_key }
|
||||
|
||||
## Validations
|
||||
it { should be_valid }
|
||||
it { should validate_presence_of(:key) }
|
||||
it { should validate_uniqueness_of(:key).scoped_to(:repository_id) }
|
||||
it { should allow_value('hookfoo.foo', 'hookfoo.foo.bar').for(:key) }
|
||||
it { should_not allow_value('hookfoo').for(:key) }
|
||||
|
||||
context 'when key is updated' do
|
||||
before do
|
||||
@git_config_key.save
|
||||
@git_config_key.key = 'hookbar.foo'
|
||||
@git_config_key.save
|
||||
end
|
||||
|
||||
it { should be_valid }
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
|
||||
describe RepositoryGitConfigKey::Option do
|
||||
before(:each) do
|
||||
@git_config_key = build(:repository_git_option_key)
|
||||
end
|
||||
|
||||
subject { @git_config_key }
|
||||
|
||||
## Validations
|
||||
it { should be_valid }
|
||||
it { should validate_presence_of(:key) }
|
||||
it { should validate_uniqueness_of(:key).scoped_to(:repository_id) }
|
||||
it { should allow_value('hookfoo', 'hookfoo.foo', 'hookfoo.foo.bar').for(:key) }
|
||||
|
||||
|
||||
context 'when key is updated' do
|
||||
before do
|
||||
@git_config_key.save
|
||||
@git_config_key.key = 'hookbar.foo'
|
||||
@git_config_key.save
|
||||
end
|
||||
|
||||
it { should be_valid }
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe RepositoryGitConfigKey do
|
||||
|
||||
let(:git_config_key) { build(:repository_git_config_key_base) }
|
||||
|
||||
subject { git_config_key }
|
||||
|
||||
## Relations
|
||||
it { should belong_to(:repository) }
|
||||
|
||||
## Validations
|
||||
it { should validate_presence_of(:repository_id) }
|
||||
it { should validate_presence_of(:value) }
|
||||
end
|
|
@ -0,0 +1,78 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe RepositoryGitExtra do
|
||||
|
||||
let(:git_extra) { build(:repository_git_extra) }
|
||||
|
||||
subject { git_extra }
|
||||
|
||||
## Relations
|
||||
it { should belong_to(:repository) }
|
||||
|
||||
## Validations
|
||||
it { should be_valid }
|
||||
|
||||
it { should validate_presence_of(:repository_id) }
|
||||
it { should validate_presence_of(:default_branch) }
|
||||
it { should validate_presence_of(:key) }
|
||||
|
||||
it { should validate_uniqueness_of(:repository_id) }
|
||||
|
||||
## Serializations
|
||||
# it { should serialize(:urls_order) }
|
||||
|
||||
|
||||
describe '#git_daemon' do
|
||||
it 'should return the value for git_daemon' do
|
||||
expect(git_extra.git_daemon).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#git_http' do
|
||||
it 'should return the value for git_http' do
|
||||
expect(git_extra.git_http).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#git_https' do
|
||||
it 'should return the value for git_https' do
|
||||
expect(git_extra.git_https).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#git_go' do
|
||||
it 'should return the value for git_go' do
|
||||
expect(git_extra.git_go).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#git_ssh' do
|
||||
it 'should return the value for git_ssh' do
|
||||
expect(git_extra.git_ssh).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#git_notify' do
|
||||
it 'should return the value for git_notify' do
|
||||
expect(git_extra.git_notify).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#default_branch' do
|
||||
it 'should return the value for default_branch' do
|
||||
expect(git_extra.default_branch).to eq 'master'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#protected_branch' do
|
||||
it 'should return the value for protected_branch' do
|
||||
expect(git_extra.protected_branch).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#key' do
|
||||
it 'should return the value for key' do
|
||||
expect(git_extra.key).to match /\A[a-zA-Z0-9]+\z/
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,165 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe RepositoryMirror do
|
||||
|
||||
VALID_URLS = [
|
||||
'ssh://user@host.xz:2222/path/to/repo.git',
|
||||
'ssh://user@host.xz/path/to/repo.git',
|
||||
'ssh://user-name@long.host-domain.xz/path.git',
|
||||
'ssh://host.xz:2222/path/to/repo.git',
|
||||
'ssh://host.xz/path/to/repo.git',
|
||||
'ssh://user@host.xz/path/to/repo.git',
|
||||
'ssh://host.xz/path/to/repo.git',
|
||||
'ssh://user@host.xz/~user/path/to/repo.git',
|
||||
'ssh://host.xz/~user/path/to/repo.git',
|
||||
'ssh://user@host.xz/~/path/to/repo.git',
|
||||
'ssh://host.xz/~/path/to/repo.git',
|
||||
'ssh://host.xz/~/path.to/repo.git'
|
||||
]
|
||||
|
||||
|
||||
def build_mirror(opts = {})
|
||||
build(:repository_mirror, opts)
|
||||
end
|
||||
|
||||
|
||||
def expect_invalid_refspec(refspec)
|
||||
expect(build_mirror(push_mode: 1, explicit_refspec: refspec)).not_to be_valid
|
||||
end
|
||||
|
||||
|
||||
def expect_valid_refspec(refspec)
|
||||
expect(build_mirror(push_mode: 1, explicit_refspec: refspec)).to be_valid
|
||||
end
|
||||
|
||||
|
||||
describe 'Valid RepositoryMirror creation' do
|
||||
before(:each) do
|
||||
@mirror = build(:repository_mirror)
|
||||
end
|
||||
|
||||
subject { @mirror }
|
||||
|
||||
## Relations
|
||||
it { should belong_to(:repository) }
|
||||
|
||||
## Validations
|
||||
it { should be_valid }
|
||||
|
||||
it { should validate_presence_of(:repository_id) }
|
||||
it { should validate_presence_of(:url) }
|
||||
it { should validate_presence_of(:push_mode) }
|
||||
|
||||
it { should validate_uniqueness_of(:url).scoped_to(:repository_id) }
|
||||
|
||||
it { should allow_value(*VALID_URLS).for(:url) }
|
||||
|
||||
it { should validate_numericality_of(:push_mode) }
|
||||
|
||||
it { should validate_inclusion_of(:push_mode).in_array(%w(0 1 2)) }
|
||||
|
||||
## Attributes content
|
||||
it { expect(@mirror.active).to be true }
|
||||
it { expect(@mirror.include_all_branches).to be false }
|
||||
it { expect(@mirror.include_all_tags).to be false }
|
||||
it { expect(@mirror.explicit_refspec).to eq '' }
|
||||
it { expect(@mirror.push_mode).to eq 0 }
|
||||
it { expect(@mirror.push_mode).to be_a(Integer) }
|
||||
|
||||
## Test changes
|
||||
describe 'when active is true' do
|
||||
before { @mirror.active = true }
|
||||
it 'shoud be active' do
|
||||
expect(@mirror.active).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when active is false' do
|
||||
before { @mirror.active = false }
|
||||
it 'should be inactive' do
|
||||
expect(@mirror.active).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'it should accept different refspec format' do
|
||||
it 'should accept <name>' do
|
||||
expect_valid_refspec 'devel'
|
||||
end
|
||||
|
||||
it 'should accept a branch path' do
|
||||
expect_valid_refspec 'refs/branches/dev'
|
||||
end
|
||||
|
||||
it 'should accept the update param (+)' do
|
||||
expect_valid_refspec '+refs/branches/dev'
|
||||
end
|
||||
|
||||
it 'should accept the wildcard param (*)' do
|
||||
expect_valid_refspec '+refs/branches/*'
|
||||
end
|
||||
|
||||
it 'should accept a destination' do
|
||||
expect_valid_refspec '+refs/branches/*:refs/branches/*'
|
||||
expect_valid_refspec '+refs/heads/experiment:refs/remotes/origin/experiment'
|
||||
expect_valid_refspec '+devel:devel'
|
||||
expect_valid_refspec '+devel:devel/*'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe 'Invalid Mirror creation' do
|
||||
## Test presence conflicts
|
||||
it 'is invalid when include_all_branches && include_all_tags' do
|
||||
expect(build_mirror(push_mode: 1, include_all_branches: true, include_all_tags: true)).not_to be_valid
|
||||
end
|
||||
|
||||
it 'is invalid when include_all_branches && explicit_refspec' do
|
||||
expect(build_mirror(push_mode: 1, include_all_branches: true, explicit_refspec: 'devel')).not_to be_valid
|
||||
end
|
||||
|
||||
## Validate push mode : forced
|
||||
it 'is invalid when push_mode forced without params' do
|
||||
expect(build_mirror(push_mode: 1)).not_to be_valid
|
||||
end
|
||||
|
||||
## Validate push mode : fast_forward
|
||||
it 'is invalid when push_mode fast_forward without params' do
|
||||
expect(build_mirror(push_mode: 2)).not_to be_valid
|
||||
end
|
||||
|
||||
## Validate explicit_refspec
|
||||
it 'should check that <source> and <target> are well formated' do
|
||||
expect_invalid_refspec ':'
|
||||
expect_invalid_refspec ':devel'
|
||||
expect_invalid_refspec ':/devel'
|
||||
expect_invalid_refspec '/devel:/devel'
|
||||
expect_invalid_refspec 'devel:/devel'
|
||||
expect_invalid_refspec '/devel:devel'
|
||||
expect_invalid_refspec '/devel:devel/*'
|
||||
expect_invalid_refspec '+refs/branches*:refs/branches*'
|
||||
expect_invalid_refspec '+refs/branches*:refs/branches/*'
|
||||
expect_invalid_refspec '+refs/branches/*:refs/branches'
|
||||
expect_invalid_refspec '+refs/branches/*:refs/branches/'
|
||||
expect_invalid_refspec '+refs/branches:refs/branches/*'
|
||||
expect_invalid_refspec '+refs/branches/:refs/branches/*'
|
||||
expect_invalid_refspec '+refs/branches/v[0-9]:refs/branches/v[0-9]'
|
||||
expect_invalid_refspec '+refs/branches/v[0-9]/refs/branches/v[0-9]'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'when many mirror are saved' do
|
||||
before do
|
||||
create(:repository_mirror, active: true)
|
||||
create(:repository_mirror, active: true)
|
||||
create(:repository_mirror, active: false)
|
||||
create(:repository_mirror, active: false)
|
||||
end
|
||||
|
||||
it { expect(RepositoryMirror.active.length).to be == 3 }
|
||||
it { expect(RepositoryMirror.inactive.length).to be == 2 }
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,51 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe RepositoryPostReceiveUrl do
|
||||
|
||||
let(:post_receive_url) { build(:repository_post_receive_url) }
|
||||
|
||||
subject { post_receive_url }
|
||||
|
||||
## Relations
|
||||
it { should belong_to(:repository) }
|
||||
|
||||
## Validations
|
||||
it { should be_valid }
|
||||
|
||||
it { should validate_presence_of(:repository_id) }
|
||||
it { should validate_presence_of(:url) }
|
||||
it { should validate_presence_of(:mode) }
|
||||
|
||||
it { should validate_uniqueness_of(:url).scoped_to(:repository_id) }
|
||||
|
||||
it { should validate_inclusion_of(:mode).in_array([:github, :get]) }
|
||||
|
||||
it { should allow_value('http://foo.com', 'https://bar.com/baz').for(:url) }
|
||||
|
||||
## Serializations
|
||||
# it { should serialize(:triggers) }
|
||||
|
||||
## Attributes content
|
||||
it { expect(post_receive_url.active).to be true }
|
||||
it { expect(post_receive_url.mode).to eq :github }
|
||||
it { expect(post_receive_url.use_triggers).to be false }
|
||||
it { expect(post_receive_url.triggers).to be_a(Array) }
|
||||
it { expect(post_receive_url.split_payloads).to be false }
|
||||
|
||||
|
||||
# describe '.active' do
|
||||
# it 'should return an array of active post_receive_urls' do
|
||||
# expect(RepositoryPostReceiveUrl).to receive(:where).with(active: true)
|
||||
# RepositoryPostReceiveUrl.active
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
# describe '.inactive' do
|
||||
# it 'should return an array of inactive post_receive_urls' do
|
||||
# expect(RepositoryPostReceiveUrl).to receive(:where).with(active: false)
|
||||
# RepositoryPostReceiveUrl.inactive
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
|
@ -0,0 +1,52 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe RepositoryProtectedBranche do
|
||||
|
||||
let(:protected_branch) { build(:repository_protected_branche) }
|
||||
|
||||
subject { protected_branch }
|
||||
|
||||
## Relations
|
||||
it { should belong_to(:repository) }
|
||||
it { should have_many(:protected_branches_members).with_foreign_key(:protected_branch_id).dependent(:destroy) }
|
||||
it { should have_many(:members).through(:protected_branches_members) }
|
||||
|
||||
## Validations
|
||||
it { should be_valid }
|
||||
|
||||
it { should validate_presence_of(:repository_id) }
|
||||
it { should validate_presence_of(:path) }
|
||||
it { should validate_presence_of(:permissions) }
|
||||
|
||||
it { should validate_uniqueness_of(:path).scoped_to([:permissions, :repository_id]) }
|
||||
|
||||
it { should validate_inclusion_of(:permissions).in_array RepositoryProtectedBranche::VALID_PERMS }
|
||||
|
||||
describe '#users' do
|
||||
it 'should return an array of users' do
|
||||
user = build(:user)
|
||||
group = build(:group)
|
||||
expect(protected_branch).to receive(:members).and_return([user, user, group])
|
||||
expect(protected_branch.users).to eq [user]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#groups' do
|
||||
it 'should return an array of groups' do
|
||||
user = build(:user)
|
||||
group = build(:group)
|
||||
expect(protected_branch).to receive(:members).and_return([group, user, group])
|
||||
expect(protected_branch.groups).to eq [group]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#allowed_users' do
|
||||
it 'should return an array of gitolite identifiers' do
|
||||
user1 = build(:user)
|
||||
user2 = build(:user)
|
||||
expect(protected_branch).to receive(:users).and_return([user1, user2])
|
||||
expect(protected_branch.allowed_users).to eq [user1.gitolite_identifier, user2.gitolite_identifier]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,301 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe Repository::Xitolite do
|
||||
|
||||
GIT_USER = 'git'
|
||||
|
||||
before(:all) do
|
||||
Setting.plugin_redmine_git_hosting[:gitolite_redmine_storage_dir] = 'redmine/'
|
||||
Setting.plugin_redmine_git_hosting[:http_server_subdir] = 'git/'
|
||||
User.current = nil
|
||||
|
||||
@project_parent = FactoryBot.create(:project, identifier: 'project-parent')
|
||||
@project_child = FactoryBot.create(:project, identifier: 'project-child', parent_id: @project_parent.id, is_public: false)
|
||||
end
|
||||
|
||||
|
||||
describe 'common_tests : fast tests' do
|
||||
before(:each) do
|
||||
Setting.plugin_redmine_git_hosting[:hierarchical_organisation] = 'true'
|
||||
Setting.plugin_redmine_git_hosting[:unique_repo_identifier] = 'false'
|
||||
|
||||
@repository_1 = build_git_repository(project: @project_child, is_default: true)
|
||||
@repository_1.valid?
|
||||
@repository_1.build_extra(default_branch: 'master', key: RedmineGitHosting::Utils::Crypto.generate_secret(64), git_https: true)
|
||||
end
|
||||
|
||||
subject { @repository_1 }
|
||||
|
||||
it { should be_valid }
|
||||
|
||||
## Relations
|
||||
it { should have_many(:mirrors) }
|
||||
it { should have_many(:post_receive_urls) }
|
||||
it { should have_many(:deployment_credentials) }
|
||||
it { should have_many(:git_config_keys) }
|
||||
it { should have_many(:protected_branches) }
|
||||
|
||||
it { should have_one(:extra) }
|
||||
|
||||
## Attributes
|
||||
it { expect(@repository_1.report_last_commit).to be true }
|
||||
it { expect(@repository_1.extra_report_last_commit).to be true }
|
||||
it { expect(@repository_1.git_default_branch).to eq 'master' }
|
||||
it { expect(@repository_1.gitolite_hook_key).to match /\A[a-zA-Z0-9]+\z/ }
|
||||
it { expect(@repository_1.git_daemon_enabled?).to be true }
|
||||
it { expect(@repository_1.git_annex_enabled?).to be false }
|
||||
it { expect(@repository_1.git_notification_enabled?).to be true }
|
||||
it { expect(@repository_1.smart_http_enabled?).to be true }
|
||||
it { expect(@repository_1.https_access_enabled?).to be true }
|
||||
it { expect(@repository_1.http_access_enabled?).to be false }
|
||||
it { expect(@repository_1.only_https_access_enabled?).to be true }
|
||||
it { expect(@repository_1.only_http_access_enabled?).to be false }
|
||||
it { expect(@repository_1.protected_branches_enabled?).to be false }
|
||||
it { expect(@repository_1.public_project?).to be false }
|
||||
it { expect(@repository_1.public_repo?).to be false }
|
||||
it { expect(@repository_1.urls_order).to eq [] }
|
||||
|
||||
|
||||
it 'should not allow identifier gitolite-admin' do
|
||||
expect(build_git_repository(project: @project_parent, identifier: 'gitolite-admin')).to be_invalid
|
||||
end
|
||||
|
||||
|
||||
describe '#exists_in_gitolite?' do
|
||||
it 'should check if repository exists on Gitolite side' do
|
||||
expect(RedmineGitHosting::Commands).to receive(:sudo_dir_exists?).with('repositories/redmine/project-parent/project-child.git')
|
||||
@repository_1.exists_in_gitolite?
|
||||
end
|
||||
end
|
||||
|
||||
describe '#empty_in_gitolite?' do
|
||||
it 'should check if repository is empty on Gitolite side' do
|
||||
expect(RedmineGitHosting::Commands).to receive(:sudo_repository_empty?).with('repositories/redmine/project-parent/project-child.git')
|
||||
@repository_1.empty_in_gitolite?
|
||||
end
|
||||
end
|
||||
|
||||
describe '#git_objects_count' do
|
||||
it 'should return repository objects count' do
|
||||
expect(RedmineGitHosting::Commands).to receive(:sudo_git_objects_count).with('repositories/redmine/project-parent/project-child.git/objects')
|
||||
@repository_1.git_objects_count
|
||||
end
|
||||
end
|
||||
|
||||
describe '#data_for_destruction' do
|
||||
it 'should return a hash of data' do
|
||||
expect(@repository_1.data_for_destruction).to eq({
|
||||
delete_repository: true,
|
||||
git_cache_id: 'project-child',
|
||||
repo_name: 'redmine/project-parent/project-child',
|
||||
repo_path: '/home/git/repositories/redmine/project-parent/project-child.git',
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe '#empty?' do
|
||||
it 'should check if repository is empty from Redmine point of view' do
|
||||
expect(@repository_1.empty?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#empty_cache!' do
|
||||
it 'should flush the repository git cache' do
|
||||
expect(RedmineGitHosting::Cache).to receive(:clear_cache_for_repository).with('project-child')
|
||||
@repository_1.empty_cache!
|
||||
end
|
||||
end
|
||||
|
||||
describe '#available_urls' do
|
||||
context 'with no option' do
|
||||
my_hash = {}
|
||||
|
||||
it 'should return an empty Hash' do
|
||||
@repository_1.extra[:git_daemon] = false
|
||||
@repository_1.extra[:git_http] = false
|
||||
@repository_1.extra[:git_https] = false
|
||||
@repository_1.extra[:git_go] = false
|
||||
@repository_1.extra[:git_ssh] = false
|
||||
expect(@repository_1.available_urls).to eq my_hash
|
||||
end
|
||||
end
|
||||
|
||||
context 'with all options' do
|
||||
my_hash = {
|
||||
ssh: { url: "ssh://#{GIT_USER}@localhost/redmine/project-parent/project-child.git", committer: 'true' },
|
||||
https: { url: 'https://redmine-test-user@localhost/git/project-parent/project-child.git', committer: 'true' },
|
||||
http: { url: 'http://redmine-test-user@localhost/git/project-parent/project-child.git', committer: 'false' },
|
||||
go: { url: 'localhost/go/project-parent/project-child', committer: 'false' },
|
||||
git: { url: 'git://localhost/redmine/project-parent/project-child.git', committer: 'false' }
|
||||
}
|
||||
|
||||
it 'should return a Hash of Git url' do
|
||||
@user = create_user_with_permissions(@project_child, login: 'redmine-test-user')
|
||||
User.current = @user
|
||||
@project_child.is_public = true
|
||||
@repository_1.extra[:git_daemon] = true
|
||||
@repository_1.extra[:git_http] = true
|
||||
@repository_1.extra[:git_https] = true
|
||||
@repository_1.extra[:git_go] = true
|
||||
@repository_1.extra[:git_ssh] = true
|
||||
@repository_1.extra.save
|
||||
expect(@repository_1.available_urls).to eq my_hash
|
||||
end
|
||||
end
|
||||
|
||||
context 'with git daemon' do
|
||||
my_hash = { git: { url: 'git://localhost/redmine/project-parent/project-child.git', committer: 'false' } }
|
||||
|
||||
it 'should return a Hash of Git url' do
|
||||
User.current = nil
|
||||
@project_child.is_public = true
|
||||
@repository_1.extra[:git_daemon] = true
|
||||
@repository_1.extra[:git_http] = false
|
||||
@repository_1.extra[:git_https] = false
|
||||
@repository_1.extra[:git_go] = false
|
||||
@repository_1.extra[:git_ssh] = false
|
||||
@repository_1.extra.save
|
||||
expect(@repository_1.available_urls).to eq my_hash
|
||||
end
|
||||
end
|
||||
|
||||
context 'with ssh' do
|
||||
my_hash = { ssh: { url: "ssh://#{GIT_USER}@localhost/redmine/project-parent/project-child.git", committer: 'true' } }
|
||||
|
||||
it 'should return a Hash of Git url' do
|
||||
@user = create_user_with_permissions(@project_child, login: 'redmine-test-user')
|
||||
User.current = @user
|
||||
@repository_1.extra[:git_daemon] = false
|
||||
@repository_1.extra[:git_http] = false
|
||||
@repository_1.extra[:git_https] = false
|
||||
@repository_1.extra[:git_go] = false
|
||||
@repository_1.extra[:git_ssh] = true
|
||||
@repository_1.extra.save
|
||||
expect(@repository_1.available_urls).to eq my_hash
|
||||
end
|
||||
end
|
||||
|
||||
context 'with http' do
|
||||
my_hash = { http: { url: 'http://localhost/git/project-parent/project-child.git', committer: 'false' } }
|
||||
|
||||
it 'should return a Hash of Git url' do
|
||||
User.current = nil
|
||||
@project_child.is_public = false
|
||||
@repository_1.extra[:git_daemon] = false
|
||||
@repository_1.extra[:git_http] = true
|
||||
@repository_1.extra[:git_https] = false
|
||||
@repository_1.extra[:git_go] = false
|
||||
@repository_1.extra[:git_ssh] = false
|
||||
@repository_1.extra.save
|
||||
expect(@repository_1.available_urls).to eq my_hash
|
||||
end
|
||||
end
|
||||
|
||||
context 'with https' do
|
||||
my_hash = { https: { url: 'https://localhost/git/project-parent/project-child.git', committer: 'false' } }
|
||||
|
||||
it 'should return a Hash of Git url' do
|
||||
User.current = nil
|
||||
@project_child.is_public = false
|
||||
@repository_1.extra[:git_daemon] = false
|
||||
@repository_1.extra[:git_http] = false
|
||||
@repository_1.extra[:git_https] = true
|
||||
@repository_1.extra[:git_go] = false
|
||||
@repository_1.extra[:git_ssh] = false
|
||||
@repository_1.extra.save
|
||||
expect(@repository_1.available_urls).to eq my_hash
|
||||
end
|
||||
end
|
||||
|
||||
context 'with http and https' do
|
||||
my_hash = {
|
||||
https: { url: 'https://localhost/git/project-parent/project-child.git', committer: 'false' },
|
||||
http: { url: 'http://localhost/git/project-parent/project-child.git', committer: 'false' }
|
||||
}
|
||||
|
||||
it 'should return a Hash of Git url' do
|
||||
User.current = nil
|
||||
@project_child.is_public = false
|
||||
@repository_1.extra[:git_daemon] = false
|
||||
@repository_1.extra[:git_http] = true
|
||||
@repository_1.extra[:git_https] = true
|
||||
@repository_1.extra[:git_go] = false
|
||||
@repository_1.extra[:git_ssh] = false
|
||||
@repository_1.extra.save
|
||||
expect(@repository_1.available_urls).to eq my_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'Repository::Xitolite class' do
|
||||
it { expect(Repository::Xitolite).to respond_to(:repo_ident_unique?) }
|
||||
it { expect(Repository::Xitolite).to respond_to(:have_duplicated_identifier?) }
|
||||
it { expect(Repository::Xitolite).to respond_to(:repo_path_to_git_cache_id) }
|
||||
it { expect(Repository::Xitolite).to respond_to(:find_by_path) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'common_tests : long tests' do
|
||||
before do
|
||||
Setting.plugin_redmine_git_hosting[:hierarchical_organisation] = 'true'
|
||||
Setting.plugin_redmine_git_hosting[:unique_repo_identifier] = 'false'
|
||||
|
||||
@repository_1 = create_git_repository(project: @project_child, is_default: true)
|
||||
extra = @repository_1.build_extra(default_branch: 'master', key: RedmineGitHosting::Utils::Crypto.generate_secret(64))
|
||||
extra.save!
|
||||
|
||||
@repository_2 = create_git_repository(project: @project_child, identifier: 'repo-test')
|
||||
end
|
||||
|
||||
context 'when blank identifier' do
|
||||
it 'should not allow identifier changes' do
|
||||
@repository_1.identifier = 'new_repo'
|
||||
expect(@repository_1).to be_invalid
|
||||
expect(@repository_1.identifier).to eq 'new_repo'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when non blank identifier' do
|
||||
it 'should not allow identifier changes' do
|
||||
@repository_2.identifier = 'new_repo2'
|
||||
expect(@repository_2).to be_valid
|
||||
expect(@repository_2.identifier).to eq 'repo-test'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'Test uniqueness' do
|
||||
context 'when blank identifier is already taken by a repository' do
|
||||
it { expect(build_git_repository(project: @project_child, identifier: '')).to be_invalid }
|
||||
end
|
||||
|
||||
context 'when set as default and blank identifier is already taken by a repository' do
|
||||
it { expect(build_git_repository(project: @project_child, identifier: '', is_default: true)).to be_invalid }
|
||||
end
|
||||
|
||||
context 'when identifier is already taken by a project' do
|
||||
it { expect(build_git_repository(project: @project_child, identifier: 'project-child')).to be_invalid }
|
||||
end
|
||||
|
||||
context 'when identifier is already taken by a repository with same project' do
|
||||
it { expect(build_git_repository(project: @project_child, identifier: 'repo-test')).to be_invalid }
|
||||
end
|
||||
|
||||
context 'when identifier are not unique' do
|
||||
it { expect(build_git_repository(project: @project_parent, identifier: 'repo-test')).to be_valid }
|
||||
end
|
||||
|
||||
context 'when identifier are unique' do
|
||||
it 'should refuse duplicated identifier' do
|
||||
Setting.plugin_redmine_git_hosting[:unique_repo_identifier] = 'true'
|
||||
expect(build_git_repository(project: @project_parent, identifier: 'repo-test')).to be_invalid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include_context 'flat_organisation'
|
||||
include_context 'hierarchical_organisation'
|
||||
end
|
15
plugins/redmine_git_hosting/spec/models/setting_spec.rb
Normal file
15
plugins/redmine_git_hosting/spec/models/setting_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe Setting do
|
||||
before do
|
||||
RedmineGitHosting::Config.reload_from_file!
|
||||
@settings = Setting.plugin_redmine_git_hosting
|
||||
@default_settings = Redmine::Plugin.find('redmine_git_hosting').settings[:default]
|
||||
end
|
||||
|
||||
subject { @settings }
|
||||
|
||||
it { should be_an_instance_of(Hash) }
|
||||
|
||||
# it { expect(@settings).to eq @default_settings }
|
||||
end
|
15
plugins/redmine_git_hosting/spec/models/user_spec.rb
Normal file
15
plugins/redmine_git_hosting/spec/models/user_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../spec_helper', __dir__)
|
||||
|
||||
describe User do
|
||||
let(:user) { build(:user) }
|
||||
|
||||
it { is_expected.to have_many(:protected_branches_members).dependent(:destroy) }
|
||||
it { is_expected.to have_many(:protected_branches).through(:protected_branches_members) }
|
||||
|
||||
describe '#gitolite_identifier' do
|
||||
it 'return the gitolite_identifier' do
|
||||
user = build(:user, login: 'adam.30', id: 12)
|
||||
expect(user.gitolite_identifier).to eq 'redmine_adam_30_12'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue