1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.captcha;
17
18 import junit.framework.*;
19
20 import org.acegisecurity.captcha.AlwaysTestAfterMaxRequestsCaptchaChannelProcessor;
21
22
23
24
25
26
27
28
29 public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessorTests extends TestCase {
30
31
32 AlwaysTestAfterMaxRequestsCaptchaChannelProcessor alwaysTestAfterMaxRequestsCaptchaChannelProcessor;
33
34
35
36 protected void setUp() throws Exception {
37 super.setUp();
38 alwaysTestAfterMaxRequestsCaptchaChannelProcessor = new AlwaysTestAfterMaxRequestsCaptchaChannelProcessor();
39 }
40
41 public void testIsContextValidConcerningHumanity()
42 throws Exception {
43 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(1);
44
45 CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
46 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
47
48 context.incrementHumanRestrictedRessoucesRequestsCount();
49
50 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1);
51 assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
52
53 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(3);
54 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
55 context.incrementHumanRestrictedRessoucesRequestsCount();
56 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
57 context.incrementHumanRestrictedRessoucesRequestsCount();
58 assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
59 }
60
61 public void testNewContext() {
62 CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
63
64 assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
65 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(1);
66 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
67 }
68 }