AI Implementation feature(820): Project Scaffold and Platform Foundations (#1)
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { LoginBackoffService } from '../../backend/src/common/services/login-backoff.service';
|
||||
|
||||
describe('LoginBackoffService', () => {
|
||||
it('starts unblocked', () => {
|
||||
const s = new LoginBackoffService();
|
||||
expect(s.isBlocked('1.1.1.1', 'alice', 1000)).toBe(0);
|
||||
});
|
||||
|
||||
it('blocks after repeated failures and resets on success', () => {
|
||||
const s = new LoginBackoffService();
|
||||
const now = 1000;
|
||||
for (let i = 0; i < 5; i++) s.recordFailure('1.1.1.1', 'alice', now);
|
||||
expect(s.isBlocked('1.1.1.1', 'alice', now + 100)).toBeGreaterThan(0);
|
||||
s.reset('1.1.1.1', 'alice');
|
||||
expect(s.isBlocked('1.1.1.1', 'alice', now + 100)).toBe(0);
|
||||
});
|
||||
|
||||
it('is per (ip, username)', () => {
|
||||
const s = new LoginBackoffService();
|
||||
for (let i = 0; i < 6; i++) s.recordFailure('1.1.1.1', 'alice', 1000 + i);
|
||||
expect(s.isBlocked('1.1.1.1', 'alice', 1100)).toBeGreaterThan(0);
|
||||
expect(s.isBlocked('1.1.1.1', 'bob', 1100)).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user