users: add stricter username rules.

Add stricter username rules:

* Only allow usernames to contain basic letters, numbers, CJK characters, underscores, dashes and periods.
* Don't allow names to start or end with punctuation.
* Don't allow names to have multiple underscores in a row.
* Don't allow active users to have names that look like deleted users (e.g. "user_1234").
* Don't allow emoji or any other Unicode characters except for Chinese, Japanese, and Korean
  characters. CJK characters are currently grandfathered in but will be disallowed in the future.

Users with an invalid name will be shown a permanent sitewide banner until they change their name.
This commit is contained in:
evazion
2022-03-05 00:46:49 -06:00
parent ca98e218a1
commit a160a3acce
7 changed files with 140 additions and 34 deletions

View File

@@ -75,6 +75,17 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
end
end
context "when a user has an invalid username" do
should "show a warning banner" do
@user = create(:user)
@user.update_columns(name: "foo__bar")
get_auth posts_path, @user
assert_response :success
assert_select "#invalid-name-notice"
end
end
context "on api authentication" do
setup do
@user = create(:user, password: "password")