Commit 3d82f20d authored by Stan Hu's avatar Stan Hu

Strip whitespace around GitHub personal access tokens

Some browsers insert a trailing whitespace after pasting the
token into the field. This should help reduce confusion.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/46588
parent c09de611
......@@ -20,7 +20,7 @@ class Import::GithubController < Import::BaseController
end
def personal_access_token
session[access_token_key] = params[:personal_access_token]
session[access_token_key] = params[:personal_access_token]&.strip
redirect_to status_import_url
end
......
---
title: Strip whitespace around GitHub personal access tokens
merge_request: 22432
author:
type: fixed
......@@ -22,6 +22,18 @@ shared_examples 'a GitHub-ish import controller: POST personal_access_token' do
expect(session[:"#{provider}_access_token"]).to eq(token)
expect(controller).to redirect_to(status_import_url)
end
it "strips access token with spaces" do
token = 'asdfasdf9876'
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
.to receive(:user).and_return(true)
post :personal_access_token, personal_access_token: " #{token} "
expect(session[:"#{provider}_access_token"]).to eq(token)
expect(controller).to redirect_to(status_import_url)
end
end
shared_examples 'a GitHub-ish import controller: GET new' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment