提交 4248b84e 编写于 作者: M Mislav Marohnić

Friendlier error message when bad credentials were used

* In case of wrong password, "Bad credentials" will now show
* In case of a user trying to paste their Personal Access Token (which
  won't work as a substitute for password here), a message stating that
  you have to use your actual password will now show.
上级 4241bfa2
......@@ -127,7 +127,32 @@ Feature: OAuth authentication
When I run `hub create` interactively
When I type "mislav"
And I type "WRONG"
Then the stderr should contain "Error creating repository: Unauthorized (HTTP 401)"
Then the stderr should contain exactly:
"""
Error creating repository: Unauthorized (HTTP 401)
Bad credentials
"""
And the exit status should be 1
And the file "../home/.config/hub" should not exist
Scenario: Personal access token used instead of password
Given the GitHub API server:
"""
post('/authorizations') {
status 403
json :message => "This API can only be accessed with username and password Basic Auth"
}
"""
When I run `hub create` interactively
When I type "mislav"
And I type "PERSONALACCESSTOKEN"
Then the stderr should contain exactly:
"""
Error creating repository: Forbidden (HTTP 403)
This API can only be accessed with username and password Basic Auth
"""
And the exit status should be 1
And the file "../home/.config/hub" should not exist
......
......@@ -70,11 +70,7 @@ module Hub
require 'rack/auth/basic'
auth = Rack::Auth::Basic::Request.new(env)
if auth.credentials != expected
halt 401, json(
:message => "expected %p; got %p" % [
expected, auth.credentials
]
)
halt 401, json(:message => "Bad credentials")
end
end
......
......@@ -1157,8 +1157,7 @@ help
def display_api_exception(action, response)
$stderr.puts "Error #{action}: #{response.message.strip} (HTTP #{response.status})"
if 422 == response.status and response.error_message?
# display validation errors
if [401, 403, 422].include?(response.status) && response.error_message?
msg = response.error_message
msg = msg.join("\n") if msg.respond_to? :join
warn msg
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册