Skip to content

DI all the things, and test them too #9

@mallorydxw

Description

@mallorydxw

We need to DI all the things, and then we need to add tests. The code is currently not really unit-testable.

Sample layout of all the classes:

Email/Setup
  handles the AJAX actions for the setup screen
Email/Login
  handles the stuff for the login screen
Email/Sender
  actually handles the sending of the emails 
SMS/Setup
SMS/Login
SMS/Sender
TOTP/Setup
TOTP/Login

Setup
  mostly calls things on Email/Setup, SMS/Setup, and TOTP/Setup
Login
  mostly calls things on Email/Login, SMS/Login, and TOTP/Login

TokenManager
  this class is used by: Email/Setup, Email/Login, SMS/Setup, SMS/Login
  ->generateNewToken($userId, $tokenNamespace)
    creates token 
    adds token to $userId's 2fa_${tokenNamespace}_temporary_token
    returns token
  ->validateToken($userId, $tokenNamespace, $token)
    checks token is correct
    checks token is not expired 
    adds token to the "recently used tokens" list
    returns true or false

src/di.php
  This file needs to replace lib/options.php

We'll probably need a few more classes that can mostly mimic the contents of lib/x.php:
Assets
ForceSetup
Helpers
  this can be used for anything in lib/helpers.php that doesn't get moved into another file
Page
Settings
Login
Settings
SiteList
UserProfile
UsersList

Should be able to do all this without the Ruby tests breaking. But as the Ruby tests are very limited we also need to be quite careful.

This'll be a lot of work. We'll probably never do it. But if we start using this plugin on more sites we should do it.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions