2017-04-05 07:44:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-12 05:28:23 -04:00
|
|
|
describe DynamicPathValidator do
|
2017-04-05 09:41:00 -04:00
|
|
|
let(:validator) { described_class.new(attributes: [:path]) }
|
2017-04-10 13:27:19 -04:00
|
|
|
|
2017-05-30 11:05:52 -04:00
|
|
|
def expect_handles_invalid_utf8
|
|
|
|
expect { yield('\255invalid') }.to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.valid_user_path' do
|
|
|
|
it 'handles invalid utf8' do
|
|
|
|
expect(described_class.valid_user_path?("a\0weird\255path")).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.valid_group_path' do
|
|
|
|
it 'handles invalid utf8' do
|
|
|
|
expect(described_class.valid_group_path?("a\0weird\255path")).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.valid_project_path' do
|
|
|
|
it 'handles invalid utf8' do
|
|
|
|
expect(described_class.valid_project_path?("a\0weird\255path")).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
describe '#path_valid_for_record?' do
|
|
|
|
context 'for project' do
|
|
|
|
it 'calls valid_project_path?' do
|
|
|
|
project = build(:project, path: 'activity')
|
2017-05-02 05:48:54 -04:00
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
expect(described_class).to receive(:valid_project_path?).with(project.full_path).and_call_original
|
2017-05-02 05:48:54 -04:00
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
expect(validator.path_valid_for_record?(project, 'activity')).to be_truthy
|
2017-05-02 05:48:54 -04:00
|
|
|
end
|
2017-04-05 07:44:23 -04:00
|
|
|
end
|
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
context 'for group' do
|
2017-05-24 16:59:26 -04:00
|
|
|
it 'calls valid_group_path?' do
|
2017-05-19 20:46:40 -04:00
|
|
|
group = build(:group, :nested, path: 'activity')
|
2017-05-02 05:48:54 -04:00
|
|
|
|
2017-05-24 16:59:26 -04:00
|
|
|
expect(described_class).to receive(:valid_group_path?).with(group.full_path).and_call_original
|
2017-04-28 12:09:01 -04:00
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
expect(validator.path_valid_for_record?(group, 'activity')).to be_falsey
|
2017-04-18 10:27:11 -04:00
|
|
|
end
|
2017-04-05 07:44:23 -04:00
|
|
|
end
|
2017-04-05 09:41:00 -04:00
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
context 'for user' do
|
2017-05-24 16:59:26 -04:00
|
|
|
it 'calls valid_user_path?' do
|
2017-05-19 20:46:40 -04:00
|
|
|
user = build(:user, username: 'activity')
|
2017-04-11 09:51:33 -04:00
|
|
|
|
2017-05-24 16:59:26 -04:00
|
|
|
expect(described_class).to receive(:valid_user_path?).with(user.full_path).and_call_original
|
2017-04-11 09:51:33 -04:00
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
expect(validator.path_valid_for_record?(user, 'activity')).to be_truthy
|
|
|
|
end
|
2017-04-05 09:41:00 -04:00
|
|
|
end
|
2017-05-02 03:13:10 -04:00
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
context 'for user namespace' do
|
2017-05-24 16:59:26 -04:00
|
|
|
it 'calls valid_user_path?' do
|
2017-05-19 20:46:40 -04:00
|
|
|
user = create(:user, username: 'activity')
|
|
|
|
namespace = user.namespace
|
2017-05-02 04:32:31 -04:00
|
|
|
|
2017-05-24 16:59:26 -04:00
|
|
|
expect(described_class).to receive(:valid_user_path?).with(namespace.full_path).and_call_original
|
2017-05-02 04:32:31 -04:00
|
|
|
|
2017-05-19 20:46:40 -04:00
|
|
|
expect(validator.path_valid_for_record?(namespace, 'activity')).to be_truthy
|
|
|
|
end
|
2017-05-02 04:32:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#validates_each' do
|
|
|
|
it 'adds a message when the path is not in the correct format' do
|
|
|
|
group = build(:group)
|
|
|
|
|
|
|
|
validator.validate_each(group, :path, "Path with spaces, and comma's!")
|
|
|
|
|
2017-05-24 16:59:26 -04:00
|
|
|
expect(group.errors[:path]).to include(Gitlab::PathRegex.namespace_format_message)
|
2017-05-02 04:32:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds a message when the path is not in the correct format' do
|
|
|
|
group = build(:group, path: 'users')
|
|
|
|
|
|
|
|
validator.validate_each(group, :path, 'users')
|
|
|
|
|
|
|
|
expect(group.errors[:path]).to include('users is a reserved name')
|
|
|
|
end
|
|
|
|
end
|
2017-04-05 07:44:23 -04:00
|
|
|
end
|