From 256b4e9910fd04b506222fb3b513bb1bbc846fc9 Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Thu, 21 Nov 2024 08:35:05 -0600 Subject: [PATCH] Update Data Request script to compute requesting issuer and have configurable depth changelog: Internal, Scripts, Update DataRequest script to compute requesting issuer and have configurable depth --- lib/data_pull.rb | 26 ++++++++++++++++++++++++-- lib/script_base.rb | 7 +++++++ spec/lib/data_pull_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/data_pull.rb b/lib/data_pull.rb index f2c1be32320..bfaa15a885f 100644 --- a/lib/data_pull.rb +++ b/lib/data_pull.rb @@ -162,14 +162,22 @@ def run(args:, config:) ActiveRecord::Base.connection.execute('SET statement_timeout = 0') uuids = args + requesting_issuers = + config.requesting_issuers.presence || compute_requesting_issuers(uuids) + users, missing_uuids = uuids.map do |uuid| DataRequests::Deployed::LookupUserByUuid.new(uuid).call || uuid end.partition { |u| u.is_a?(User) } - shared_device_users = DataRequests::Deployed::LookupSharedDeviceUsers.new(users).call + shared_device_users = + if config.depth && config.depth > 0 + DataRequests::Deployed::LookupSharedDeviceUsers.new(users, config.depth).call + else + users + end output = shared_device_users.map do |user| - DataRequests::Deployed::CreateUserReport.new(user, config.requesting_issuers).call + DataRequests::Deployed::CreateUserReport.new(user, requesting_issuers).call end if config.include_missing? @@ -198,6 +206,20 @@ def run(args:, config:) json: output, ) end + + private + + def compute_requesting_issuers(uuids) + service_providers = ServiceProviderIdentity.where(uuid: uuids).pluck(:service_provider) + return nil if service_providers.empty? + service_provider = service_providers.tally.max_by { |_sp, count| count }[0] + + warn "Computed service provider #{service_provider}" + + [ + service_provider, + ] + end end class ProfileSummary diff --git a/lib/script_base.rb b/lib/script_base.rb index 01352c25dee..c6e0c95f790 100644 --- a/lib/script_base.rb +++ b/lib/script_base.rb @@ -33,6 +33,7 @@ def reason_arg? :show_help, :requesting_issuers, :deflate, + :depth, :reason, keyword_init: true, ) do @@ -111,6 +112,12 @@ def option_parser config.requesting_issuers << issuer end + opts.on('--depth=DEPTH', <<-MSG) do |depth| + depth of connected devices (used for ig-request task) + MSG + config.depth = depth.to_i + end + opts.on('--help') do config.show_help = true end diff --git a/spec/lib/data_pull_spec.rb b/spec/lib/data_pull_spec.rb index 640f0741544..d772f9abfaf 100644 --- a/spec/lib/data_pull_spec.rb +++ b/spec/lib/data_pull_spec.rb @@ -319,6 +319,26 @@ expect(result.subtask).to eq('ig-request') expect(result.uuids).to eq([user.uuid]) end + + context 'with SP UUID argument and no requesting issuer' do + let(:args) { [identity.uuid] } + let(:config) { ScriptBase::Config.new } + + it 'runs the report with computed requesting issuer', aggregate_failures: true do + expect(result.table).to be_nil + expect(result.json.first.keys).to contain_exactly( + :user_id, + :login_uuid, + :requesting_issuer_uuid, + :email_addresses, + :mfa_configurations, + :user_events, + ) + + expect(result.subtask).to eq('ig-request') + expect(result.uuids).to eq([user.uuid]) + end + end end end