示例#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 testSearchUsers() throws Exception {
    // now we should have two jcoders, one from the mock and one from the XML realm

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

    Request request = this.buildRequest();
    request.getAttributes().put(UserSearchPlexusResource.USER_SOURCE_KEY, "all");
    request.getAttributes().put(UserSearchPlexusResource.USER_ID_KEY, "jcoder");

    List<PlexusUserResource> result =
        ((PlexusUserListResourceResponse) userSearchResource.get(null, request, null, null))
            .getData();

    // now make sure we have 2 jcoders
    PlexusUserResource jcoderXML = null;
    PlexusUserResource jcoderMock = null;

    for (PlexusUserResource plexusUserResource : result) {
      if (plexusUserResource.getUserId().equals("jcoder")) {
        if (plexusUserResource.getSource().endsWith(SecurityXmlUserManager.SOURCE)) {
          jcoderXML = plexusUserResource;
        } else if (plexusUserResource.getSource().endsWith(MockUserManager.SOURCE)) {
          jcoderMock = plexusUserResource;
        } else {
          Assert.fail(
              "found a jcoder with an unknown source of: " + plexusUserResource.getSource());
        }
      }
    }

    Assert.assertNotNull("jcoderXML is null", jcoderXML);
    Assert.assertNotNull("jcoderMock is null", jcoderMock);
  }