Skip to content
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

Add support to Embedded Ansible for ssh user@host:path urls #19129

Merged
merged 1 commit into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/git_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GitRepository < ApplicationRecord

attr_reader :git_lock

validates :url, :format => URI.regexp(%w[http https file ssh]), :allow_nil => false
validates :url, :format => Regexp.union(URI.regexp(%w[http https file ssh]), /\A[-\w:.]+@.*:/), :allow_nil => false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should our custom regexp:

/\A[-\w:.]+@.*:/

Be a constant so that we can reference it else where? For parsing out user/pass/etc. later?


default_value_for :verify_ssl, OpenSSL::SSL::VERIFY_PEER
validates :verify_ssl, :inclusion => {:in => [OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER]}
Expand Down
32 changes: 27 additions & 5 deletions spec/models/git_repository_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
describe GitRepository do
it "no url" do
expect { FactoryBot.create(:git_repository, :url => nil) }.to raise_error(ActiveRecord::RecordInvalid)
end
describe "#url" do
it "missing" do
expect(FactoryBot.build(:git_repository, :url => nil)).to_not be_valid
end

it "invalid" do
expect(FactoryBot.build(:git_repository, :url => "abc")).to_not be_valid
end

it "invalid url" do
expect { FactoryBot.create(:git_repository, :url => "abc") }.to raise_error(ActiveRecord::RecordInvalid)
it "http" do
expect(FactoryBot.build(:git_repository, :url => "http://example.com/ManageIQ/manageiq.git")).to be_valid
end

it "https" do
expect(FactoryBot.build(:git_repository, :url => "https://example.com/ManageIQ/manageiq.git")).to be_valid
end

it "file" do
expect(FactoryBot.build(:git_repository, :url => "file:///home/foo/ManageIQ/manageiq")).to be_valid
end

it "ssh" do
expect(FactoryBot.build(:git_repository, :url => "ssh://example.com/ManageIQ/manageiq.git")).to be_valid
end

it "ssh user@host:path" do
expect(FactoryBot.build(:git_repository, :url => "[email protected]:ManageIQ/manageiq.git")).to be_valid
end
end

it "default dirname" do
Expand Down