Exemple #1
0
  @Test
  public void testPutChangeConfig() throws Exception {
    // the test config starts off being setup for simple auth scheme, this test will update it for
    // DIGEST-MD5
    PlexusResource resource = getResource();

    LdapConnectionInfoResponse response = new LdapConnectionInfoResponse();
    LdapConnectionInfoDTO connectionInfo = new LdapConnectionInfoDTO();
    response.setData(connectionInfo);
    connectionInfo.setHost("localhost");
    connectionInfo.setPort(this.getLdapPort());
    connectionInfo.setSearchBase("o=sonatype");
    connectionInfo.setSystemPassword("secret");
    connectionInfo.setSystemUsername("admin");
    connectionInfo.setProtocol("ldap");
    connectionInfo.setAuthScheme("DIGEST-MD5");
    connectionInfo.setRealm("localhost");

    LdapConnectionInfoResponse result =
        (LdapConnectionInfoResponse) resource.put(null, null, null, response);
    this.validateConnectionDTO(connectionInfo, result.getData());

    // now how about that get
    result = (LdapConnectionInfoResponse) resource.get(null, null, null, null);
    this.validateConnectionDTO(connectionInfo, result.getData());
  }
  public void updateUserRoleTest() throws Exception {
    // first get the list of the previous users roles so we can make sure they change
    User jcoderXML = securitySystem.getUser("jcoder", SecurityXmlUserManager.SOURCE);
    User jcoderMock = securitySystem.getUser("jcoder", MockUserManager.SOURCE);

    List<String> jcoderXMLOriginalRoles = new ArrayList<String>();
    for (RoleIdentifier role : jcoderXML.getRoles()) {
      jcoderXMLOriginalRoles.add(role.getRoleId());
    }

    List<String> jcoderMockOriginalRoles = new ArrayList<String>();
    for (RoleIdentifier role : jcoderMock.getRoles()) {
      jcoderMockOriginalRoles.add(role.getRoleId());
    }

    // now update one... and check the other

    Request request = this.buildRequest();
    Response response = new Response(request);
    request.getAttributes().put(UserToRolePlexusResource.USER_ID_KEY, "jcoder");
    request.getAttributes().put(UserToRolePlexusResource.SOURCE_ID_KEY, MockUserManager.SOURCE);

    PlexusResource userToRoleResource =
        this.lookup(PlexusResource.class, "UserSearchPlexusResource");

    UserToRoleResourceRequest payload = new UserToRoleResourceRequest();
    payload.setData(new UserToRoleResource());
    payload.getData().setUserId("jcoder");
    payload.getData().setSource(MockUserManager.SOURCE);
    payload.getData().getRoles().add("admin");

    userToRoleResource.put(null, request, response, null);

    // the xml user should have the original roles the mock users should only have admin.

    jcoderXML = securitySystem.getUser("jcoder", SecurityXmlUserManager.SOURCE);
    jcoderMock = securitySystem.getUser("jcoder", MockUserManager.SOURCE);

    List<String> jcoderXMLNewRoles = new ArrayList<String>();
    for (RoleIdentifier role : jcoderXML.getRoles()) {
      jcoderXMLNewRoles.add(role.getRoleId());
    }

    List<String> jcoderMockNewRoles = new ArrayList<String>();
    for (RoleIdentifier role : jcoderMock.getRoles()) {
      jcoderMockNewRoles.add(role.getRoleId());
    }

    Assert.assertEquals(jcoderXMLOriginalRoles, jcoderXMLNewRoles);

    Assert.assertEquals(1, jcoderMockNewRoles.size());
    Assert.assertTrue(jcoderMockNewRoles.contains("admin"));
  }