From 25f74defe5e0d96371842bbe78561bde2cf37a2d Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 21 Jun 2016 13:59:12 +0200 Subject: [PATCH] try fixing updating github oauth scopes --- lib/travis/api/app/endpoint/authorization.rb | 2 +- spec/unit/endpoint/authorization/user_manager_spec.rb | 2 +- spec_core/github/oauth_spec.rb | 8 ++++---- vendor/travis-core/lib/travis/github/oauth.rb | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/travis/api/app/endpoint/authorization.rb b/lib/travis/api/app/endpoint/authorization.rb index 2343c2d5..3cf72469 100644 --- a/lib/travis/api/app/endpoint/authorization.rb +++ b/lib/travis/api/app/endpoint/authorization.rb @@ -292,7 +292,7 @@ class Travis::Api::App Travis.run_service(:sync_user, user) end - Travis::Github::Oauth.track_scopes(user) # unless Travis.env == 'test' + Travis::Github::Oauth.update_scopes(user) # unless Travis.env == 'test' nullify_logins(user.github_id, user.login) end diff --git a/spec/unit/endpoint/authorization/user_manager_spec.rb b/spec/unit/endpoint/authorization/user_manager_spec.rb index 9f3acf40..71ea2932 100644 --- a/spec/unit/endpoint/authorization/user_manager_spec.rb +++ b/spec/unit/endpoint/authorization/user_manager_spec.rb @@ -3,7 +3,7 @@ describe Travis::Api::App::Endpoint::Authorization::UserManager do before do Travis::Features.enable_for_all(:education_data_sync) - Travis::Github::Oauth.stubs(:track_scopes) # TODO test that scopes are being updated + Travis::Github::Oauth.stubs(:update_scopes) # TODO test that scopes are being updated end describe '#info' do diff --git a/spec_core/github/oauth_spec.rb b/spec_core/github/oauth_spec.rb index eb7fe169..86613d91 100644 --- a/spec_core/github/oauth_spec.rb +++ b/spec_core/github/oauth_spec.rb @@ -20,7 +20,7 @@ describe Travis::Github::Oauth do end end - describe 'track_scopes' do + describe 'update_scopes' do before { user.reload } describe 'the token did not change' do @@ -28,7 +28,7 @@ describe Travis::Github::Oauth do it 'does not resolve github scopes' do Travis::Github::Oauth.expects(:scopes_for).never - described_class.track_scopes(user) + described_class.update_scopes(user) end end @@ -42,7 +42,7 @@ describe Travis::Github::Oauth do it 'updates github scopes' do Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar']) - described_class.track_scopes(user) + described_class.update_scopes(user) expect(user.reload.github_scopes).to eq ['foo', 'bar'] end end @@ -57,7 +57,7 @@ describe Travis::Github::Oauth do it 'updates github scopes' do Travis::Github::Oauth.expects(:scopes_for).returns(['foo', 'bar']) - described_class.track_scopes(user) + described_class.update_scopes(user) expect(user.reload.github_scopes).to eq ['foo', 'bar'] end end diff --git a/vendor/travis-core/lib/travis/github/oauth.rb b/vendor/travis-core/lib/travis/github/oauth.rb index 969152a4..59348ab1 100644 --- a/vendor/travis-core/lib/travis/github/oauth.rb +++ b/vendor/travis-core/lib/travis/github/oauth.rb @@ -1,7 +1,7 @@ module Travis module Github module Oauth - class TrackScopes < Struct.new(:user) + class UpdateScopes < Struct.new(:user) def run update if update? end @@ -14,17 +14,17 @@ module Travis end def update? - github_oauth_token_changed?(user) or user.github_scopes.blank? + token_changed?(user) or not Oauth.correct_scopes?(user) end - def github_oauth_token_changed?(user) + def token_changed?(user) user.github_oauth_token_changed? or user.previous_changes.key?('github_oauth_token') end end class << self - def track_scopes(user) - TrackScopes.new(user).run + def update_scopes(user) + UpdateScopes.new(user).run end def correct_scopes?(user)