MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestAuthenticationSpeed

Function TestAuthenticationSpeed

auth/auth_time_sensitive_test.go:29–47  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
29func 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}

Callers

nothing calls this directly

Calls 10

AuthenticateMethod · 0.95
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
NewTestAuthenticatorFunction · 0.85
NewUserMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65
GetSingleDataStoreMethod · 0.45
SinceMethod · 0.45

Tested by

no test coverage detected