Skip to content

LG-9984: Add mfa_created_at to analytics#8718

Merged
jc-gsa merged 16 commits intomainfrom
LG-9984-add-mfa-created-at-to-analytics
Jul 7, 2023
Merged

LG-9984: Add mfa_created_at to analytics#8718
jc-gsa merged 16 commits intomainfrom
LG-9984-add-mfa-created-at-to-analytics

Conversation

@jc-gsa
Copy link
Contributor

@jc-gsa jc-gsa commented Jul 3, 2023

🎫 Ticket

LG-9984

Adds value mfa_created_at to event Multi-Factor Authentication.

@jc-gsa jc-gsa requested a review from a team July 3, 2023 23:02
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Couple comments and a lingering question about data querying, but functionally I tested this and it works great 👍

private

def track_analytics(result)
mfa_created_at = current_user&.encrypted_recovery_code_digest_generated_at
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the nil-safe operator here? Not sure I'd expect current_user to be nil here, and don't see a corresponding spec.

Suggested change
mfa_created_at = current_user&.encrypted_recovery_code_digest_generated_at
mfa_created_at = current_user.encrypted_recovery_code_digest_generated_at

# TODO Note: This is a mirror of the style found in:
# app/forms/totp_verification_form.rb
# @return [BackupCodeConfiguration, nil]
def if_valid_code_return_config(plaintext_code)
Copy link
Contributor

@aduth aduth Jul 5, 2023

Choose a reason for hiding this comment

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

Granting that it's drawing from some prior art, I find the method name a little awkward. It seems to work and act like a config "look-up", so I'd wonder if something like config or config_for could work (some precedent for the latter).

(Not a blocker)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the case TOTP, and the method if_valid_totp_code_return_config, I prefer the verbose descriptiveness. Changing that method, and the method in question, to config hides the validation which is generally more important than the config itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's fair. I feel like the method had been doing a lot that wasn't obvious by its name, and my previous suggestion was based on an assumption that it's largely a "lookup", which is only partially true.

I'm a bit surprised about the side-effect to update the used_at property, and worry that that it's not obvious that the code is effectively consumed any time we call this if_valid_code_return_config method.

I'd wonder if we should split this up somehow between the validation/consumption/retrieval. I'm not sure we need all the same validation for the created_at property, for example.

true
end

# TODO Note: This is a mirror of the style found in:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the TODO remark?

Suggested change
# TODO Note: This is a mirror of the style found in:
# Note: This is a mirror of the style found in:

Comment on lines +39 to +44
return unless plaintext_code.present?
backup_code = RandomPhrase.normalize(plaintext_code)
config = BackupCodeConfiguration.find_with_code(code: backup_code, user_id: @user.id)
return unless code_usable?(config)
config.update!(used_at: Time.zone.now)
config
Copy link
Contributor

@aduth aduth Jul 5, 2023

Choose a reason for hiding this comment

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

To avoid duplicating this logic between here and in verify, can we refactor verify to use this new method?

i.e.

def verify(plaintext_code)
  if_valid_code_return_config(plaintext_code).present?
end

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we include a test case in this file that yields a value other than nil ?

# @param [Hash] errors Authentication error reasons, if unsuccessful
# @param [String] context
# @param [String] multi_factor_auth_method
# @param [DateTime] multi_factor_auth_method_created_at time auth method was created
Copy link
Contributor

Choose a reason for hiding this comment

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

For awareness: In trying to verify how we'd query this, I wasn't able to get CloudWatch to produce results for date string filtering. Worst case we might need to convert this to another format like a timestamp number, but hopefully I'm just doing something wrong. Have you been able to devise a query using this type of data?

Slack thread here: https://gsa-tts.slack.com/archives/C5E7EJWF7/p1688563099123109

jc-gsa added 2 commits July 5, 2023 16:02
changelog: Internal, Analytics, Add mfa_created_at to Multi-Factor Authentication event
@jc-gsa jc-gsa force-pushed the LG-9984-add-mfa-created-at-to-analytics branch from 8c8bd3f to bf29282 Compare July 5, 2023 21:28
@jc-gsa jc-gsa merged commit 73c598b into main Jul 7, 2023
@jc-gsa jc-gsa deleted the LG-9984-add-mfa-created-at-to-analytics branch July 7, 2023 16:24
This was referenced Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants