Skip to content

Fix split email in self module#175

Open
darkone-linux wants to merge 1 commit into
cloud-gouv:mainfrom
darkone-linux:fix-split-email
Open

Fix split email in self module#175
darkone-linux wants to merge 1 commit into
cloud-gouv:mainfrom
darkone-linux:fix-split-email

Conversation

@darkone-linux

Copy link
Copy Markdown

This fix addresses two issues:

  • The splitString "." on the email could incorrectly capture the @.
    john.doe@domain.tld -> john, doe@domain
  • The argument order for elemAt was most likely reversed.

To test quickly:

nix-instantiate --eval --strict -E '
let
  pkgs = import (import ./npins).nixpkgs {};
  inherit (pkgs) lib;
  selfModule = import ./modules/self.nix;
  eval = lib.evalModules {
    modules = [
      selfModule
      {
        _module.args.vpnProfiles = {};
        _module.check = false;
      }
      {
        securix.self = {
          mainDisk = "/dev/nvme0n1";
          edition = "test";
          user.email = "prenom.nom@domaine.tld";
          machine = {
            hardwareSKU = "x280";
            serialNumber = "000000";
          };
        };
      }
    ];
  };
in {
  username = eval.config.securix.self.user.username;
}
'

It should normally produce:

{ username = "pnom"; }

NB: It might make sense to move this kind of processing into a dedicated library, using testable helper functions. That would make the algorithm more robust and allow handling additional cases, for example email addresses that do not follow the "firstname.lastname..." pattern.

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