Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix application requests for non dotcom hosts #851

Merged
merged 3 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

gem 'jruby-openssl', :platforms => :jruby
gem 'rake'
gem 'rake', '> 11.0.1', '< 12.0'

group :development do
gem 'awesome_print', :require => 'ap'
Expand Down
6 changes: 3 additions & 3 deletions lib/octokit/client/authorizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def check_application_authorization(token, options = {})
secret = opts.delete(:client_secret) || client_secret

as_app(key, secret) do |app_client|
app_client.get "/applications/#{client_id}/tokens/#{token}", opts
app_client.get "applications/#{client_id}/tokens/#{token}", opts
end
end

Expand All @@ -173,7 +173,7 @@ def reset_application_authorization(token, options = {})
secret = opts.delete(:client_secret) || client_secret

as_app(key, secret) do |app_client|
app_client.post "/applications/#{client_id}/tokens/#{token}", opts
app_client.post "applications/#{client_id}/tokens/#{token}", opts
end
end

Expand All @@ -194,7 +194,7 @@ def revoke_application_authorization(token, options = {})
secret = opts.delete(:client_secret) || client_secret

as_app(key, secret) do |app_client|
app_client.delete "/applications/#{client_id}/tokens/#{token}", opts
app_client.delete "applications/#{client_id}/tokens/#{token}", opts

app_client.last_response.status == 204
end
Expand Down
54 changes: 48 additions & 6 deletions spec/octokit/client/authorizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
end
end # .authorize_url

describe ".check_application_authorization", :vcr do
it "checks an application authorization" do
describe ".check_application_authorization" do
it "checks an application authorization", :vcr do
authorization = create_app_token

token = @app_client.check_application_authorization(authorization.token)
Expand All @@ -179,10 +179,24 @@
assert_requested :get, url
expect(token.user.login).to eq(test_github_login)
end

it "works in Enterprise mode" do
client = Octokit::Client.new \
:client_id => "abcde12345fghij67890",
:client_secret => "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd",
:api_endpoint => "https://gh-enterprise.com/api/v3"

path = "applications/abcde12345fghij67890/tokens/25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8"

request = stub_get("https://abcde12345fghij67890:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd@gh-enterprise.com/api/v3/#{path}")
token = client.check_application_authorization("25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8")

assert_requested request
end
end # .check_application_authorization

describe ".reset_application_authorization", :vcr do
it "resets a token" do
describe ".reset_application_authorization" do
it "resets a token", :vcr do
authorization = create_app_token

new_authorization = @app_client.reset_application_authorization authorization.token
Expand All @@ -195,10 +209,24 @@
:login => test_github_client_id, :password => test_github_client_secret
assert_requested :post, reset_url
end

it "works in Enterprise mode" do
client = Octokit::Client.new \
:client_id => "abcde12345fghij67890",
:client_secret => "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd",
:api_endpoint => "https://gh-enterprise.com/api/v3"

path = "applications/abcde12345fghij67890/tokens/25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8"

request = stub_post("https://abcde12345fghij67890:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd@gh-enterprise.com/api/v3/#{path}")
token = client.reset_application_authorization("25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8")

assert_requested request
end
end # .reset_application_authorization

describe ".revoke_application_authorization", :vcr do
it "deletes an application authorization" do
describe ".revoke_application_authorization" do
it "deletes an application authorization", :vcr do
authorization = create_app_token

result = @app_client.revoke_application_authorization authorization.token
Expand All @@ -209,6 +237,20 @@
:login => test_github_client_id, :password => test_github_client_secret
assert_requested :delete, revoke_url
end

it "works in Enterprise mode" do
client = Octokit::Client.new \
:client_id => "abcde12345fghij67890",
:client_secret => "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd",
:api_endpoint => "https://gh-enterprise.com/api/v3"

path = "applications/abcde12345fghij67890/tokens/25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8"

request = stub_delete("https://abcde12345fghij67890:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd@gh-enterprise.com/api/v3/#{path}")
token = client.revoke_application_authorization("25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8")

assert_requested request
end
end # .revoke_application_authorization

describe ".revoke_all_application_authorizations" do
Expand Down