提交 1e4477b5 编写于 作者: M Mislav Marohnić

Fix reusing old OAuth tokens stored in Authorizations API

For people who are using hub for a longer time now, hub has stored an OAuth
token in Authorizations API with a `note_url` value that is now outdated
(e.g. "http://defunkt.io/hub/"). The newer `oauth_app_url` doesn't match
that, so the token is not reused. Hub tries to create a new OAuth token
with a `note` that says "hub" which fails with a 422 because it already
exists.

This fixes reusing old OAuth tokens even if the `note_url` doesn't match
anymore. Any key with `note` that says "hub" will get reused.

Fixes #496
上级 0f44f3e3
......@@ -58,6 +58,36 @@ Feature: OAuth authentication
And the exit status should be 0
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
Scenario: Re-use existing authorization with an old URL
Given the GitHub API server:
"""
require 'rack/auth/basic'
get('/authorizations') {
auth = Rack::Auth::Basic::Request.new(env)
halt 401 unless auth.credentials == %w[mislav kitty]
json [
{:token => 'OTOKEN', :note => 'hub', :note_url => 'http://defunkt.io/hub/'}
]
}
post('/authorizations') {
status 422
json :message => "Validation Failed",
:errors => [{:resource => "OauthAccess", :code => "already_exists", :field => "description"}]
}
get('/user') {
json :login => 'mislav'
}
post('/user/repos') {
json :full_name => 'mislav/dotfiles'
}
"""
When I run `hub create` interactively
When I type "mislav"
And I type "kitty"
Then the output should contain "github.com password for mislav (never stored):"
And the exit status should be 0
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
Scenario: Credentials from GITHUB_USER & GITHUB_PASSWORD
Given the GitHub API server:
"""
......
......@@ -326,7 +326,7 @@ module Hub
end
end
if found = res.data.find {|auth| auth['note_url'] == oauth_app_url }
if found = res.data.find {|auth| auth['note'] == 'hub' || auth['note_url'] == oauth_app_url }
found['token']
else
# create a new authorization
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册