예제 #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());
  }
예제 #2
0
  @Test
  public void testLdapConnectionInfoResponse() throws Exception {
    LdapConnectionInfoResponse resource = new LdapConnectionInfoResponse();
    LdapConnectionInfoDTO dto = new LdapConnectionInfoDTO();

    resource.setData(dto);

    dto.setAuthScheme("authScheme");
    dto.setHost("host");
    dto.setPort(123);
    dto.setProtocol("protocol");
    dto.setRealm("realm");
    dto.setSearchBase("searchBase");
    dto.setSystemPassword("systemPassword");
    dto.setSystemUsername("systemUsername");

    validateXmlHasNoPackageNames(resource);
  }
예제 #3
0
  @SuppressWarnings("unchecked")
  public void validateLdapConfig(LdapConnectionInfoDTO connInfo) throws Exception {
    CConnectionInfo fileConfig = LdapConfigurationUtil.getConfiguration().getConnectionInfo();
    Assert.assertEquals(connInfo.getAuthScheme(), fileConfig.getAuthScheme());
    Assert.assertEquals(connInfo.getHost(), fileConfig.getHost());
    Assert.assertEquals(connInfo.getPort(), fileConfig.getPort());
    Assert.assertEquals(connInfo.getProtocol(), fileConfig.getProtocol());
    Assert.assertEquals(connInfo.getRealm(), fileConfig.getRealm());
    Assert.assertEquals(connInfo.getSearchBase(), fileConfig.getSearchBase());
    Assert.assertEquals(connInfo.getSystemUsername(), fileConfig.getSystemUsername());

    // if the expectedPassword == null then the actual should be null
    if (connInfo.getSystemPassword() == null) {
      Assert.assertNull(fileConfig.getSystemPassword());
    } else {
      // make sure its not clear text
      Assert.assertNotSame(connInfo.getSystemPassword(), fileConfig.getSystemPassword());
      Assert.assertTrue(fileConfig.getSystemPassword().length() > 0);
    }
  }
예제 #4
0
  public void validateResourceResponse(LdapConnectionInfoDTO expected, LdapConnectionInfoDTO actual)
      throws Exception {
    Assert.assertEquals(expected.getAuthScheme(), actual.getAuthScheme());
    Assert.assertEquals(expected.getHost(), actual.getHost());
    Assert.assertEquals(expected.getPort(), actual.getPort());
    Assert.assertEquals(expected.getProtocol(), actual.getProtocol());
    Assert.assertEquals(expected.getRealm(), actual.getRealm());
    Assert.assertEquals(expected.getSearchBase(), actual.getSearchBase());
    Assert.assertEquals(expected.getSystemUsername(), actual.getSystemUsername());

    // if the expectedPassword == null then the actual should be null
    // if its anything else the actual password should be "--FAKE-PASSWORD--"
    if (expected.getSystemPassword() == null) {
      Assert.assertNull(actual.getSystemPassword());
    } else {
      Assert.assertEquals(LdapRealmPlexusResourceConst.FAKE_PASSWORD, actual.getSystemPassword());
    }

    // also validate the file config
    this.validateLdapConfig(expected);
  }