TestBcryptCostTimes will output the time it takes to hash a password with each bcrypt cost value
(t *testing.T)
| 43 | |
| 44 | // TestBcryptCostTimes will output the time it takes to hash a password with each bcrypt cost value |
| 45 | func TestBcryptCostTimes(t *testing.T) { |
| 46 | // Little value in running this regularly. Might be useful for one-off informational purposes |
| 47 | t.Skip("Test disabled") |
| 48 | |
| 49 | minCostToTest := bcrypt.DefaultCost |
| 50 | maxCostToTest := bcrypt.DefaultCost + 5 |
| 51 | |
| 52 | for i := minCostToTest; i < maxCostToTest; i++ { |
| 53 | t.Run(fmt.Sprintf("cost%d", i), func(t *testing.T) { |
| 54 | startTime := time.Now() |
| 55 | _, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i) |
| 56 | duration := time.Since(startTime) |
| 57 | |
| 58 | t.Logf("bcrypt.GenerateFromPassword with cost %d took: %v", i, duration) |
| 59 | assert.NoError(t, err) |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestSetBcryptCost(t *testing.T) { |
| 65 | ctx := base.TestCtx(t) |