Package org.sonatype.nexus.integrationtests

Examples of org.sonatype.nexus.integrationtests.TestContext


  @Test
  public void createUser()
      throws Exception
  {
    TestContext testContext = TestContainer.getInstance().getTestContext();
    testContext.useAdminForRequests();

    // create user,
    UserResource resource = new UserResource();
    resource.setUserId(USER_ID);
    resource.setFirstName("Marvin Velo");
    resource.setEmail("velo@earth.com");
    resource.setStatus("active");
    resource.addRole("nx-admin");
    userUtil.createUser(resource);

    // get email
    // two e-mails (first confirming user creating and second with users pw)
    emailServerHelper.waitForMail(2);
    Thread.sleep(1000); //w8 a few more

    MimeMessage[] msgs = emailServerHelper.getReceivedMessages();
    String password = null;
    StringBuilder emailsContent = new StringBuilder();

    /// make sure we have at least 1 message
    Assert.assertTrue("No emails recieved.", msgs.length > 0);

    for (MimeMessage mimeMessage : msgs) {
      emailsContent.append(GreenMailUtil.getHeaders(mimeMessage)).append('\n');

      // Sample body: Your new password is ********
      String body = GreenMailUtil.getBody(mimeMessage);
      emailsContent.append(body).append('\n').append('\n');

      int index = body.indexOf("Your new password is ");
      int passwordStartIndex = index + "Your new password is ".length();
      if (index != -1) {
        password = body.substring(passwordStartIndex, body.indexOf('\n', passwordStartIndex)).trim();
        log.debug("New password:\n" + password);
        break;
      }
    }

    Assert.assertNotNull(password, "Didn't recieve a password.  Got the following messages:\n" + emailsContent);

    // login with generated password
    testContext.setUsername(USER_ID);
    testContext.setPassword(password);
    Status status = UserCreationUtil.login();
    Assert.assertTrue(status.isSuccess());

    // set new password
    String newPassword = "velo123";
    status = ChangePasswordUtils.changePassword(USER_ID, password, newPassword);
    Assert.assertTrue(status.isSuccess());

    // check if the user is 'active'
    testContext.useAdminForRequests();
    UserResource user = userUtil.getUser(USER_ID);
    Assert.assertEquals(user.getStatus(), "active");

    // login with new password
    testContext.setUsername(USER_ID);
    testContext.setPassword(newPassword);
    status = UserCreationUtil.login();
    Assert.assertTrue(status.isSuccess());
  }
View Full Code Here


  @Test
  public void changePasswordAndReboot() throws Exception {
    this.giveUserRole(TEST_USER_NAME, "nx-admin");

    TestContext context = TestContainer.getInstance().getTestContext();

    context.setUsername(TEST_USER_NAME);
    context.setPassword(TEST_USER_PASSWORD);


    String newPassword = "123password";
    Status status = ChangePasswordUtils.changePassword(TEST_USER_NAME, TEST_USER_PASSWORD, newPassword);
    Assert.assertTrue("Status: ", status.isSuccess());

    // now change the password
    context.setPassword(newPassword);

    // reboot
    restartNexus();

    // now we can verify everything worked out
View Full Code Here

  @Test
  public void loginExternalUser()
      throws Exception
  {
    TestContext testContext = TestContainer.getInstance().getTestContext();

    RoleResource role = new RoleResource();
    role.setId("role-123");
    role.setName("Role role-123");
    role.setDescription("Role role-123 external map");
    role.setSessionTimeout(60);
    role.addRole("nx-admin");
    testContext.useAdminForRequests();
    roleUtil.createRole(role);

    testContext.setUsername("admin-simple");
    testContext.setPassword("admin123");
    assertThat(UserCreationUtil.login(), isSuccess());
  }
View Full Code Here

  public void testCookieForStateFullClient()
      throws Exception
  {
    setAnonymousAccess(false);

    TestContext context = TestContainer.getInstance().getTestContext();
    String username = context.getAdminUsername();
    String password = context.getPassword();
    String url = this.getBaseNexusUrl() + "content/";
    URI nexusBaseURI = new URI(url);

    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "SomeUAThatWillMakeMeLookStateful/1.0");
View Full Code Here

   * Makes a request after setting the user agent and verifies that the session cookie is NOT set.
   */
  private void testCookieNotSetForKnownStateLessClients(final String userAgent)
      throws Exception
  {
    TestContext context = TestContainer.getInstance().getTestContext();
    String username = context.getAdminUsername();
    String password = context.getPassword();
    String url = this.getBaseNexusUrl() + "content/";
    URI uri = new URI(url);

    Header header = new BasicHeader("User-Agent", userAgent + "/1.6"); // user agent plus some version

View Full Code Here

  }

  public static final String ADMIN_ROLE = "nx-admin";

  private <T> T invokeAsAdministrator(final Callable<T> callable) throws Exception {
    final TestContext ctx = TestContainer.getInstance().getTestContext();
    final String username = ctx.getUsername();
    final String password = ctx.getPassword();
    final boolean secure = ctx.isSecureTest();
    ctx.useAdminForRequests();
    ctx.setSecureTest(true);

    try {
      return callable.call();
    }
    finally {
      ctx.setUsername(username);
      ctx.setPassword(password);
      ctx.setSecureTest(secure);
    }
  }
View Full Code Here

  @Before
  public void setSecureTest()
      throws IOException
  {
    TestContext ctx = TestContainer.getInstance().getTestContext();
    ctx.setSecureTest(true);
    ctx.setUsername("test");
    ctx.setPassword("test");
  }
View Full Code Here

  @Test
  public void test()
      throws Exception
  {
    // use admin
    TestContext testContext = TestContainer.getInstance().getTestContext();

    // user is created at security.xml

    testContext.setUsername(NEXUS504_USER);
    testContext.setPassword(TEST_USER_PASSWORD);

    assertThat(UserCreationUtil.login(), hasStatusCode(403));

    // add login privilege to role
    testContext.useAdminForRequests();

    RoleResource role = roleUtil.getRole(NEXUS504_ROLE);
    role.addPrivilege("2"/* login */);
    assertThat("Unable to add login privilege to role " + NEXUS504_ROLE + "\n"
        + RoleMessageUtil.update(role).getDescription(), RoleMessageUtil.update(role), isSuccess());

    // try to login again
    testContext.setUsername(NEXUS504_USER);
    testContext.setPassword(TEST_USER_PASSWORD);
    Status status2 = UserCreationUtil.login();
    assertThat(status2, hasStatusCode(200));
  }
View Full Code Here

   */
  @Test
  public void testLogout()
      throws Exception
  {
    TestContext context = TestContainer.getInstance().getTestContext();
    String username = context.getAdminUsername();
    String password = context.getPassword();
    String url = this.getBaseNexusUrl() + RequestFacade.SERVICE_LOCAL + "status";
    String logoutUrl = this.getBaseNexusUrl() + RequestFacade.SERVICE_LOCAL + "authentication/logout";

    Header userAgentHeader = new BasicHeader("User-Agent", "Something Stateful");

View Full Code Here

                              final String artifactPath)
      throws Exception
  {
    checkState(wagonFactory != null, "Wagon factory must be provided to be able to deploy");

    final TestContext testContext = nexusRestClient.getTestContext();
    final Wagon wagon = wagonFactory.get(wagonHint);

    String username = null;
    String password = null;

    if (testContext.isSecureTest()) {
      username = testContext.getUsername();
      password = testContext.getPassword();
    }

    new WagonDeployer(
        wagon, wagonHint, username, password, repositoryUrl, fileToDeploy, artifactPath,
        nexusRestClient.getTestContext()).deploy();
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.integrationtests.TestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.