Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create MFA Report script #11740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions lib/data_pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def banner

* #{basename} ig-request uuid1 uuid2 --requesting-issuer=ABC:DEF:GHI

* #{basename} mfa-report uuid1 uuid2

* #{basename} profile-summary uuid1 uuid2

* #{basename} uuid-convert partner-uuid1 partner-uuid2
Expand All @@ -59,6 +61,7 @@ def subtask(name)
'email-lookup' => EmailLookup,
'events-summary' => EventsSummary,
'ig-request' => InspectorGeneralRequest,
'mfa-report' => MfaReport,
'profile-summary' => ProfileSummary,
'uuid-convert' => UuidConvert,
'uuid-export' => UuidExport,
Expand Down Expand Up @@ -156,6 +159,44 @@ def run(args:, config:)
end
end

class MfaReport
def run(args:, config:)
require 'data_requests/deployed'
uuids = args

users, missing_uuids = uuids.map do |uuid|
DataRequests::Deployed::LookupUserByUuid.new(uuid).call || uuid
end.partition { |u| u.is_a?(User) }

output = users.map do |user|
output = DataRequests::Deployed::CreateMfaConfigurationsReport.new(user).call
output[:uuid] = user.uuid

output
end

if config.include_missing?
output += missing_uuids.map do |uuid|
{
uuid: uuid,
phone_configurations: [],
auth_app_configurations: [],
webauthn_configurations: [],
piv_cac_configurations: [],
backup_code_configurations: [],
not_found: true,
}
end
end

ScriptBase::Result.new(
subtask: 'mfa-report',
uuids: uuids,
json: output,
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a JSON-only report? might match existing tooling better of we could find a way to do tabular representation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, yeah. I'm not sure what representing as a table could look like since the fields for each MFA type can vary pretty significantly (in content and amount).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More similar to the IG Report than the other reports unfortunately

)
end
end

class InspectorGeneralRequest
def run(args:, config:)
require 'data_requests/deployed'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def webauthn_configurations_report
user.webauthn_configurations.map do |webauthn_configuration|
{
name: webauthn_configuration.name,
platform_authenticator: webauthn_configuration.platform_authenticator,
created_at: webauthn_configuration.created_at,
}
end
Expand Down
27 changes: 27 additions & 0 deletions spec/lib/data_pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,33 @@
end
end

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

describe '#run' do
let(:user) { create(:user) }
let(:args) { [user.uuid] }
let(:config) { ScriptBase::Config.new }

subject(:result) { subtask.run(args:, config:) }

it 'runs the MFA report, has a JSON-only response', aggregate_failures: true do
expect(result.table).to be_nil
expect(result.json.first.keys).to contain_exactly(
:uuid,
:phone_configurations,
:auth_app_configurations,
:webauthn_configurations,
:piv_cac_configurations,
:backup_code_configurations,
)

expect(result.subtask).to eq('mfa-report')
expect(result.uuids).to eq([user.uuid])
end
end
end

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
webauthn_data = result[:webauthn_configurations]

expect(webauthn_data.first[:name]).to eq(webauthn_configuration.name)
expect(webauthn_data.first[:platform_authenticator]).to eq(
webauthn_configuration.platform_authenticator,
)
expect(webauthn_data.first[:created_at]).to be_within(1.second).of(
webauthn_configuration.created_at,
)
Expand Down