2018-10-09 02:01:08 -04:00
|
|
|
# encoding: utf-8
|
2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
2018-10-09 02:01:08 -04:00
|
|
|
|
|
|
|
require 'theme_store/git_importer'
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe ThemeStore::GitImporter do
|
2022-07-27 06:21:10 -04:00
|
|
|
describe "#import" do
|
2018-10-09 02:01:08 -04:00
|
|
|
let(:url) { "https://github.com/example/example.git" }
|
2019-06-04 05:28:36 -04:00
|
|
|
let(:trailing_slash_url) { "https://github.com/example/example/" }
|
2018-10-09 02:01:08 -04:00
|
|
|
let(:ssh_url) { "git@github.com:example/example.git" }
|
|
|
|
let(:branch) { "dev" }
|
|
|
|
|
|
|
|
before do
|
|
|
|
hex = "xxx"
|
|
|
|
SecureRandom.stubs(:hex).returns(hex)
|
2022-11-01 12:33:17 -04:00
|
|
|
FinalDestination.stubs(:resolve).with(url).returns(URI.parse(url))
|
|
|
|
FinalDestination::SSRFDetector.stubs(:lookup_and_filter_ips).with("github.com").returns(["192.0.2.100"])
|
2018-10-09 02:01:08 -04:00
|
|
|
@temp_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{hex}"
|
|
|
|
@ssh_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_ssh_#{hex}"
|
|
|
|
end
|
|
|
|
|
2022-11-01 12:33:17 -04:00
|
|
|
it "imports http urls" do
|
|
|
|
Discourse::Utils
|
|
|
|
.expects(:execute_command)
|
|
|
|
.with(
|
|
|
|
{ "GIT_TERMINAL_PROMPT" => "0" },
|
2022-11-02 05:47:59 -04:00
|
|
|
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, timeout: 20
|
2022-11-01 12:33:17 -04:00
|
|
|
)
|
2018-10-09 02:01:08 -04:00
|
|
|
|
|
|
|
importer = ThemeStore::GitImporter.new(url)
|
|
|
|
importer.import!
|
|
|
|
end
|
|
|
|
|
2022-11-01 12:33:17 -04:00
|
|
|
it "imports when the url has a trailing slash" do
|
|
|
|
Discourse::Utils
|
|
|
|
.expects(:execute_command)
|
|
|
|
.with(
|
|
|
|
{ "GIT_TERMINAL_PROMPT" => "0" },
|
2022-11-02 05:47:59 -04:00
|
|
|
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "https://github.com/example/example.git", @temp_folder, timeout: 20
|
2022-11-01 12:33:17 -04:00
|
|
|
)
|
2019-06-04 05:28:36 -04:00
|
|
|
|
|
|
|
importer = ThemeStore::GitImporter.new(trailing_slash_url)
|
|
|
|
importer.import!
|
|
|
|
end
|
|
|
|
|
2022-11-01 12:33:17 -04:00
|
|
|
it "imports ssh urls" do
|
|
|
|
Discourse::Utils
|
|
|
|
.expects(:execute_command)
|
|
|
|
.with(
|
|
|
|
{ "GIT_SSH_COMMAND" => "ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no" },
|
2022-11-02 05:47:59 -04:00
|
|
|
"git", "clone", "ssh://git@github.com/example/example.git", @temp_folder, timeout: 20
|
2022-11-01 12:33:17 -04:00
|
|
|
)
|
2018-10-09 02:01:08 -04:00
|
|
|
|
|
|
|
importer = ThemeStore::GitImporter.new(ssh_url, private_key: "private_key")
|
|
|
|
importer.import!
|
|
|
|
end
|
|
|
|
|
2022-11-01 12:33:17 -04:00
|
|
|
it "imports http urls with a particular branch" do
|
|
|
|
Discourse::Utils
|
|
|
|
.expects(:execute_command)
|
|
|
|
.with(
|
|
|
|
{ "GIT_TERMINAL_PROMPT" => "0" },
|
2022-11-15 14:23:57 -05:00
|
|
|
"git", "-c", "http.followRedirects=false", "-c", "http.curloptResolve=github.com:443:192.0.2.100", "clone", "--single-branch", "-b", branch, "https://github.com/example/example.git", @temp_folder, timeout: 20
|
2022-11-01 12:33:17 -04:00
|
|
|
)
|
2018-10-09 02:01:08 -04:00
|
|
|
|
|
|
|
importer = ThemeStore::GitImporter.new(url, branch: branch)
|
|
|
|
importer.import!
|
|
|
|
end
|
|
|
|
|
2022-11-01 12:33:17 -04:00
|
|
|
it "imports ssh urls with a particular branch" do
|
|
|
|
Discourse::Utils
|
|
|
|
.expects(:execute_command)
|
|
|
|
.with(
|
|
|
|
{ "GIT_SSH_COMMAND" => "ssh -i #{@ssh_folder}/id_rsa -o IdentitiesOnly=yes -o IdentityFile=#{@ssh_folder}/id_rsa -o StrictHostKeyChecking=no" },
|
2022-11-15 14:23:57 -05:00
|
|
|
"git", "clone", "--single-branch", "-b", branch, "ssh://git@github.com/example/example.git", @temp_folder, timeout: 20
|
2022-11-01 12:33:17 -04:00
|
|
|
)
|
2018-10-09 02:01:08 -04:00
|
|
|
|
|
|
|
importer = ThemeStore::GitImporter.new(ssh_url, private_key: "private_key", branch: branch)
|
|
|
|
importer.import!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|