github.com/resonatecoop/id@v1.1.0-43/util/password/password_test.go (about) 1 package password_test 2 3 import ( 4 "testing" 5 6 "github.com/resonatecoop/id/util/password" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestVerifyPassword(t *testing.T) { 11 // Test valid passwords 12 assert.Nil(t, password.VerifyPassword( 13 "$2a$10$CUoGytf1pR7CC6Y043gt/.vFJUV4IRqvH5R6F0VfITP8s2TqrQ.4e", 14 "test_secret", 15 )) 16 17 assert.Nil(t, password.VerifyPassword( 18 "$2a$10$4J4t9xuWhOKhfjN0bOKNReS9sL3BVSN9zxIr2.VaWWQfRBWh1dQIS", 19 "test_password", 20 )) 21 22 assert.Nil(t, password.VerifyPassword( 23 "$P$5ZDzPE45C7nt/53A.Slxyhx5GxHxs8/", 24 "phpassword", 25 )) 26 27 // Test invalid password 28 assert.NotNil(t, password.VerifyPassword("bogus", "password")) 29 } 30 31 func TestValidatePassword(t *testing.T) { 32 // Test empty password 33 assert.NotNil(t, password.ValidatePassword("")) 34 35 // Test password too short 36 assert.NotNil(t, password.ValidatePassword("bogus")) 37 38 // Test insecure password 39 assert.NotNil(t, password.ValidatePassword("123456789")) 40 }