From c84350ab68837c3c3e4e1e9dd0a9d80313db5904 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 28 Jul 2015 15:33:16 +0200 Subject: Fix bug causing Bitbucket importer to crash when OAuth application had been removed. --- CHANGELOG | 12 ++++++++++++ app/controllers/import/bitbucket_controller.rb | 1 + lib/gitlab/bitbucket_import/client.rb | 21 +++++++++++++++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b22e098d128..470765e122e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,18 @@ v 7.13.2 - Show the first tab automatically on MergeRequests#new - Add rake task 'gitlab:update_commit_count' (Daniel Gerhardt) - Fix Gmail Actions + - Fix full screen mode for snippet comments (Daniel Gerhardt) + - Fix 404 error in files view after deleting the last file in a repository (Stan Hu) + - Fix the "Reload with full diff" URL button (Stan Hu) + - Fix label read access for unauthenticated users (Daniel Gerhardt) + - Fix access to disabled features for unauthenticated users (Daniel Gerhardt) + - Fix OAuth provider bug where GitLab would not go return to the redirect_uri after sign-in (Stan Hu) + - Fix file upload dialog for comment editing (Daniel Gerhardt) + - Set OmniAuth full_host parameter to ensure redirect URIs are correct (Stan Hu) + - Expire Rails cache entries after two weeks to prevent endless Redis growth + - Add support for destroying project milestones (Stan Hu) + - Add fetch command to the MR page + - Fix bug causing Bitbucket importer to crash when OAuth application had been removed. v 7.13.1 - Fix: Label modifications are not reflected in existing notes and in the issue list diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb index ca78a4aaa8e..af0b841f0b7 100644 --- a/app/controllers/import/bitbucket_controller.rb +++ b/app/controllers/import/bitbucket_controller.rb @@ -3,6 +3,7 @@ class Import::BitbucketController < Import::BaseController before_action :bitbucket_auth, except: :callback rescue_from OAuth::Error, with: :bitbucket_unauthorized + rescue_from Gitlab::BitbucketImport::Client::Unauthorized, with: :bitbucket_unauthorized def callback request_token = session.delete(:oauth_request_token) diff --git a/lib/gitlab/bitbucket_import/client.rb b/lib/gitlab/bitbucket_import/client.rb index 5b1952b9675..778b76f6890 100644 --- a/lib/gitlab/bitbucket_import/client.rb +++ b/lib/gitlab/bitbucket_import/client.rb @@ -1,6 +1,8 @@ module Gitlab module BitbucketImport class Client + class Unauthorized < StandardError; end + attr_reader :consumer, :api def initialize(access_token = nil, access_token_secret = nil) @@ -46,23 +48,23 @@ module Gitlab end def user - JSON.parse(api.get("/api/1.0/user").body) + JSON.parse(get("/api/1.0/user").body) end def issues(project_identifier) - JSON.parse(api.get("/api/1.0/repositories/#{project_identifier}/issues").body) + JSON.parse(get("/api/1.0/repositories/#{project_identifier}/issues").body) end def issue_comments(project_identifier, issue_id) - JSON.parse(api.get("/api/1.0/repositories/#{project_identifier}/issues/#{issue_id}/comments").body) + JSON.parse(get("/api/1.0/repositories/#{project_identifier}/issues/#{issue_id}/comments").body) end def project(project_identifier) - JSON.parse(api.get("/api/1.0/repositories/#{project_identifier}").body) + JSON.parse(get("/api/1.0/repositories/#{project_identifier}").body) end def find_deploy_key(project_identifier, key) - JSON.parse(api.get("/api/1.0/repositories/#{project_identifier}/deploy-keys").body).find do |deploy_key| + JSON.parse(get("/api/1.0/repositories/#{project_identifier}/deploy-keys").body).find do |deploy_key| deploy_key["key"].chomp == key.chomp end end @@ -82,11 +84,18 @@ module Gitlab end def projects - JSON.parse(api.get("/api/1.0/user/repositories").body).select { |repo| repo["scm"] == "git" } + JSON.parse(get("/api/1.0/user/repositories").body).select { |repo| repo["scm"] == "git" } end private + def get(url) + response = api.get(url) + raise Unauthorized if (400..499).include?(response.code.to_i) + + response + end + def config Gitlab.config.omniauth.providers.find { |provider| provider.name == "bitbucket"} end -- cgit v1.2.1 From 1fb04bcd74a6cf9f57bf3624b78a9d0d3b775a1c Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Tue, 4 Aug 2015 13:21:32 +0300 Subject: update changelog --- CHANGELOG | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 470765e122e..6718b2148db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ Please view this file on the master branch, on stable branches it's out of date. +v 7.13.3 + - Fix bug causing Bitbucket importer to crash when OAuth application had been removed. v 7.13.2 - Fix randomly failed spec @@ -9,18 +11,6 @@ v 7.13.2 - Show the first tab automatically on MergeRequests#new - Add rake task 'gitlab:update_commit_count' (Daniel Gerhardt) - Fix Gmail Actions - - Fix full screen mode for snippet comments (Daniel Gerhardt) - - Fix 404 error in files view after deleting the last file in a repository (Stan Hu) - - Fix the "Reload with full diff" URL button (Stan Hu) - - Fix label read access for unauthenticated users (Daniel Gerhardt) - - Fix access to disabled features for unauthenticated users (Daniel Gerhardt) - - Fix OAuth provider bug where GitLab would not go return to the redirect_uri after sign-in (Stan Hu) - - Fix file upload dialog for comment editing (Daniel Gerhardt) - - Set OmniAuth full_host parameter to ensure redirect URIs are correct (Stan Hu) - - Expire Rails cache entries after two weeks to prevent endless Redis growth - - Add support for destroying project milestones (Stan Hu) - - Add fetch command to the MR page - - Fix bug causing Bitbucket importer to crash when OAuth application had been removed. v 7.13.1 - Fix: Label modifications are not reflected in existing notes and in the issue list -- cgit v1.2.1