Return a 401 Response when Github creds are bad via the API (#5249) [deploy]

This commit is contained in:
Molly Struve 2019-12-26 14:51:36 -06:00 committed by GitHub
parent b5db5b19a9
commit 2415392da5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -1,6 +1,6 @@
module Api
module V0
class GithubReposController < ApplicationController
class GithubReposController < ApiController
def index
client = create_octokit_client
existing_user_repos = GithubRepo.
@ -10,6 +10,8 @@ module Api
repo.selected = existing_user_repos.include?(repo.id)
repo
end
rescue Octokit::Unauthorized => e
render json: { error: "Github Unauthorized: #{e.message}", status: 401 }, status: :unauthorized
end
def update_or_create

View file

@ -19,6 +19,13 @@ RSpec.describe "Api::V0::GithubRepos", type: :request do
get "/api/github_repos"
expect(response).to have_http_status(:ok)
end
it "returns 401 if github raises an unauthorized error" do
allow(Octokit::Client).to receive(:new).and_raise(Octokit::Unauthorized)
get "/api/github_repos"
expect(response).to have_http_status(:unauthorized)
expect(response.parsed_body["error"]).to include("Github Unauthorized")
end
end
describe "POST /api/v0/github_repos/update_or_create" do