コード例 #1
0
 @Test
 public void testCheckCaptcha_singleCall_emptyAnswer() throws Exception {
   expect(requestMock.get(eq("captcha_answer"))).andReturn("").atLeastOnce();
   expect(requestMock.get(eq("captcha_type"))).andReturn("image").anyTimes();
   expect(requestMock.get(eq("captcha_id"))).andReturn(sessionId).anyTimes();
   replayDefault();
   assertFalse(captchaService.checkCaptcha());
   verifyDefault();
 }
コード例 #2
0
 @Override
 public void onEvent(Event event, Object source, Object data) {
   // Do not use the the LESS cache if we're doing an HTML export because we need that URLs located
   // in less file be
   // recomputed (see ExportURLFactory).
   XWikiContext xcontext = (XWikiContext) data;
   XWikiRequest request = xcontext.getRequest();
   String format = request.get("format");
   if ("html".equals(format)) {
     lessContext.setHtmlExport(true);
   }
 }
コード例 #3
0
 @Test
 public void testCheckCaptcha_singleCall_false() throws Exception {
   String wrongAnwser = "chetuck";
   expect(requestMock.get(eq("captcha_answer"))).andReturn(wrongAnwser).atLeastOnce();
   expect(requestMock.get(eq("captcha_type"))).andReturn("image").atLeastOnce();
   expect(requestMock.get(eq("captcha_id"))).andReturn(sessionId).atLeastOnce();
   expect(imgCaptchaVerifierMock.isAnswerCorrect(eq(sessionId), eq(wrongAnwser)))
       .andReturn(false)
       .once();
   replayDefault();
   assertFalse(captchaService.checkCaptcha());
   verifyDefault();
 }
コード例 #4
0
 @Test
 public void testCheckCaptcha_doubleCall_true() throws Exception {
   String expectedAnwser = "chetuck";
   expect(requestMock.get(eq("captcha_answer"))).andReturn(expectedAnwser).atLeastOnce();
   expect(requestMock.get(eq("captcha_type"))).andReturn("image").atLeastOnce();
   expect(requestMock.get(eq("captcha_id"))).andReturn(sessionId).atLeastOnce();
   expect(imgCaptchaVerifierMock.isAnswerCorrect(eq(sessionId), eq(expectedAnwser)))
       .andReturn(true)
       .once();
   expect(imgCaptchaVerifierMock.isAnswerCorrect(eq(sessionId), eq(expectedAnwser)))
       .andReturn(false)
       .anyTimes();
   replayDefault();
   assertTrue(captchaService.checkCaptcha());
   // check answer caching
   assertTrue(captchaService.checkCaptcha());
   verifyDefault();
 }
コード例 #5
0
 @Before
 public void setUp_CelementsWebScriptServiceTest() throws Exception {
   context = getContext();
   requestMock = createMockAndAddToDefault(XWikiRequest.class);
   context.setRequest(requestMock);
   sessionId = "AD87ND789S1L08";
   sessionMock = createMockAndAddToDefault(HttpSession.class);
   expect(requestMock.getSession()).andReturn(sessionMock).anyTimes();
   expect(sessionMock.getId()).andReturn(sessionId).anyTimes();
   captchaService = (CaptchaService) Utils.getComponent(ICaptchaServiceRole.class);
   setupImageCaptchaVerifierMock();
 }