Skip to content

Improve and extract username and email generators into a class

What does this MR do and why?

See this thread !112931 (comment 1295900394).

We need the same username and email generators for a service class that will create Service Account, #392000 (closed).

This MR extracts the functionality to Gitlab::Utils::UsernameAndEmailGenerator class to share it between classes by using the Composition.

This MR also improves username/email generators by

  • changing {random_string} part from SecureRandom.hex(8) to SecureRandom.hex(16) to reduce the probability(1/16**16) of duplicates, see !112548 (comment 1289885385).
  • Returns uniquify conflict resolver back in case of duplicates. Though there is a very low probability 1/16*16, technically, there could be conflicts and this will guard against "username/email reserved" issues.
  • Addresses all issues mentioned in !112931 (comment 1299350132) and adds tests for each issue to prevent any regression in the future.

Related to !112548 (merged)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Bogdan Denkovych

Merge request reports

Loading