mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-06 14:33:10 -06:00
* Refactor ApplicationServiceWorkerState to be more robust * Add launch.json to VS Code * Implement login with JWT, registering with email, failed login rate limiting and reset password with m.login.email.identity auth type * Log errors when JWT parsing failed * Development build script * Fix linter errors * Use golangci-lint as a linter in VS Code * Fix tests with RtFailedLogin * Pass config load tests - parse JWT public key only if enabled * Reduce CI steps Do not support 386 arch and go 1.16, 1.17 * Fix linter errors * Change RtFailedLogin logic - nil pointer can be provided * Respect access token in query * Fix typos * Use only one mutex in RtFailedLogin * Remove eventsRemaining across appservice component * Push dendrite to production registry as well * Rafactor TestRtFailedLogin
41 lines
827 B
Go
41 lines
827 B
Go
package ratelimit
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/matryer/is"
|
|
)
|
|
|
|
func TestRtFailedLogin(t *testing.T) {
|
|
is := is.New(t)
|
|
rtfl := NewRtFailedLogin(&RtFailedLoginConfig{
|
|
Enabled: true,
|
|
Limit: 3,
|
|
Interval: 10 * time.Millisecond,
|
|
})
|
|
var (
|
|
can bool
|
|
remaining time.Duration
|
|
remainingB time.Duration
|
|
)
|
|
for i := 0; i < 3; i++ {
|
|
can, remaining = rtfl.CanAct("foo")
|
|
is.True(can)
|
|
is.Equal(remaining, time.Duration(0))
|
|
rtfl.Act("foo")
|
|
}
|
|
can, remaining = rtfl.CanAct("foo")
|
|
is.True(!can)
|
|
is.True(remaining > time.Millisecond*9)
|
|
can, remainingB = rtfl.CanAct("bar")
|
|
is.True(can)
|
|
is.Equal(remainingB, time.Duration(0))
|
|
rtfl.Act("bar")
|
|
rtfl.Act("bar")
|
|
time.Sleep(remaining + time.Millisecond)
|
|
can, remaining = rtfl.CanAct("foo")
|
|
is.True(can)
|
|
is.Equal(remaining, time.Duration(0))
|
|
}
|