예제 #1
0
  @Override
  protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception {
    HtmlForm form = authorizationPage.getFormByName("loginform");
    final HtmlTextInput login = form.getInputByName("log");
    login.setValueAttribute("testscribeup");
    final HtmlPasswordInput passwd = form.getInputByName("pwd");
    passwd.setValueAttribute("testpwdscribeup");

    HtmlElement button = (HtmlElement) authorizationPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // HtmlButton button = form.getButtonByName("wp-submit");

    final HtmlPage confirmPage = button.click();
    form = confirmPage.getFormByName("loginform");

    button = (HtmlElement) confirmPage.createElement("button");
    button.setAttribute("type", "submit");
    form.appendChild(button);
    // button = form.getButtonByName("wp-submit");

    final HtmlPage callbackPage = button.click();
    final String callbackUrl = callbackPage.getUrl().toString();
    logger.debug("callbackUrl : {}", callbackUrl);
    return callbackUrl;
  }
예제 #2
0
  public Page submitAuthentication(String username, String password) throws IOException {
    if (usernameField != null && passwordField != null && submitField != null) {
      usernameField.setValueAttribute(username);
      passwordField.setValueAttribute(password);
      return submitField.click();
    }

    return null;
  }
예제 #3
0
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   final HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlPasswordInput password = form.getInputByName("password");
   password.setValueAttribute("testpwdpac4j");
   final HtmlSubmitInput submit = form.getInputByValue("Sign In");
   final HtmlPage callbackPage = submit.click();
   /*form = confirmPage.getForms().get(0);
   HtmlButton continueButton = (HtmlButton) form.getElementById("continue-button");
   HtmlPage callbackPage = continueButton.click();*/
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
예제 #4
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginValid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("*****@*****.**");
    textPassword.setValueAttribute("malczyk123");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.getTitleText().equals("Taskflow-Main"));

    webClient.closeAllWindows();
  }
예제 #5
0
  /**
   * Test method.
   *
   * @throws IOException exception
   */
  public void testLoginInvalid() throws IOException {
    final WebClient webClient = new WebClient();
    // XXX: issues with jquery
    webClient.setJavaScriptEnabled(false);
    final HtmlPage page = webClient.getPage(HTTP_PROCC_LOGIN_USER);
    final HtmlForm form = page.getFormByName(LOGIN_USER_FORM_NAME);

    final HtmlTextInput textEmail = form.getInputByName(EMAIL_INPUT_NAME);
    final HtmlPasswordInput textPassword = form.getInputByName(PASSWD_INPUT_NAME);
    final HtmlSubmitInput btnLogin = form.getInputByName(LOGIN_SUBMIT_NAME);

    textEmail.setValueAttribute("invalidLogin");
    textPassword.setValueAttribute("invalidPasswd");

    final HtmlPage nextPage = btnLogin.click();
    assertTrue(nextPage.asText().contains("Błędny login bądź hasło"));

    webClient.closeAllWindows();
  }
예제 #6
0
 @Override
 protected String getCallbackUrl(final WebClient webClient, final HtmlPage authorizationPage)
     throws Exception {
   webClient.waitForBackgroundJavaScript(5000);
   HtmlForm form = authorizationPage.getForms().get(0);
   final HtmlTextInput login = form.getInputByName("login_email");
   login.setValueAttribute("*****@*****.**");
   final HtmlPasswordInput passwd = form.getInputByName("login_password");
   passwd.setValueAttribute("testpwdscribeup");
   HtmlButton submit = form.getButtonByName("");
   HtmlPage confirmPage = submit.click();
   confirmPage = (HtmlPage) confirmPage.refresh();
   webClient.waitForBackgroundJavaScript(5000);
   form = confirmPage.getForms().get(0);
   HtmlButton submit2 = form.getButtonByName("allow_access");
   final HtmlPage callbackPage = submit2.click();
   final String callbackUrl = callbackPage.getUrl().toString();
   logger.debug("callbackUrl : {}", callbackUrl);
   return callbackUrl;
 }
예제 #7
0
  public static HtmlPage login(HtmlPage page, String username, String password) {
    int attempts = 0;
    boolean loggedIn = false;
    while (!loggedIn) {
      try {
        if (attempts > 3) System.exit(1);
        attempts++;
        System.out.println("Logging in... (Attempt " + attempts + ")");

        page = wc.getPage("http://torn.com/login");

        final HtmlForm form = page.getFormByName("login");

        HtmlSubmitInput button = form.getInputByName("btnLogin");

        HtmlTextInput textField = form.getInputByName("player");

        // Change the value of the text field
        textField.setValueAttribute(username);

        final HtmlPasswordInput passwordField = form.getInputByName("password");

        // Change the value of the text field
        passwordField.setValueAttribute(password);

        // Now submit the form by clicking the button and get back the second page.
        page = button.click();

        page = wc.getPage("http://torn.com/index.php");
        loggedIn = true;

      } catch (Exception e) {
        System.out.println(e.toString());
        loggedIn = false;
      }
    }
    return page;
  }
  @Test
  public void testConfigureApitoken() throws Exception {
    prepareSecurity();

    FreeStyleProject p = j.createFreeStyleProject();
    p.addProperty(
        new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("test2", false)));

    WebClient wc = j.createWebClient();
    wc.login("test1");

    String apitokenForTest2 = User.get("test2").getProperty(ApiTokenProperty.class).getApiToken();
    assertNotNull(apitokenForTest2);
    assertNotEquals("", apitokenForTest2);

    // authentication fails without apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }

    // authentication succeeds with the good apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2);
      j.submit(page.getFormByName("config"));

      assertEquals(
          "test2",
          ((SpecificUsersAuthorizationStrategy)
                  p.getProperty(AuthorizeProjectProperty.class).getStrategy())
              .getUserid());
    }

    // authentication fails with a bad apitoken
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(true);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2 + "xxx");
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }

    // authentication fails if the apitoken is used for password
    {
      HtmlPage page = wc.getPage(p, "configure");
      HtmlCheckBoxInput useApitoken =
          page.<HtmlCheckBoxInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'useApitoken') and @type='checkbox']");
      useApitoken.setChecked(false);
      HtmlPasswordInput password =
          page.<HtmlPasswordInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'password') and @type='password']");
      password.setValueAttribute(apitokenForTest2);
      HtmlTextInput apitoken =
          page.<HtmlTextInput>getFirstByXPath(
              "//*[contains(@class, 'specific-user-authorization')]//input[contains(@name, 'apitoken') and @type='text']");
      apitoken.setValueAttribute(apitokenForTest2);
      try {
        j.submit(page.getFormByName("config"));
        fail();
      } catch (FailingHttpStatusCodeException e) {
        assertEquals(400, e.getStatusCode());
      }
    }
  }