Skip to content

Commit

Permalink
Review Comments fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramahuja1001 committed Jul 1, 2024
1 parent 81faa78 commit 0ae320f
Showing 1 changed file with 17 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,91 +28,48 @@
import org.apache.hadoop.io.Text;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
import org.junit.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

public class TestAuthWithDigestMD5 {

private static final Logger LOG = LoggerFactory.getLogger(TestAuthWithDigestMD5.class.getName());
protected static HiveMetaStoreClient client;
public static final String HS2TOKEN = "HiveServer2ImpersonationToken";

protected static String correctUser = "correct_user";
protected static String correctPassword = "correct_passwd";

protected static Configuration conf = null;

private static MiniHiveKdc miniKDC = null;
protected static Configuration clientConf;
protected static String hiveMetastorePrincipal;
protected static String hiveMetastoreKeytab;
private static boolean isServerStarted = false;
protected static int port;
MiniHiveKdc miniKDC = null;
private static HiveMetaStoreClient client;
private static final String HS2TOKEN = "HiveServer2ImpersonationToken";
private static Configuration conf = null;

@Before
public void setUp() throws Exception {
miniKDC = new MiniHiveKdc();
hiveMetastorePrincipal =
miniKDC.getFullyQualifiedServicePrincipal(miniKDC.getHiveMetastoreServicePrincipal());
hiveMetastoreKeytab = miniKDC.getKeyTabFile(
String hiveMetastorePrincipal = miniKDC.getFullyQualifiedServicePrincipal(miniKDC.getHiveMetastoreServicePrincipal());
String hiveMetastoreKeytab = miniKDC.getKeyTabFile(
miniKDC.getServicePrincipalForUser(miniKDC.getHiveMetastoreServicePrincipal()));
conf = MetastoreConf.newMetastoreConf();

if (null == conf) {
conf = MetastoreConf.newMetastoreConf();
}
String correctUser = "correct_user";
String correctPassword = "correct_passwd";

MetastoreConf.setBoolVar(conf, ConfVars.EXECUTE_SET_UGI, false);
clientConf = new Configuration(conf);

MetastoreConf.setVar(conf, ConfVars.THRIFT_METASTORE_AUTHENTICATION, "CONFIG");
MetastoreConf.setVar(conf, ConfVars.THRIFT_AUTH_CONFIG_USERNAME, correctUser);
MetastoreConf.setVar(conf, ConfVars.THRIFT_AUTH_CONFIG_PASSWORD, correctPassword);
MetastoreConf.setBoolVar(conf, ConfVars.USE_THRIFT_SASL, true);
MetastoreConf.setVar(conf, ConfVars.KERBEROS_PRINCIPAL, hiveMetastorePrincipal);
MetastoreConf.setVar(conf, ConfVars.KERBEROS_KEYTAB_FILE, hiveMetastoreKeytab);

// set some values to use for getting conf. vars
MetastoreConf.setBoolVar(conf, ConfVars.METRICS_ENABLED, true);
conf.set("datanucleus.autoCreateTables", "false");
conf.set("hive.in.test", "true");
MetastoreConf.setVar(conf, ConfVars.METASTORE_METADATA_TRANSFORMER_CLASS, " ");

MetaStoreTestUtils.setConfForStandloneMode(conf);
MetastoreConf.setLongVar(conf, ConfVars.BATCH_RETRIEVE_MAX, 2);
MetastoreConf.setVar(conf, ConfVars.STORAGE_SCHEMA_READER_IMPL, "no.such.class");
MetastoreConf.setBoolVar(conf, ConfVars.INTEGER_JDO_PUSHDOWN, true);
MetastoreConf.setTimeVar(conf, ConfVars.DELEGATION_TOKEN_RENEW_INTERVAL,10000, TimeUnit.MILLISECONDS);
MetastoreConf.setTimeVar(conf, ConfVars.DELEGATION_TOKEN_GC_INTERVAL,3000, TimeUnit.MILLISECONDS);

if (isServerStarted) {
Assert.assertNotNull("Unable to connect to the MetaStore server", client);
return;
}
start();
}

protected void start() throws Exception {
port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(),
int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(),
conf);
System.out.println("Starting MetaStore Server on port " + port);
isServerStarted = true;

MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port);
MetastoreConf.setBoolVar(conf, ConfVars.EXECUTE_SET_UGI, false);

client = createClient();
client = new HiveMetaStoreClient(conf);
}

protected HiveMetaStoreClient createClient() throws Exception {
MetastoreConf.setVar(clientConf, ConfVars.KERBEROS_PRINCIPAL, hiveMetastorePrincipal);
MetastoreConf.setVar(clientConf, ConfVars.KERBEROS_KEYTAB_FILE, hiveMetastoreKeytab);
return new HiveMetaStoreClient(conf);
}

@Test
public void testPostRenewalTimeThreadKickedIn() throws Exception {
Expand All @@ -126,11 +83,13 @@ public void testPostRenewalTimeThreadKickedIn() throws Exception {
delegationToken.setService(new Text(HS2TOKEN));
UserGroupInformation.getCurrentUser().addToken(delegationToken);

LOG.info("Sleeping for 15 seconds");
Thread.sleep(15000);
LOG.info("Waking Up");

client = new HiveMetaStoreClient(conf);
}

@After
public void tearDown() {
miniKDC.shutDown();
}

}

0 comments on commit 0ae320f

Please sign in to comment.