Skip to content

Commit

Permalink
Test for oauth rakes
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Torres committed Aug 9, 2018
1 parent 6da2243 commit 27fd03e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -326,6 +326,7 @@ SPEC_HELPER_MIN_SPECS = \
spec/lib/carto/visualization_invalidation_service_spec.rb \
spec/lib/tasks/layers_rake_spec.rb \
spec/lib/tasks/fix_unique_legends_spec.rb \
spec/lib/tasks/oauth_rake_spec.rb \
spec/models/carto/username_proposer_spec.rb \
spec/services/carto/overquota_users_service_spec.rb \
spec/services/visualization/common_data_service_spec.rb \
Expand Down
85 changes: 85 additions & 0 deletions spec/lib/tasks/oauth_rake_spec.rb
@@ -0,0 +1,85 @@
require 'spec_helper_min'
require 'rake'

describe 'oauth.rake' do
before(:all) do
Rake.application.rake_require('tasks/oauth')
Rake::Task.define_task(:environment)

@sequel_developer = FactoryGirl.create(:valid_user)
@developer = Carto::User.find(@sequel_developer.id)
@user = FactoryGirl.create(:valid_user)
@oauth_app = FactoryGirl.create(:oauth_app, user: @developer)
end

before(:each) do
@oauth_app_user = @oauth_app.oauth_app_users.create!(user_id: @user.id)
end

after(:each) do
@oauth_app_user.reload.destroy!
end

after(:all) do
@oauth_app.destroy!
@user.destroy
@sequel_developer.destroy
end

describe '#destroy_expired_access_tokens' do
before(:each) do
Rake::Task['cartodb:oauth:destroy_expired_access_tokens'].reenable
end

it 'does not delete just created access tokens' do
access_token = @oauth_app_user.oauth_access_tokens.create!
Rake::Task['cartodb:oauth:destroy_expired_access_tokens'].invoke
expect(Carto::OauthAccessToken.exists?(access_token.id)).to(be_true)
end

it 'deletes old access tokens' do
access_token = @oauth_app_user.oauth_access_tokens.create!
Delorean.jump(2.hours)
Rake::Task['cartodb:oauth:destroy_expired_access_tokens'].invoke
expect(Carto::OauthAccessToken.exists?(access_token.id)).to(be_false)
end
end

describe '#destroy_expired_refresh_tokens' do
before(:each) do
Rake::Task['cartodb:oauth:destroy_expired_refresh_tokens'].reenable
end

it 'does not delete just created access tokens' do
refresh_token = @oauth_app_user.oauth_refresh_tokens.create!(scopes: ['offline'])
Rake::Task['cartodb:oauth:destroy_expired_refresh_tokens'].invoke
expect(Carto::OauthRefreshToken.exists?(refresh_token.id)).to(be_true)
end

it 'deletes old access tokens' do
refresh_token = @oauth_app_user.oauth_refresh_tokens.create!(scopes: ['offline'])
Delorean.jump(1.year)
Rake::Task['cartodb:oauth:destroy_expired_refresh_tokens'].invoke
expect(Carto::OauthRefreshToken.exists?(refresh_token.id)).to(be_false)
end
end

describe '#destroy_expired_authorization_codes' do
before(:each) do
Rake::Task['cartodb:oauth:destroy_expired_authorization_codes'].reenable
end

it 'does not delete just created access tokens' do
authorization_code = @oauth_app_user.oauth_authorization_codes.create!
Rake::Task['cartodb:oauth:destroy_expired_authorization_codes'].invoke
expect(Carto::OauthAuthorizationCode.exists?(authorization_code.id)).to(be_true)
end

it 'deletes old access tokens' do
authorization_code = @oauth_app_user.oauth_authorization_codes.create!
Delorean.jump(2.minutes)
Rake::Task['cartodb:oauth:destroy_expired_authorization_codes'].invoke
expect(Carto::OauthAuthorizationCode.exists?(authorization_code.id)).to(be_false)
end
end
end

0 comments on commit 27fd03e

Please sign in to comment.