Пример #1
0
  public void testFileItemPersistence() throws Exception {
    // TODO: write a synchronous connector?
    byte[] testData = new byte[1024];
    for (int i = 0; i < testData.length; i++) testData[i] = (byte) i;

    Server server = new Server();
    SocketConnector connector = new SocketConnector();
    server.addConnector(connector);

    ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(new ServletHolder(new FileItemPersistenceTestServlet()), "/");
    server.addHandler(handler);

    server.start();

    localPort = connector.getLocalPort();

    try {
      WebClient wc = new WebClient();
      HtmlPage p = (HtmlPage) wc.getPage("http://localhost:" + localPort + '/');
      HtmlForm f = p.getFormByName("main");
      HtmlFileInput input = (HtmlFileInput) f.getInputByName("test");
      input.setData(testData);
      f.submit();
    } finally {
      server.stop();
    }
  }
  public void testLogInWithOpenIDAndSignUp() throws Exception {
    openid = createServer();

    realm = new HudsonPrivateSecurityRealm(true);
    hudson.setSecurityRealm(realm);

    WebClient wc = new WebClient();
    // Workaround failing ajax requests to build queue
    wc.setThrowExceptionOnFailingAjax(false);

    // Login with OpenID as an unregistered user
    HtmlPage login = wc.goTo("federatedLoginService/openid/login?from=/");
    login
        .getDocumentElement()
        .getOneHtmlElementByAttribute("a", "title", "log in with OpenID")
        .click();
    HtmlForm loginForm = getFormById(login, "openid_form");
    loginForm.getInputByName("openid").setValueAttribute(openid.url);
    HtmlPage signUp = (HtmlPage) loginForm.submit();

    // Sign up user
    HtmlForm signUpForm =
        getFormByAction(signUp, "/securityRealm/createAccountWithFederatedIdentity");
    signUpForm.getInputByName("password1").setValueAttribute("x");
    signUpForm.getInputByName("password2").setValueAttribute("x");
    HtmlPage loggedIn = submit(signUpForm);

    assertNotNull(loggedIn.getAnchorByHref("/logout"));
    assertNotNull(loggedIn.getAnchorByHref("/user/aliceW"));

    wc.goTo("logout");

    // Re-login
    login(wc);
  }
  private void login(WebClient wc) throws Exception {
    HtmlPage login = wc.goTo("federatedLoginService/openid/login?from=/");
    login
        .getDocumentElement()
        .getOneHtmlElementByAttribute("a", "title", "log in with OpenID")
        .click();
    HtmlForm loginForm = getFormById(login, "openid_form");
    loginForm.getInputByName("openid").setValueAttribute(openid.url);
    HtmlPage loggedIn = (HtmlPage) loginForm.submit();

    assertNotNull(loggedIn.getAnchorByHref("/logout"));
    assertNotNull(loggedIn.getAnchorByHref("/user/aliceW"));
  }
  private ClaimBuildAction applyClaimWithFailureCauseSelected(
      String element, String error, String reason, String description) throws Exception {
    HtmlPage page = whenNavigatingtoClaimPage();
    page.getElementById(element).click();
    HtmlForm form = page.getFormByName("claim");
    form.getTextAreaByName("reason").setText(reason);
    HtmlSelect select = form.getSelectByName("_.errors");
    HtmlOption option = select.getOptionByValue(error);
    select.setSelectedAttribute(option, true);

    assertEquals(description, form.getTextAreaByName("errordesc").getTextContent());

    form.submit((HtmlButton) j.last(form.getHtmlElementsByTagName("button")));

    ClaimBuildAction action = build.getAction(ClaimBuildAction.class);
    return action;
  }
Пример #5
0
  @Test
  @Issue("JENKINS-11543")
  public void unicodeParametersArePresetCorrectly() throws Exception {
    final FreeStyleProject p = j.createFreeStyleProject();
    ParametersDefinitionProperty pdb =
        new ParametersDefinitionProperty(
            new StringParameterDefinition("sname:a¶‱ﻷ", "svalue:a¶‱ﻷ", "sdesc:a¶‱ﻷ"),
            new FileParameterDefinition("fname:a¶‱ﻷ", "fdesc:a¶‱ﻷ"));
    p.addProperty(pdb);

    WebClient wc = j.createWebClient();
    wc.setThrowExceptionOnFailingStatusCode(false); // Ignore 405
    HtmlPage page = wc.getPage(p, "build");

    // java.lang.IllegalArgumentException: No such parameter definition: <gibberish>.
    wc.setThrowExceptionOnFailingStatusCode(true);
    final HtmlForm form = page.getFormByName("parameters");
    form.submit(form.getButtonByCaption("Build"));
  }