@@ -89,7 +89,21 @@ class SiteServiceImplTest extends Specification {
89
89
return true
90
90
})
91
91
}
92
-
92
+
93
+ def " logAboutAbsentPage() should pass abbreviated page when it's too long" () {
94
+ given :
95
+ String longPageUrl = ' /long/url/' + (' x' * SuspiciousActivity . PAGE_URL_LENGTH )
96
+ and :
97
+ String expectedPageUrl = longPageUrl. take(SuspiciousActivity . PAGE_URL_LENGTH - 3 ) + ' ...'
98
+ when :
99
+ service. logAboutAbsentPage(longPageUrl, TEST_METHOD , null , null , null , null )
100
+ then :
101
+ 1 * suspiciousActivityDao. add({ SuspiciousActivity activity ->
102
+ assert activity?. page == expectedPageUrl
103
+ return true
104
+ })
105
+ }
106
+
93
107
@Unroll
94
108
def " logAboutAbsentPage() should pass method to dao" (String expectedMethod) {
95
109
when :
@@ -155,6 +169,19 @@ class SiteServiceImplTest extends Specification {
155
169
return true
156
170
})
157
171
}
172
+ def " logAboutAbsentPage() should pass abbreviated referer when it's too long" () {
173
+ given :
174
+ String longRefererUrl = ' /long/url/' + (' x' * SuspiciousActivity . REFERER_PAGE_LENGTH )
175
+ and :
176
+ String expectedRefererUrl = longRefererUrl. take(SuspiciousActivity . REFERER_PAGE_LENGTH - 3 ) + ' ...'
177
+ when :
178
+ service. logAboutAbsentPage(TEST_PAGE , TEST_METHOD , null , null , longRefererUrl, null )
179
+ then :
180
+ 1 * suspiciousActivityDao. add({ SuspiciousActivity activity ->
181
+ assert activity?. refererPage == expectedRefererUrl
182
+ return true
183
+ })
184
+ }
158
185
159
186
def " logAboutAbsentPage() should pass empty string to dao for unknown referer" () {
160
187
when :
@@ -175,6 +202,19 @@ class SiteServiceImplTest extends Specification {
175
202
return true
176
203
})
177
204
}
205
+ def " logAboutAbsentPage() should pass abbreviated user agent when it's too long" () {
206
+ given :
207
+ String longUserAgent = ' Mozilla/5.0 (Windows NT 6.1) AppleWebKit/' + (' x' * SuspiciousActivity . USER_AGENT_LENGTH )
208
+ and :
209
+ String expectedUserAgent = longUserAgent. take(SuspiciousActivity . USER_AGENT_LENGTH - 3 ) + ' ...'
210
+ when :
211
+ service. logAboutAbsentPage(TEST_PAGE , TEST_METHOD , null , null , null , longUserAgent)
212
+ then :
213
+ 1 * suspiciousActivityDao. add({ SuspiciousActivity activity ->
214
+ assert activity?. userAgent == expectedUserAgent
215
+ return true
216
+ })
217
+ }
178
218
179
219
def " logAboutAbsentPage() should pass empty string to dao for unknown user agent" () {
180
220
when :
@@ -247,6 +287,19 @@ class SiteServiceImplTest extends Specification {
247
287
return true
248
288
})
249
289
}
290
+ def " logAboutFailedAuthentication() should pass abbreviated page when it's too long" () {
291
+ given :
292
+ String longPageUrl = ' /long/url/' + (' x' * SuspiciousActivity . PAGE_URL_LENGTH )
293
+ and :
294
+ String expectedPageUrl = longPageUrl. take(SuspiciousActivity . PAGE_URL_LENGTH - 3 ) + ' ...'
295
+ when :
296
+ service. logAboutFailedAuthentication(longPageUrl, TEST_METHOD , null , null , null , null , null )
297
+ then :
298
+ 1 * suspiciousActivityDao. add({ SuspiciousActivity activity ->
299
+ assert activity?. page == expectedPageUrl
300
+ return true
301
+ })
302
+ }
250
303
251
304
def " logAboutFailedAuthentication() should pass null to dao for unknown user" () {
252
305
when :
@@ -310,6 +363,20 @@ class SiteServiceImplTest extends Specification {
310
363
})
311
364
}
312
365
366
+ def " logAboutFailedAuthentication() should pass abbreviated referer when it's too long" () {
367
+ given :
368
+ String longRefererUrl = ' /long/url/' + (' x' * SuspiciousActivity . REFERER_PAGE_LENGTH )
369
+ and :
370
+ String expectedRefererUrl = longRefererUrl. take(SuspiciousActivity . REFERER_PAGE_LENGTH - 3 ) + ' ...'
371
+ when :
372
+ service. logAboutFailedAuthentication(TEST_PAGE , TEST_METHOD , null , null , longRefererUrl, null , null )
373
+ then :
374
+ 1 * suspiciousActivityDao. add({ SuspiciousActivity activity ->
375
+ assert activity?. refererPage == expectedRefererUrl
376
+ return true
377
+ })
378
+ }
379
+
313
380
def " logAboutFailedAuthentication() should pass user agent to dao" () {
314
381
when :
315
382
service. logAboutFailedAuthentication(TEST_PAGE , TEST_METHOD , null , null , null , TEST_USER_AGENT , null )
@@ -330,4 +397,18 @@ class SiteServiceImplTest extends Specification {
330
397
})
331
398
}
332
399
400
+ def " logAboutFailedAuthentication() should pass abbreviated user agent when it's too long" () {
401
+ given :
402
+ String longUserAgent = ' Mozilla/5.0 (Windows NT 6.1) AppleWebKit/' + (' x' * SuspiciousActivity . USER_AGENT_LENGTH )
403
+ and :
404
+ String expectedUserAgent = longUserAgent. take(SuspiciousActivity . USER_AGENT_LENGTH - 3 ) + ' ...'
405
+ when :
406
+ service. logAboutFailedAuthentication(TEST_PAGE , TEST_METHOD , null , null , null , longUserAgent, null )
407
+ then :
408
+ 1 * suspiciousActivityDao. add({ SuspiciousActivity activity ->
409
+ assert activity?. userAgent == expectedUserAgent
410
+ return true
411
+ })
412
+ }
413
+
333
414
}
0 commit comments