Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/data_pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def banner

* #{basename} profile-summary uuid1 uuid2

* #{basename} uuid-export uuid1 uuid2 --requesting-issuer ABC:DEF:GHI

Options:
EOS
end
Expand All @@ -55,6 +57,7 @@ def subtask(name)
'email-lookup' => EmailLookup,
'ig-request' => InspectorGeneralRequest,
'profile-summary' => ProfileSummary,
'uuid-export' => UuidExport,
}[name]
end

Expand Down Expand Up @@ -211,4 +214,49 @@ def run(args:, config:)
)
end
end

class UuidExport
def run(args:, config:)
login_uuids = args

uuids = []
table = []
table << %w[login_uuid agency issuer external_uuid]

User.includes(:agency_identities, identities: { service_provider_record: :agency }).
where(uuid: login_uuids).
then do |scope|
if config.requesting_issuers.present?
scope.where(service_provider_record: { issuer: config.requesting_issuers })
else
scope
end
end.each do |user|
user.identities.each do |identity|
uuids << user.uuid
external_uuid = user.agency_identities&.find do |a_i|
a_i.agency == identity.service_provider_record.agency
end&.uuid || identity.uuid
table << [
user.uuid,
identity.service_provider_record.agency&.name,
identity.service_provider_record.issuer,
external_uuid,
]
end
end

if config.include_missing?
(login_uuids - uuids.uniq).each do |missing_uuid|
table << [missing_uuid, '[NOT FOUND]', '[NOT FOUND]', '[NOT FOUND]']
end
end

ScriptBase::Result.new(
subtask: 'uuid-export',
uuids: uuids.uniq,
table:,
)
end
end
end
70 changes: 70 additions & 0 deletions spec/lib/data_pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,74 @@
end
end
end

describe DataPull::UuidExport do
subject(:subtask) { DataPull::UuidExport.new }

let(:user1) { create(:user, :fully_registered) }
let(:user2) { create(:user, :fully_registered) }

let(:agency) { create(:agency) }
let(:service_provider) { create(:service_provider, agency_id: agency.id) }
let(:other_sp) { create(:service_provider, active: true, agency_id: agency.id) }

let(:identity) do
create(:service_provider_identity, service_provider: service_provider.issuer, user: user1)
end
let(:other_identity) do
create(:service_provider_identity, service_provider: other_sp.issuer, user: user2)
end

let(:agency_identity) do
create(:agency_identity, agency: agency, user: user1, uuid: identity.uuid)
end
let(:other_agency_identity) do
create(:agency_identity, agency: agency, user: user2, uuid: other_identity.uuid)
end

let(:args) { [user1.uuid, user2.uuid, 'does-not-exist'] }
let(:include_missing) { true }
subject(:result) { subtask.run(args: args, config: config) }

describe '#run' do
context 'without requesting issuers' do
let(:config) { ScriptBase::Config.new(include_missing: include_missing) }

it 'return partner UUIDs for all apps', aggregate_failures: true do
expected_table = [
['login_uuid', 'agency', 'issuer', 'external_uuid'],
[user1.uuid, agency.name, service_provider.issuer, agency_identity.uuid],
[user2.uuid, agency.name, other_sp.issuer, other_agency_identity.uuid],
['does-not-exist', '[NOT FOUND]', '[NOT FOUND]', '[NOT FOUND]'],
]

expect(result.table).to eq(expected_table)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hit some flakiness with this spec today in an unrelated pull request:

https://gitlab.login.gov/lg/identity-idp/-/jobs/651103

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like any sort would be guaranteed on the order of how users are listed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(result.subtask).to eq('uuid-export')
expect(result.uuids).to match_array([user1.uuid, user2.uuid])
end
end

context 'with requesting issuers' do
let(:config) do
ScriptBase::Config.new(
include_missing: include_missing,
requesting_issuers: [service_provider.issuer],
)
end

it 'return partner UUIDs for just provided app', aggregate_failures: true do
expected_table = [
['login_uuid', 'agency', 'issuer', 'external_uuid'],
[user1.uuid, agency.name, service_provider.issuer, agency_identity.uuid],
[user2.uuid, '[NOT FOUND]', '[NOT FOUND]', '[NOT FOUND]'],
['does-not-exist', '[NOT FOUND]', '[NOT FOUND]', '[NOT FOUND]'],
]

expect(result.table).to eq(expected_table)
expect(result.subtask).to eq('uuid-export')
expect(result.uuids).to match_array([user1.uuid])
end
end
end
end
end