@@ -110,7 +110,7 @@ def test_find_from_value_finds_new_token_by_digest
110110 found = AccessToken . find_from_value ( @token . plaintext_value )
111111
112112 assert_equal @token . id , found &.id
113- assert_equal AccessToken :: HASHED_TOKEN_LENGTH , @token . reload . read_attribute ( :value ) . length
113+ assert @token . reload . read_attribute ( :value ) . start_with? ( AccessToken :: DIGEST_PREFIX )
114114 end
115115
116116 def test_find_from_value_finds_legacy_token
@@ -120,26 +120,18 @@ def test_find_from_value_finds_legacy_token
120120 found = AccessToken . find_from_value ( legacy_value )
121121
122122 assert_equal @token . id , found &.id
123- end
124-
125- def test_find_from_value_migrates_legacy_token_to_hash
126- legacy_value = 'legacy_plaintext_token_value_64chars'
127- @token . update_columns ( value : legacy_value )
128-
129- AccessToken . find_from_value ( legacy_value )
130-
131- assert_equal AccessToken ::HASHED_TOKEN_LENGTH , @token . reload . read_attribute ( :value ) . length
132- assert_equal AccessToken . compute_digest ( legacy_value ) , @token . read_attribute ( :value )
123+ # No migration: DB value remains unchanged
124+ assert_equal legacy_value , @token . reload . read_attribute ( :value )
133125 end
134126
135127 def test_find_from_value_rejects_leaked_hash_as_token
136- leaked_hash = @token . reload . read_attribute ( :value )
128+ stored_hash = @token . reload . read_attribute ( :value )
137129
138- # Verify the hash is 96 chars ( our security boundary)
139- assert_equal AccessToken ::HASHED_TOKEN_LENGTH , leaked_hash . length
130+ # Verify the DB value has our prefix
131+ assert stored_hash . start_with? ( AccessToken ::DIGEST_PREFIX )
140132
141133 # An attacker with access to the DB hash should NOT be able to authenticate
142- found = AccessToken . find_from_value ( leaked_hash )
134+ found = AccessToken . find_from_value ( stored_hash )
143135
144136 assert_nil found , "Security vulnerability: leaked hash was accepted as a valid token"
145137 end
0 commit comments