Persist RS auth tokens in Redis
This commit is contained in:
9
spec/factories/remote_storage_authorizations.rb
Normal file
9
spec/factories/remote_storage_authorizations.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
FactoryBot.define do
|
||||
factory :remote_storage_authorization do
|
||||
permissions { ["documents:rw"] }
|
||||
client_id { "some-fancy-app" }
|
||||
redirect_uri { "https://example.com/some-fancy-app" }
|
||||
app_name { "Fancy App" }
|
||||
expire_at { nil }
|
||||
end
|
||||
end
|
||||
36
spec/jobs/expire_remote_storage_authorization_job_spec.rb
Normal file
36
spec/jobs/expire_remote_storage_authorization_job_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ExpireRemoteStorageAuthorizationJob, type: :job do
|
||||
before do
|
||||
@user = create :user, cn: "ronald", ou: "kosmos.org"
|
||||
@rs_authorization = create :remote_storage_authorization, user: @user, expire_at: 1.day.ago
|
||||
end
|
||||
|
||||
after do
|
||||
clear_enqueued_jobs
|
||||
clear_performed_jobs
|
||||
end
|
||||
|
||||
subject(:job) {
|
||||
described_class.perform_later(@rs_authorization.id)
|
||||
}
|
||||
|
||||
let(:redis) {
|
||||
@redis ||= Redis.new(url: Setting.redis_url)
|
||||
}
|
||||
|
||||
it "removes the RS authorization from redis" do
|
||||
redis_key = "rs:authorizations:#{@user.address}:#{@rs_authorization.token}"
|
||||
expect(redis.keys(redis_key)).to_not be_empty
|
||||
|
||||
perform_enqueued_jobs { job }
|
||||
|
||||
expect(redis.keys(redis_key)).to be_empty
|
||||
end
|
||||
|
||||
it "deletes the RS authorization object" do
|
||||
expect {
|
||||
perform_enqueued_jobs { job }
|
||||
}.to change(RemoteStorageAuthorization, :count).by(-1)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user