b4e2679437
Previously, the GitHub importer would only work if the site configured an OAuth2 provider were configured. Users attempting to import via a GitHub personal access token would see an Error 500 due to a failed redirection. We fix this by only doing the redirection if the provider has been configured and allowing users to see the new import page. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/38524
57 lines
1.6 KiB
Ruby
57 lines
1.6 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe Import::GithubController do
|
|
include ImportSpecHelper
|
|
|
|
let(:provider) { :github }
|
|
|
|
include_context 'a GitHub-ish import controller'
|
|
|
|
describe "GET new" do
|
|
it_behaves_like 'a GitHub-ish import controller: GET new'
|
|
|
|
it "redirects to GitHub for an access token if logged in with GitHub" do
|
|
allow(controller).to receive(:logged_in_with_provider?).and_return(true)
|
|
expect(controller).to receive(:go_to_provider_for_permissions)
|
|
|
|
get :new
|
|
end
|
|
|
|
it "prompts for an access token if GitHub not configured" do
|
|
allow(controller).to receive(:github_import_configured?).and_return(false)
|
|
expect(controller).not_to receive(:go_to_provider_for_permissions)
|
|
|
|
get :new
|
|
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
end
|
|
|
|
describe "GET callback" do
|
|
it "updates access token" do
|
|
token = "asdasd12345"
|
|
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
|
|
.to receive(:get_token).and_return(token)
|
|
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
|
|
.to receive(:github_options).and_return({})
|
|
stub_omniauth_provider('github')
|
|
|
|
get :callback
|
|
|
|
expect(session[:github_access_token]).to eq(token)
|
|
expect(controller).to redirect_to(status_import_github_url)
|
|
end
|
|
end
|
|
|
|
describe "POST personal_access_token" do
|
|
it_behaves_like 'a GitHub-ish import controller: POST personal_access_token'
|
|
end
|
|
|
|
describe "GET status" do
|
|
it_behaves_like 'a GitHub-ish import controller: GET status'
|
|
end
|
|
|
|
describe "POST create" do
|
|
it_behaves_like 'a GitHub-ish import controller: POST create'
|
|
end
|
|
end
|