Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions hadoop-client-modules/hadoop-client-minicluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
<artifactId>hadoop-client-runtime</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Leave JUnit as a direct dependency -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Adding hadoop-annotations so we can make it optional to remove from our transitive tree -->
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand Down Expand Up @@ -629,6 +623,10 @@
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
Expand All @@ -640,6 +638,10 @@
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
Expand Down
20 changes: 20 additions & 0 deletions hadoop-common-project/hadoop-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.client.ZKClientConfig;
import org.apache.zookeeper.common.ClientX509Util;
import org.hamcrest.Matcher;
import org.hamcrest.core.IsNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
Expand All @@ -35,10 +33,7 @@

import java.util.Arrays;

import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.ArgumentMatchers.isA;
Expand Down Expand Up @@ -219,14 +214,18 @@ public void testSSLConfiguration() {
verify(cfBuilder).zkClientConfig(clientConfCaptor.capture());
ZKClientConfig conf = clientConfCaptor.getValue();

assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT), is("true"));
assertThat(conf.getProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET),
is("org.apache.zookeeper.ClientCnxnSocketNetty"));
assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT)).isEqualTo("true");
assertThat(conf.getProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET))
.isEqualTo("org.apache.zookeeper.ClientCnxnSocketNetty");
try (ClientX509Util sslOpts = new ClientX509Util()) {
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty()), is("keystoreLoc"));
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty()), is("ksPass"));
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty()), is("truststoreLoc"));
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty()), is("tsPass"));
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty()))
.isEqualTo("keystoreLoc");
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty()))
.isEqualTo("ksPass");
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty()))
.isEqualTo("truststoreLoc");
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty()))
.isEqualTo("tsPass");
}

verifyDummyConnectionString();
Expand All @@ -244,39 +243,39 @@ public void testNoConnectionString(){
clientConfigurer.withConnectionString(null);

Throwable t = assertThrows(NullPointerException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), containsString("Zookeeper connection string cannot be null!"));
assertThat(t.getMessage()).contains("Zookeeper connection string cannot be null!");
}

@Test
public void testNoRetryPolicy() {
clientConfigurer.withRetryPolicy(null);

Throwable t = assertThrows(NullPointerException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), containsString("Zookeeper connection retry policy cannot be null!"));
assertThat(t.getMessage()).contains("Zookeeper connection retry policy cannot be null!");
}

@Test
public void testNoAuthType() {
clientConfigurer.withAuthType(null);

Throwable t = assertThrows(NullPointerException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), containsString("Zookeeper authType cannot be null!"));
assertThat(t.getMessage()).contains("Zookeeper authType cannot be null!");
}

@Test
public void testUnrecognizedAuthType() {
clientConfigurer.withAuthType("something");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), is("Zookeeper authType must be one of [none, sasl]!"));
assertThat(t.getMessage()).isEqualTo("Zookeeper authType must be one of [none, sasl]!");
}

@Test
public void testSaslAuthTypeWithoutKeytab() {
clientConfigurer.withAuthType("sasl");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Keytab must be specified!"));
assertThat(t.getMessage()).isEqualTo("Zookeeper client's Kerberos Keytab must be specified!");
}

@Test
Expand All @@ -286,7 +285,8 @@ public void testSaslAuthTypeWithEmptyKeytab() {
.withKeytab("");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Keytab must be specified!"));

assertThat(t.getMessage()).isEqualTo("Zookeeper client's Kerberos Keytab must be specified!");
}

@Test
Expand All @@ -296,7 +296,8 @@ public void testSaslAuthTypeWithoutPrincipal() {
.withKeytab("keytabLoc");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Principal must be specified!"));
assertThat(t.getMessage()).isEqualTo(
"Zookeeper client's Kerberos Principal must be specified!");
}

@Test
Expand All @@ -307,7 +308,8 @@ public void testSaslAuthTypeWithEmptyPrincipal() {
.withPrincipal("");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), is("Zookeeper client's Kerberos Principal must be specified!"));
assertThat(t.getMessage()).isEqualTo(
"Zookeeper client's Kerberos Principal must be specified!");
}

@Test
Expand All @@ -319,7 +321,7 @@ public void testSaslAuthTypeWithoutJaasLoginEntryName() {
.withJaasLoginEntryName(null);

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), is("JAAS Login Entry name must be specified!"));
assertThat(t.getMessage()).isEqualTo("JAAS Login Entry name must be specified!");
}

@Test
Expand All @@ -331,7 +333,7 @@ public void testSaslAuthTypeWithEmptyJaasLoginEntryName() {
.withJaasLoginEntryName("");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(), is("JAAS Login Entry name must be specified!"));
assertThat(t.getMessage()).isEqualTo("JAAS Login Entry name must be specified!");
}

@Test
Expand All @@ -340,8 +342,8 @@ public void testSSLWithoutKeystore() {
.enableSSL(true);

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(),
is("The keystore location parameter is empty for the ZooKeeper client connection."));
assertThat(t.getMessage()).isEqualTo(
"The keystore location parameter is empty for the ZooKeeper client connection.");
}

@Test
Expand All @@ -351,8 +353,8 @@ public void testSSLWithEmptyKeystore() {
.withKeystore("");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(),
is("The keystore location parameter is empty for the ZooKeeper client connection."));
assertThat(t.getMessage()).isEqualTo(
"The keystore location parameter is empty for the ZooKeeper client connection.");
}

@Test
Expand All @@ -362,8 +364,8 @@ public void testSSLWithoutTruststore() {
.withKeystore("keyStoreLoc");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(),
is("The truststore location parameter is empty for the ZooKeeper client connection."));
assertThat(t.getMessage()).isEqualTo(
"The truststore location parameter is empty for the ZooKeeper client connection.");
}

@Test
Expand All @@ -374,8 +376,8 @@ public void testSSLWithEmptyTruststore() {
.withTruststore("");

Throwable t = assertThrows(IllegalArgumentException.class, () -> clientConfigurer.create());
assertThat(t.getMessage(),
is("The truststore location parameter is empty for the ZooKeeper client connection."));
assertThat(t.getMessage()).isEqualTo(
"The truststore location parameter is empty for the ZooKeeper client connection.");
}

private void testSaslAuthType(String vendor) {
Expand All @@ -395,36 +397,39 @@ private void testSaslAuthType(String vendor) {
verify(cfBuilder).aclProvider(aclProviderCaptor.capture());
SASLOwnerACLProvider aclProvider = aclProviderCaptor.getValue();

assertThat(aclProvider.getDefaultAcl().size(), is(1));
assertThat(aclProvider.getDefaultAcl().get(0).getId().getScheme(), is("sasl"));
assertThat(aclProvider.getDefaultAcl().get(0).getId().getId(), is("principal"));
assertThat(aclProvider.getDefaultAcl().get(0).getPerms(), is(ZooDefs.Perms.ALL));
assertThat(aclProvider.getDefaultAcl().size()).isEqualTo(1);
assertThat(aclProvider.getDefaultAcl().get(0).getId().getScheme()).isEqualTo("sasl");
assertThat(aclProvider.getDefaultAcl().get(0).getId().getId()).isEqualTo("principal");
assertThat(aclProvider.getDefaultAcl().get(0).getPerms()).isEqualTo(ZooDefs.Perms.ALL);

Arrays.stream(new String[] {"/", "/foo", "/foo/bar/baz", "/random/path"})
.forEach(s -> {
assertThat(aclProvider.getAclForPath(s).size(), is(1));
assertThat(aclProvider.getAclForPath(s).get(0).getId().getScheme(), is("sasl"));
assertThat(aclProvider.getAclForPath(s).get(0).getId().getId(), is("principal"));
assertThat(aclProvider.getAclForPath(s).get(0).getPerms(), is(ZooDefs.Perms.ALL));
assertThat(aclProvider.getAclForPath(s).size()).isEqualTo(1);
assertThat(aclProvider.getAclForPath(s).get(0).getId().getScheme()).isEqualTo("sasl");
assertThat(aclProvider.getAclForPath(s).get(0).getId().getId()).isEqualTo("principal");
assertThat(aclProvider.getAclForPath(s).get(0).getPerms()).isEqualTo(ZooDefs.Perms.ALL);
});

assertThat(System.getProperty(ZKClientConfig.LOGIN_CONTEXT_NAME_KEY), is("TestEntry"));
assertThat(System.getProperty("zookeeper.authProvider.1"),
is("org.apache.zookeeper.server.auth.SASLAuthenticationProvider"));
assertThat(System.getProperty(ZKClientConfig.LOGIN_CONTEXT_NAME_KEY)).isEqualTo("TestEntry");
assertThat(System.getProperty("zookeeper.authProvider.1")).isEqualTo(
"org.apache.zookeeper.server.auth.SASLAuthenticationProvider");

Configuration config = Configuration.getConfiguration();
assertThat(config.getAppConfigurationEntry("TestEntry").length, is(1));
assertThat(config.getAppConfigurationEntry("TestEntry").length).isEqualTo(1);
AppConfigurationEntry entry = config.getAppConfigurationEntry("TestEntry")[0];
assertThat(entry.getOptions().get("keyTab"), is("keytabLoc"));
assertThat(entry.getOptions().get("principal"), is("principal@some.host/SOME.REALM"));
assertThat(entry.getOptions().get("useKeyTab"), is("true"));
assertThat(entry.getOptions().get("storeKey"), is("true"));
assertThat(entry.getOptions().get("useTicketCache"), is("false"));
assertThat(entry.getOptions().get("refreshKrb5Config"), is("true"));
assertThat(entry.getOptions().get("keyTab")).isEqualTo("keytabLoc");
assertThat(entry.getOptions().get("principal")).isEqualTo("principal@some.host/SOME.REALM");
assertThat(entry.getOptions().get("useKeyTab")).isEqualTo("true");
assertThat(entry.getOptions().get("storeKey")).isEqualTo("true");
assertThat(entry.getOptions().get("useTicketCache")).isEqualTo("false");
assertThat(entry.getOptions().get("refreshKrb5Config")).isEqualTo("true");

if (System.getProperty("java.vendor").contains("IBM")){
assertThat(entry.getLoginModuleName(), is("com.ibm.security.auth.module.Krb5LoginModule"));
assertThat(entry.getLoginModuleName()).isEqualTo(
"com.ibm.security.auth.module.Krb5LoginModule");
} else {
assertThat(entry.getLoginModuleName(), is("com.sun.security.auth.module.Krb5LoginModule"));
assertThat(entry.getLoginModuleName()).isEqualTo(
"com.sun.security.auth.module.Krb5LoginModule");
}
} finally {
Configuration.setConfiguration(origConf);
Expand Down Expand Up @@ -465,8 +470,8 @@ private void verifyDefaultRetryPolicy() {
verify(cfBuilder).retryPolicy(retry.capture());
ExponentialBackoffRetry policy = retry.getValue();

assertThat(policy.getBaseSleepTimeMs(), is(1000));
assertThat(policy.getN(), is(3));
assertThat(policy.getBaseSleepTimeMs()).isEqualTo(1000);
assertThat(policy.getN()).isEqualTo(3);
}

private void verifyDefaultAclProvider() {
Expand All @@ -478,21 +483,16 @@ private void verifyDefaultZKClientConfig() {
verify(cfBuilder).zkClientConfig(clientConfCaptor.capture());
ZKClientConfig conf = clientConfCaptor.getValue();

assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT), isEmptyOrFalse());
assertThat(conf.getProperty(ZKClientConfig.SECURE_CLIENT))
.satisfiesAnyOf(value -> assertThat(value).isNullOrEmpty(),
value -> assertThat(value).isEqualTo("false"));

try (ClientX509Util sslOpts = new ClientX509Util()) {
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty()), isEmpty());
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty()), isEmpty());
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty()), isEmpty());
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty()), isEmpty());
assertThat(conf.getProperty(sslOpts.getSslKeystoreLocationProperty())).isNullOrEmpty();
assertThat(conf.getProperty(sslOpts.getSslKeystorePasswdProperty())).isNullOrEmpty();
assertThat(conf.getProperty(sslOpts.getSslTruststoreLocationProperty())).isNullOrEmpty();
assertThat(conf.getProperty(sslOpts.getSslTruststorePasswdProperty())).isNullOrEmpty();
}
}

private Matcher<String> isEmptyOrFalse() {
return anyOf(isEmpty(), is("false"));
}

private Matcher<String> isEmpty() {
return anyOf(new IsNull<>(), is(""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2610,12 +2610,6 @@ public void testGettingPropertiesWithPrefix() throws Exception {
assertTrue(prefixedProps.isEmpty());
}

public static void main(String[] argv) throws Exception {
junit.textui.TestRunner.main(new String[]{
TestConfiguration.class.getName()
});
}

@Test
public void testGetAllPropertiesByTags() throws Exception {

Expand Down
5 changes: 0 additions & 5 deletions hadoop-common-project/hadoop-minikdc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
<artifactId>slf4j-reload4j</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Loading