use of org.apache.kafka.common.security.TestSecurityConfig in project kafka by apache.
the class AbstractConfigTest method testValuesWithPrefixAllOrNothing.
@Test
public void testValuesWithPrefixAllOrNothing() {
String prefix1 = "prefix1.";
String prefix2 = "prefix2.";
Properties props = new Properties();
props.put("sasl.mechanism", "PLAIN");
props.put("prefix1.sasl.mechanism", "GSSAPI");
props.put("prefix1.sasl.kerberos.kinit.cmd", "/usr/bin/kinit2");
props.put("prefix1.ssl.truststore.location", "my location");
props.put("sasl.kerberos.service.name", "service name");
props.put("ssl.keymanager.algorithm", "algorithm");
TestSecurityConfig config = new TestSecurityConfig(props);
Map<String, Object> valuesWithPrefixAllOrNothing1 = config.valuesWithPrefixAllOrNothing(prefix1);
// All prefixed values are there
assertEquals("GSSAPI", valuesWithPrefixAllOrNothing1.get("sasl.mechanism"));
assertEquals("/usr/bin/kinit2", valuesWithPrefixAllOrNothing1.get("sasl.kerberos.kinit.cmd"));
assertEquals("my location", valuesWithPrefixAllOrNothing1.get("ssl.truststore.location"));
// Non-prefixed values are missing
assertFalse(valuesWithPrefixAllOrNothing1.containsKey("sasl.kerberos.service.name"));
assertFalse(valuesWithPrefixAllOrNothing1.containsKey("ssl.keymanager.algorithm"));
Map<String, Object> valuesWithPrefixAllOrNothing2 = config.valuesWithPrefixAllOrNothing(prefix2);
assertTrue(valuesWithPrefixAllOrNothing2.containsKey("sasl.kerberos.service.name"));
assertTrue(valuesWithPrefixAllOrNothing2.containsKey("ssl.keymanager.algorithm"));
}
use of org.apache.kafka.common.security.TestSecurityConfig in project kafka by apache.
the class SslFactoryTest method testPemReconfiguration.
@Test
public void testPemReconfiguration() throws Exception {
Properties props = new Properties();
props.putAll(sslConfigsBuilder(Mode.SERVER).createNewTrustStore(null).usePem(true).build());
TestSecurityConfig sslConfig = new TestSecurityConfig(props);
SslFactory sslFactory = new SslFactory(Mode.SERVER);
sslFactory.configure(sslConfig.values());
SslEngineFactory sslEngineFactory = sslFactory.sslEngineFactory();
assertNotNull(sslEngineFactory, "SslEngineFactory not created");
props.put("some.config", "some.value");
sslConfig = new TestSecurityConfig(props);
sslFactory.reconfigure(sslConfig.values());
assertSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory recreated unnecessarily");
props.put(SslConfigs.SSL_KEYSTORE_KEY_CONFIG, new Password(((Password) props.get(SslConfigs.SSL_KEYSTORE_KEY_CONFIG)).value() + " "));
sslConfig = new TestSecurityConfig(props);
sslFactory.reconfigure(sslConfig.values());
assertNotSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory not recreated");
sslEngineFactory = sslFactory.sslEngineFactory();
props.put(SslConfigs.SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG, new Password(((Password) props.get(SslConfigs.SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG)).value() + " "));
sslConfig = new TestSecurityConfig(props);
sslFactory.reconfigure(sslConfig.values());
assertNotSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory not recreated");
sslEngineFactory = sslFactory.sslEngineFactory();
props.put(SslConfigs.SSL_TRUSTSTORE_CERTIFICATES_CONFIG, new Password(((Password) props.get(SslConfigs.SSL_TRUSTSTORE_CERTIFICATES_CONFIG)).value() + " "));
sslConfig = new TestSecurityConfig(props);
sslFactory.reconfigure(sslConfig.values());
assertNotSame(sslEngineFactory, sslFactory.sslEngineFactory(), "SslEngineFactory not recreated");
sslEngineFactory = sslFactory.sslEngineFactory();
}
Aggregations