-
Notifications
You must be signed in to change notification settings - Fork 166
LG-15273 Create a Redis Set to track Socure users #11773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0952b88
add a redis pool to track the number of socure users
theabrad 6577ab7
add specs for socure_user service
theabrad 79ca2d7
linty mclinterson
theabrad 897add2
add changelog
theabrad 12d506c
move socure_users_pool to use throttle pool
theabrad 63e180d
remove flushdb for socure_users_spec
theabrad 6a1e3c9
use REDIS_POOL rather than REDIS_THROTTLE_POOL
theabrad bfaf877
flush REDIS_POOL in specs
theabrad 3fc4279
SocureUser -> SocureUserSet
theabrad cfde010
socure_user_set
theabrad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Idv | ||
| class SocureUser | ||
| attr_reader :redis_pool | ||
|
|
||
| def initialize(redis_pool: REDIS_POOL) | ||
| @redis_pool = redis_pool | ||
| end | ||
|
|
||
| def add_user!(user_uuid:) | ||
| return if maxed_users? | ||
|
|
||
| redis_pool.with do |client| | ||
| client.sadd(key, user_uuid) | ||
| end | ||
| end | ||
|
|
||
| def count | ||
| redis_pool.with do |client| | ||
| client.scard(key) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def maxed_users? | ||
| count >= IdentityConfig.store.doc_auth_socure_max_allowed_users | ||
| end | ||
|
|
||
| def key | ||
| 'idv:socure:users' | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Idv::SocureUser do | ||
| let(:socure_user_set) { Idv::SocureUser.new } | ||
| let(:dummy_uuid_1) { 'ABC0001' } | ||
| let(:dummy_uuid_2) { 'ABC0002' } | ||
| let(:dummy_uuid_3) { 'ABC0003' } | ||
|
|
||
| around do |ex| | ||
| REDIS_POOL.with { |client| client.flushdb } | ||
| ex.run | ||
| REDIS_POOL.with { |client| client.flushdb } | ||
| end | ||
|
|
||
| describe '#add_user!' do | ||
| before do | ||
| allow(IdentityConfig.store).to receive(:doc_auth_socure_max_allowed_users).and_return(2) | ||
| end | ||
|
|
||
| it 'correctly adds user and tracks count' do | ||
| socure_user_set.add_user!(user_uuid: dummy_uuid_1) | ||
| expect(socure_user_set.count).to eq(1) | ||
| end | ||
|
|
||
| it 'does not add duplicates' do | ||
| socure_user_set.add_user!(user_uuid: dummy_uuid_1) | ||
| expect(socure_user_set.count).to eq(1) | ||
| socure_user_set.add_user!(user_uuid: dummy_uuid_1) | ||
| expect(socure_user_set.count).to eq(1) | ||
| end | ||
|
|
||
| it 'does not allow more than doc_auth_socure_max_allowed_users to be added to set' do | ||
| socure_user_set.add_user!(user_uuid: dummy_uuid_1) | ||
| expect(socure_user_set.count).to eq(1) | ||
| socure_user_set.add_user!(user_uuid: dummy_uuid_2) | ||
| expect(socure_user_set.count).to eq(2) | ||
| socure_user_set.add_user!(user_uuid: dummy_uuid_3) | ||
| expect(socure_user_set.count).to eq(2) | ||
| end | ||
| end | ||
|
|
||
| describe '#count' do | ||
| before do | ||
| allow(IdentityConfig.store).to receive(:doc_auth_socure_max_allowed_users).and_return(10) | ||
| end | ||
| it 'count is zero when there are no users in the redis store' do | ||
| expect(socure_user_set.count).to eq(0) | ||
| end | ||
|
|
||
| it 'gives the user count' do | ||
| 10.times.each do |index| | ||
| socure_user_set.add_user!(user_uuid: "ABC000#{index}") | ||
| end | ||
|
|
||
| expect(socure_user_set.count).to eq(10) | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.