@@ -82,23 +82,31 @@ describe('user', function () {
8282 assert . equal ( r , true )
8383 } )
8484
85- it ( 'auths valid pbkdb2 password' , async ( ) => {
86- const r = await User . validPassword (
87- 'YouGuessedIt!' ,
88- '050cfa70c3582be0d5bfae25138a8486dc2e6790f39bc0c4e111223ba6034432' ,
89- 'unit-test' ,
90- '(ICzAm2.QfCa6.MN' ,
91- )
85+ it ( 'auths valid self-describing PBKDF2 password' , async ( ) => {
86+ const salt = '(ICzAm2.QfCa6.MN'
87+ const hash = await User . hashForStorage ( 'YouGuessedIt!' , salt )
88+ const r = await User . validPassword ( 'YouGuessedIt!' , hash , 'unit-test' , salt )
9289 assert . equal ( r , true )
9390 } )
9491
95- it ( 'rejects invalid pbkdb2 password' , async ( ) => {
96- const r = await User . validPassword (
97- 'YouMissedIt!' ,
98- '050cfa70c3582be0d5bfae25138a8486dc2e6790f39bc0c4e111223ba6034432' ,
99- 'unit-test' ,
100- '(ICzAm2.QfCa6.MN' ,
101- )
92+ it ( 'rejects invalid self-describing PBKDF2 password' , async ( ) => {
93+ const salt = '(ICzAm2.QfCa6.MN'
94+ const hash = await User . hashForStorage ( 'YouGuessedIt!' , salt )
95+ const r = await User . validPassword ( 'YouMissedIt!' , hash , 'unit-test' , salt )
96+ assert . equal ( r , false )
97+ } )
98+
99+ it ( 'auths valid legacy PBKDF2-5000 password' , async ( ) => {
100+ const salt = '(ICzAm2.QfCa6.MN'
101+ const hash = await User . hashAuthPbkdf2 ( 'YouGuessedIt!' , salt , 5000 )
102+ const r = await User . validPassword ( 'YouGuessedIt!' , hash , 'unit-test' , salt )
103+ assert . equal ( r , true )
104+ } )
105+
106+ it ( 'rejects invalid legacy PBKDF2-5000 password' , async ( ) => {
107+ const salt = '(ICzAm2.QfCa6.MN'
108+ const hash = await User . hashAuthPbkdf2 ( 'YouGuessedIt!' , salt , 5000 )
109+ const r = await User . validPassword ( 'YouMissedIt!' , hash , 'unit-test' , salt )
102110 assert . equal ( r , false )
103111 } )
104112
@@ -188,7 +196,7 @@ describe('user', function () {
188196 before ( cleanup )
189197 after ( cleanup )
190198
191- it ( 'upgrades plain text password to PBKDF2 on login' , async ( ) => {
199+ it ( 'upgrades plain text password to self-describing PBKDF2 on login' , async ( ) => {
192200 await cleanup ( )
193201 await insertUser ( testPass , null )
194202
@@ -198,14 +206,15 @@ describe('user', function () {
198206 const row = await getDbPassword ( )
199207 assert . ok ( row . pass_salt , 'pass_salt should be set after upgrade' )
200208 assert . notEqual ( row . password , testPass , 'password should be hashed' )
209+ assert . ok ( row . password . includes ( '$' ) , 'password should be in self-describing format' )
201210
202211 // verify round-trip: can still log in with the upgraded hash
203212 const again = await User . authenticate ( authCreds )
204213 assert . ok ( again , 'login should succeed after upgrade' )
205214 await cleanup ( )
206215 } )
207216
208- it ( 'upgrades SHA1 password to PBKDF2 on login' , async ( ) => {
217+ it ( 'upgrades SHA1 password to self-describing PBKDF2 on login' , async ( ) => {
209218 // authenticate() passes the full authTry.username (including @group) to
210219 // validPassword(), so the HMAC key must match that full string
211220 const sha1Hash = crypto
@@ -221,13 +230,14 @@ describe('user', function () {
221230 const row = await getDbPassword ( )
222231 assert . ok ( row . pass_salt , 'pass_salt should be set after upgrade' )
223232 assert . notEqual ( row . password , sha1Hash , 'password should be re-hashed' )
233+ assert . ok ( row . password . includes ( '$' ) , 'password should be in self-describing format' )
224234
225235 const again = await User . authenticate ( authCreds )
226236 assert . ok ( again , 'login should succeed after upgrade' )
227237 await cleanup ( )
228238 } )
229239
230- it ( 'upgrades PBKDF2-5000 to current iterations on login' , async ( ) => {
240+ it ( 'upgrades PBKDF2-5000 to self-describing format on login' , async ( ) => {
231241 const legacySalt = User . generateSalt ( )
232242 const legacyHash = await User . hashAuthPbkdf2 ( testPass , legacySalt , 5000 )
233243 await cleanup ( )
@@ -239,15 +249,16 @@ describe('user', function () {
239249 const row = await getDbPassword ( )
240250 assert . notEqual ( row . password , legacyHash , 'password should be re-hashed' )
241251 assert . notEqual ( row . pass_salt , legacySalt , 'salt should be regenerated' )
252+ assert . ok ( row . password . includes ( '$' ) , 'password should be in self-describing format' )
242253
243254 const again = await User . authenticate ( authCreds )
244255 assert . ok ( again , 'login should succeed after upgrade' )
245256 await cleanup ( )
246257 } )
247258
248- it ( 'does not re-hash password already at current iterations ' , async ( ) => {
259+ it ( 'does not re-hash password already in self-describing format ' , async ( ) => {
249260 const salt = User . generateSalt ( )
250- const hash = await User . hashAuthPbkdf2 ( testPass , salt )
261+ const hash = await User . hashForStorage ( testPass , salt )
251262 await cleanup ( )
252263 await insertUser ( hash , salt )
253264
0 commit comments