-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring credential-cache for kerberized hive connector
- Loading branch information
1 parent
5b9d874
commit 5120f3f
Showing
24 changed files
with
609 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,19 @@ | |
package io.trino.hdfs.authentication; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.airlift.configuration.ConfigurationFactory; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import javax.validation.constraints.AssertTrue; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
|
||
import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping; | ||
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; | ||
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults; | ||
import static io.airlift.testing.ValidationAssertions.assertFailsValidation; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestHdfsKerberosConfig | ||
{ | ||
|
@@ -32,12 +35,13 @@ public void testDefaults() | |
{ | ||
assertRecordedDefaults(recordDefaults(HdfsKerberosConfig.class) | ||
.setHdfsTrinoPrincipal(null) | ||
.setHdfsTrinoKeytab(null)); | ||
.setHdfsTrinoKeytab(null) | ||
.setHdfsTrinoCredentialCacheLocation(null)); | ||
} | ||
|
||
@Test | ||
public void testExplicitPropertyMappings() | ||
throws IOException | ||
public void testExplicitPropertyMappingsForKeytab() | ||
throws Exception | ||
{ | ||
Path keytab = Files.createTempFile(null, null); | ||
|
||
|
@@ -46,10 +50,64 @@ public void testExplicitPropertyMappings() | |
.put("hive.hdfs.trino.keytab", keytab.toString()) | ||
.buildOrThrow(); | ||
|
||
ConfigurationFactory configurationFactory = new ConfigurationFactory(properties); | ||
HdfsKerberosConfig config = configurationFactory.build(HdfsKerberosConfig.class); | ||
|
||
HdfsKerberosConfig expected = new HdfsKerberosConfig() | ||
.setHdfsTrinoPrincipal("[email protected]") | ||
.setHdfsTrinoKeytab(keytab.toString()); | ||
|
||
assertFullMapping(properties, expected); | ||
assertThat(config.getHdfsTrinoPrincipal()) | ||
.isEqualTo(expected.getHdfsTrinoPrincipal()); | ||
assertThat(config.getHdfsTrinoKeytab()) | ||
.isEqualTo(expected.getHdfsTrinoKeytab()); | ||
} | ||
|
||
@Test | ||
public void testExplicitPropertyMappingsForCredentialCache() | ||
throws Exception | ||
{ | ||
Path credentialCacheLocation = Files.createTempFile("credentialCache", null); | ||
|
||
Map<String, String> properties = ImmutableMap.<String, String>builder() | ||
.put("hive.hdfs.trino.principal", "[email protected]") | ||
.put("hive.hdfs.trino.credential-cache.location", credentialCacheLocation.toString()) | ||
.buildOrThrow(); | ||
|
||
ConfigurationFactory configurationFactory = new ConfigurationFactory(properties); | ||
HdfsKerberosConfig config = configurationFactory.build(HdfsKerberosConfig.class); | ||
|
||
HdfsKerberosConfig expected = new HdfsKerberosConfig() | ||
.setHdfsTrinoPrincipal("[email protected]") | ||
.setHdfsTrinoCredentialCacheLocation(credentialCacheLocation.toString()); | ||
|
||
assertThat(config.getHdfsTrinoPrincipal()) | ||
.isEqualTo(expected.getHdfsTrinoPrincipal()); | ||
assertThat(config.getHdfsTrinoCredentialCacheLocation()) | ||
.isEqualTo(expected.getHdfsTrinoCredentialCacheLocation()); | ||
} | ||
|
||
@Test | ||
public void testValidation() | ||
throws Exception | ||
{ | ||
assertFailsValidation( | ||
new HdfsKerberosConfig() | ||
.setHdfsTrinoPrincipal("[email protected]"), | ||
"configValid", | ||
"Exactly one of `hive.hdfs.trino.keytab` or `hive.hdfs.trino.credential-cache.location` must be specified", | ||
AssertTrue.class); | ||
|
||
Path keytab = Files.createTempFile(null, null); | ||
Path credentialCacheLocation = Files.createTempFile("credentialCache", null); | ||
|
||
assertFailsValidation( | ||
new HdfsKerberosConfig() | ||
.setHdfsTrinoPrincipal("[email protected]") | ||
.setHdfsTrinoKeytab(keytab.toString()) | ||
.setHdfsTrinoCredentialCacheLocation(credentialCacheLocation.toString()), | ||
"configValid", | ||
"Exactly one of `hive.hdfs.trino.keytab` or `hive.hdfs.trino.credential-cache.location` must be specified", | ||
AssertTrue.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.