Test that multiple authentications of the same user/password are fast. This is an important check because the underlying bcrypt algorithm used to verify passwords is _extremely_ slow (~100ms!) so we use a cache to speed it up (see password_hash.go).
(t *testing.T)
| 27 | // This is an important check because the underlying bcrypt algorithm used to verify passwords |
| 28 | // is _extremely_ slow (~100ms!) so we use a cache to speed it up (see password_hash.go). |
| 29 | func TestAuthenticationSpeed(t *testing.T) { |
| 30 | |
| 31 | ctx := base.TestCtx(t) |
| 32 | testBucket := base.GetTestBucket(t) |
| 33 | defer testBucket.Close(ctx) |
| 34 | dataStore := testBucket.GetSingleDataStore() |
| 35 | auth := NewTestAuthenticator(t, dataStore, nil, DefaultAuthenticatorOptions(ctx)) |
| 36 | user, _ := auth.NewUser("me", "goIsKewl", nil) |
| 37 | assert.True(t, user.Authenticate("goIsKewl")) |
| 38 | |
| 39 | start := time.Now() |
| 40 | for i := 0; i < 1000; i++ { |
| 41 | assert.True(t, user.Authenticate("goIsKewl")) |
| 42 | } |
| 43 | durationPerAuth := time.Since(start) / 1000 |
| 44 | if durationPerAuth > time.Millisecond { |
| 45 | t.Errorf("user.Authenticate is too slow: %v", durationPerAuth) |
| 46 | } |
| 47 | } |
nothing calls this directly
no test coverage detected