Skip to content

Commit d35585c

Browse files
committed
Fix tests
1 parent 09b0930 commit d35585c

6 files changed

Lines changed: 52 additions & 10 deletions

File tree

features/step_definitions/strong_passwords_steps.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
end
77

88
Then /^I should see the error that the password is too weak$/ do
9-
assert has_content? User::STRONG_PASSWORD_FAIL_MSG
9+
assert has_content? "is too short (minimum is 15 characters)"
1010
end

test/integration/admin/api/buyers_users_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def setup
3939
put admin_api_account_user_path(buyer, user), params: { access_token: token_value, password: 'weakpwd' }
4040

4141
assert_response :unprocessable_entity
42-
assert_match User::STRONG_PASSWORD_FAIL_MSG, response.body
42+
assert_match "is too short (minimum is 15 characters)", response.body
4343
end
4444

4545
test 'update with strong password accepted when strong passwords enabled' do

test/integration/developer_portal/signup_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_weak_password_rejected_when_strong_passwords_enabled
102102
post signup_path, params: account_params(WEAK_PASSWORD)
103103

104104
assert_response :success
105-
assert_match User::STRONG_PASSWORD_FAIL_MSG, response.body
105+
assert_match "is too short (minimum is 15 characters)", response.body
106106
end
107107

108108
def test_strong_password_accepted_when_strong_passwords_enabled

test/integration/provider/signups_controller_integration_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_weak_password_rejected_when_strong_passwords_enabled
109109
end
110110

111111
assert_response :success
112-
assert_match User::STRONG_PASSWORD_FAIL_MSG, response.body
112+
assert_match "is too short (minimum is 15 characters)", response.body
113113
end
114114

115115
def test_strong_password_accepted_when_strong_passwords_enabled

test/integration/user-management-api/users_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def setup
405405
put admin_api_user_path(format: :xml, id: chuck.id, password: "weakpwd", password_confirmation: "weakpwd"), params: { provider_key: @provider.api_key }
406406

407407
assert_response :unprocessable_entity
408-
assert_match User::STRONG_PASSWORD_FAIL_MSG, response.body
408+
assert_match "is too short (minimum is 15 characters)", response.body
409409
end
410410

411411
test 'update with strong password accepted when strong passwords enabled' do

test/unit/authentication/by_password_test.rb

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class WeakPasswordTest < Authentication::ByPasswordTest
2424
user = user_with_password.call('weakpassword')
2525

2626
assert_not user.valid?
27-
assert_equal User::STRONG_PASSWORD_FAIL_MSG, user.errors[:password].first
27+
assert_equal "is too short (minimum is 15 characters)", user.errors[:password].first
2828
end
2929

3030
test 'weak password must be present' do
@@ -52,7 +52,7 @@ class ExistingUsersTest < Authentication::ByPasswordTest
5252
@user.password = "nononono"
5353
@user.valid?
5454

55-
assert_equal User::STRONG_PASSWORD_FAIL_MSG, @user.errors[:password].first
55+
assert_equal "is too short (minimum is 15 characters)", @user.errors[:password].first
5656
end
5757

5858
test 'password is not validated when user is sample data' do
@@ -66,17 +66,24 @@ class ExistingUsersTest < Authentication::ByPasswordTest
6666

6767
class ValidationsTest < Authentication::ByPasswordTest
6868
test 'should be valid with ASCII printable characters and longer than 15 characters' do
69-
user = @buyer.users.new password: "StrongPass123-+_!$#.@", password_confirmation: "StrongPass123-+_!$#.@"
70-
user.valid?
69+
user = user_with_password.call('StrongPass123-+_!$#.@')
70+
71+
assert user.valid?
72+
assert user.errors[:password].blank?
73+
end
7174

75+
test 'should be valid with Unicode characters and longer than 15 characters' do
76+
user = user_with_password.call('contraseña12345')
77+
78+
assert user.valid?
7279
assert user.errors[:password].blank?
7380
end
7481

7582
test 'should be invalid if shorter than 15 characters' do
7683
user = user_with_password.call('Pas$123')
7784
user.valid?
7885

79-
assert_equal User::STRONG_PASSWORD_FAIL_MSG, user.errors[:password].first
86+
assert_equal "is too short (minimum is 15 characters)", user.errors[:password].first
8087
end
8188

8289
test 'should be invalid if password and password confirmation do not match' do
@@ -87,6 +94,41 @@ class ValidationsTest < Authentication::ByPasswordTest
8794
end
8895
end
8996

97+
class UnicodeNormalizationTest < Authentication::ByPasswordTest
98+
test 'password is normalized to NFC before saving' do
99+
# "café" with e + combining acute accent (NFD form)
100+
password_nfd = "cafe\u0301_secretpass"
101+
# "café" with precomposed é (NFC form)
102+
password_nfc = "café_secretpass"
103+
104+
assert_not_equal password_nfd, password_nfc
105+
assert_equal password_nfd.unicode_normalize(:nfc), password_nfc
106+
107+
user = user_with_password.call(password_nfd)
108+
user.password_confirmation = password_nfd
109+
user.save!
110+
111+
assert user.authenticated?(password_nfc), 'Should authenticate with NFC form'
112+
assert user.authenticated?(password_nfd), 'Should authenticate with NFD form (normalized before comparison)'
113+
end
114+
115+
test 'password length is counted after NFC normalization' do
116+
# 15 characters in NFD (e + combining accent = 2 code points)
117+
password_nfd = "contraseñas123".unicode_normalize(:nfd)
118+
# 14 characters in NFC (ñ = 1 code point)
119+
password_nfc = "contraseñas123".unicode_normalize(:nfc)
120+
121+
assert_equal 15, password_nfd.length
122+
assert_equal 14, password_nfc.length
123+
124+
user = user_with_password.call(password_nfd)
125+
user.password_confirmation = password_nfd
126+
127+
assert_not user.valid?, 'Should be invalid because NFC-normalized length is 14 (< 15)'
128+
assert_equal "is too short (minimum is 15 characters)", user.errors[:password].first
129+
end
130+
end
131+
90132
class MethodsTest < Authentication::ByPasswordTest
91133
class ValidatePasswordTest < MethodsTest
92134
setup do

0 commit comments

Comments
 (0)