discourse/spec/lib
Osama Sayegh dd6ec65061
FEATURE: Centralized 2FA page (#15377)
2FA support in Discourse was added and grown gradually over the years: we first
added support for TOTP for logins, then we implemented backup codes, and last
but not least, security keys. 2FA usage was initially limited to logging in,
but it has been expanded and we now require 2FA for risky actions such as
adding a new admin to the site.

As a result of this gradual growth of the 2FA system, technical debt has
accumulated to the point where it has become difficult to require 2FA for more
actions. We now have 5 different 2FA UI implementations and each one has to
support all 3 2FA methods (TOTP, backup codes, and security keys) which makes
it difficult to maintain a consistent UX for these different implementations.
Moreover, there is a lot of repeated logic in the server-side code behind these
5 UI implementations which hinders maintainability even more.

This commit is the first step towards repaying the technical debt: it builds a
system that centralizes as much as possible of the 2FA server-side logic and
UI. The 2 main components of this system are:

1. A dedicated page for 2FA with support for all 3 methods.
2. A reusable server-side class that centralizes the 2FA logic (the
`SecondFactor::AuthManager` class).

From a top-level view, the 2FA flow in this new system looks like this:

1. User initiates an action that requires 2FA;

2. Server is aware that 2FA is required for this action, so it redirects the
user to the 2FA page if the user has a 2FA method, otherwise the action is
performed.

3. User submits the 2FA form on the page;

4. Server validates the 2FA and if it's successful, the action is performed and
the user is redirected to the previous page.

A more technically-detailed explanation/documentation of the new system is
available as a comment at the top of the `lib/second_factor/auth_manager.rb`
file. Please note that the details are not set in stone and will likely change
in the future, so please don't use the system in your plugins yet.

Since this is a new system that needs to be tested, we've decided to migrate
only the 2FA for adding a new admin to the new system at this time (in this
commit). Our plan is to gradually migrate the remaining 2FA implementations to
the new system.

For screenshots of the 2FA page, see PR #15377 on GitHub.
2022-02-17 12:12:59 +03:00
..
auth DEV: Introduce Auth::Result API for overrides_* (#15378) 2021-12-23 10:53:17 +00:00
backup_restore DEV: Prevent extraneous log message in specs (#15504) 2022-01-09 20:26:52 +01:00
compression DEV: Split max decompressed setting for themes and backups (#8179) 2019-10-11 14:38:10 -03:00
content_security_policy FIX: Allow CSP to work correctly for non-default hostnames/schemes (#9180) 2020-03-19 19:54:42 +00:00
i18n FIX: translation precedence was different on client and server 2021-12-17 14:03:35 +01:00
imap/providers FEATURE: Improve group email settings UI (#13083) 2021-05-28 09:28:18 +10:00
onebox DEV: Add tests for wistia onebox. (#15860) 2022-02-08 13:04:32 +08:00
second_factor FEATURE: Centralized 2FA page (#15377) 2022-02-17 12:12:59 +03:00
seed_data DEV: Add rubocop-rspec (#9288) 2020-03-27 17:35:40 +01:00
site_settings FEATURE: Replace Crawl-delay directive with proper rate limiting (#15131) 2021-11-30 12:55:25 +03:00
topic_query FIX: Exclude PMs that user sent to themselves. (#14496) 2021-10-04 11:55:35 +08:00
validators FEATURE: Add timezone to core user_options (#8380) 2019-11-25 10:49:27 +10:00
webauthn DEV: Add Windows Hello webauthn authentication spec (#15871) 2022-02-09 12:47:47 +10:00
bookmark_manager_spec.rb DEV: Rolling back bookmarkable column changes (#15482) 2022-01-07 12:16:43 +10:00
bookmark_query_spec.rb FEATURE: Go to last unread for topic-level bookmark links (#14396) 2021-09-21 13:49:56 +10:00
bookmark_reminder_notification_handler_spec.rb DEV: Ignore bookmarks.topic_id column and remove references to it in code (#14289) 2021-09-15 10:16:54 +10:00
browser_detection_spec.rb FIX: Detect DiscourseHub user agent. 2019-08-09 11:58:15 +03:00
content_security_policy_spec.rb DEV: prevents flakky spec when deleting plugin (#14701) 2021-10-25 10:24:21 +02:00
db_helper_spec.rb FEATURE: Include optimized thumbnails for topics (#9215) 2020-05-05 09:07:50 +01:00
discourse_js_processor_spec.rb Support for transpiling .js files (#9160) 2020-03-11 09:43:55 -04:00
encodings_spec.rb DEV: use #frozen_string_literal: true on all spec 2019-04-30 10:27:42 +10:00
group_email_credentials_check_spec.rb FEATURE: Scheduled group email credential problem check (#15396) 2022-01-04 10:14:33 +10:00
introduction_updater_spec.rb FIX: replace default welcome topic post with new value from wizard 2020-04-01 15:42:45 -04:00
message_id_service_spec.rb FIX: Canonical Message-ID was incorrect for some cases (#15701) 2022-02-03 10:36:32 +10:00
mini_sql_multisite_connection_spec.rb DEV: upgrade mini_sql (#12465) 2021-03-24 08:48:04 +11:00
onebox_spec.rb DEV: Absorb onebox gem into core (#12979) 2021-05-26 15:11:35 +05:30
post_jobs_enqueuer_spec.rb FIX: Do not send emails to mailing_list_mode subscribers for PMs (#14159) 2021-08-26 15:16:35 +10:00
s3_cors_rulesets_spec.rb DEV: Improve s3:ensure_cors_rules logging (#14832) 2021-11-08 11:44:12 +10:00
search_spec.rb FEATURE: Split up text segmentation for Chinese and Japanese. 2022-02-07 09:21:14 +08:00
shrink_uploaded_image_spec.rb DEV: Improve script/downsize_uploads.rb (#13508) 2021-06-24 00:09:40 +02:00
theme_flag_modifier_spec.rb PERF: Eager load Theme associations in Stylesheet Manager. 2021-06-21 11:06:58 +08:00
theme_javascript_compiler_spec.rb FEATURE: Introduce theme/component QUnit tests (take 2) (#12661) 2021-04-12 15:02:58 +03:00
tiny_japanese_segmenter_spec.rb FEATURE: Split up text segmentation for Chinese and Japanese. 2022-02-07 09:21:14 +08:00
topic_upload_security_manager_spec.rb DEV: Clean up S3 specs, stubs, and helpers 2020-09-28 12:02:25 +01:00
twitter_api_spec.rb FIX: Replace Twitter handles one at a time (#15870) 2022-02-09 13:54:02 +02:00
upload_creator_spec.rb FIX: Blurry onebox favicon images (#15258) 2021-12-10 12:25:50 -07:00
upload_markdown_spec.rb DEV: Expand UploadMarkdown generation capabilities (#15930) 2022-02-14 15:48:27 +10:00
upload_recovery_spec.rb DEV: Fix methods removed in Ruby 3.2 (#15459) 2022-01-05 18:45:08 +01:00
upload_security_spec.rb FIX: manually adds frowning_face_with_open_mouth for apple (#13528) 2021-07-21 23:27:20 +02:00