@@ -82,23 +82,68 @@ describe('GET /internal/auth-events/login-stats', () => {
8282describe ( 'GET /internal/security/anomalies' , ( ) => {
8383 it ( 'returns anomalies' , async ( ) => {
8484 ( AuthEvent . findAll as any ) . mockResolvedValue ( [
85- { ip_address : '1.1.1.1' } ,
86- { ip_address : '1.1.1.1' } ,
87- { ip_address : '1.1.1.1' } ,
88- { ip_address : '1.1.1.1' } ,
89- { ip_address : '1.1.1.1' } ,
90- { ip_address : '1.1.1.1' } ,
91- { ip_address : '1.1.1.1' } ,
92- { ip_address : '1.1.1.1' } ,
93- { ip_address : '1.1.1.1' } ,
94- { ip_address : '1.1.1.1' } ,
95- { ip_address : '1.1.1.1' } ,
85+ {
86+ user_id : 'user_1' ,
87+ type : 'login_failed' ,
88+ ip_address : '192.168.1.10' ,
89+ user_agent : 'Mozilla/5.0 Chrome' ,
90+ metadata : { reason : 'invalid_password' } ,
91+ created_at : new Date ( '2026-03-29T10:00:00Z' ) ,
92+ } ,
93+ {
94+ user_id : 'user_2' ,
95+ type : 'jwt_failed' ,
96+ ip_address : '192.168.1.11' ,
97+ user_agent : 'Mozilla/5.0 Firefox' ,
98+ metadata : { reason : 'invalid_signature' } ,
99+ created_at : new Date ( '2026-03-29T10:05:00Z' ) ,
100+ } ,
101+ {
102+ user_id : null ,
103+ type : 'suspicious_ip' ,
104+ ip_address : '10.0.0.5' ,
105+ user_agent : null ,
106+ metadata : { flagged : true } ,
107+ created_at : new Date ( '2026-03-29T10:10:00Z' ) ,
108+ } ,
109+ {
110+ user_id : 'user_3' ,
111+ type : 'otp_failed' ,
112+ ip_address : '172.16.0.3' ,
113+ user_agent : 'Safari' ,
114+ metadata : { attempts : 3 } ,
115+ created_at : new Date ( '2026-03-29T10:15:00Z' ) ,
116+ } ,
117+ {
118+ user_id : 'user_4' ,
119+ type : 'refresh_token_failed' ,
120+ ip_address : '192.168.1.20' ,
121+ user_agent : 'Mozilla/5.0 Edge' ,
122+ metadata : { expired : true } ,
123+ created_at : new Date ( '2026-03-29T10:20:00Z' ) ,
124+ } ,
125+ {
126+ user_id : null ,
127+ type : 'suspicious_device' ,
128+ ip_address : '203.0.113.42' ,
129+ user_agent : 'Unknown' ,
130+ metadata : { anomaly : 'new_device' } ,
131+ created_at : new Date ( '2026-03-29T10:25:00Z' ) ,
132+ } ,
133+ {
134+ user_id : 'user_5' ,
135+ type : 'webauthn_login_failed' ,
136+ ip_address : '198.51.100.8' ,
137+ user_agent : 'Mozilla/5.0 Chrome' ,
138+ metadata : { challenge_failed : true } ,
139+ created_at : new Date ( '2026-03-29T10:30:00Z' ) ,
140+ } ,
96141 ] ) ;
97142
98143 const res = await request ( app ) . get ( '/internal/security/anomalies' ) ;
99144
100145 expect ( res . status ) . toBe ( 200 ) ;
101- expect ( res . body . suspiciousIps . length ) . toBeGreaterThan ( 0 ) ;
146+ expect ( res . body . total ) . toBe ( 7 ) ;
102147 } ) ;
103148} ) ;
104149
0 commit comments