Skip to content

Commit

Permalink
HDDS-11869. Enable OM Ratis in TestOzoneDelegationTokenSecretManager (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
chungen0126 authored Dec 19, 2024
1 parent 4fe166d commit 0066526
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.util.Time;

import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY;
import static org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMTokenProto.Type.S3AUTHINFO;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -132,14 +131,6 @@ public void setUp() throws Exception {

private OzoneConfiguration createNewTestPath() throws IOException {
OzoneConfiguration config = new OzoneConfiguration();
// When ratis is enabled, tokens are not updated to the store directly by
// OzoneDelegationTokenSecretManager. Tokens are updated via Ratis
// through the DoubleBuffer. Hence, to test
// OzoneDelegationTokenSecretManager, we should disable OM Ratis.
// TODO: Once HA and non-HA code paths are merged in
// OzoneDelegationTokenSecretManager, this test should be updated to
// test both ratis enabled and disabled case.
config.setBoolean(OZONE_OM_RATIS_ENABLE_KEY, false);
File newFolder = folder.toFile();
if (!newFolder.exists()) {
assertTrue(newFolder.mkdirs());
Expand Down Expand Up @@ -257,13 +248,15 @@ private void testRenewTokenSuccessHelper(boolean restartSecretManager)
Token<OzoneTokenIdentifier> token = secretManager.createToken(TEST_USER,
TEST_USER,
TEST_USER);
addToTokenStore(token);
Thread.sleep(10 * 5);

if (restartSecretManager) {
restartSecretManager();
}

long renewalTime = secretManager.renewToken(token, TEST_USER.toString());
addToTokenStore(token);
assertThat(renewalTime).isGreaterThan(0);
}

Expand All @@ -287,6 +280,7 @@ public void testRenewTokenFailure() throws Exception {
secretManager.start(certificateClient);
Token<OzoneTokenIdentifier> token = secretManager.createToken(TEST_USER,
TEST_USER, TEST_USER);
addToTokenStore(token);
AccessControlException exception =
assertThrows(AccessControlException.class,
() -> secretManager.renewToken(token, "rougeUser"));
Expand Down Expand Up @@ -354,6 +348,7 @@ public void testCancelTokenSuccess() throws Exception {
secretManager.start(certificateClient);
Token<OzoneTokenIdentifier> token = secretManager.createToken(TEST_USER,
TEST_USER, TEST_USER);
addToTokenStore(token);
secretManager.cancelToken(token, TEST_USER.toString());
}

Expand Down Expand Up @@ -512,4 +507,11 @@ private void validateHash(byte[] hash, byte[] identifier) throws Exception {
.setSecretKeyClient(secretKeyClient)
.build();
}

private void addToTokenStore(Token<OzoneTokenIdentifier> token) throws IOException {
OzoneTokenIdentifier ozoneTokenIdentifier = OzoneTokenIdentifier.
readProtoBuf(token.getIdentifier());
long renewDate = secretManager.updateToken(token, ozoneTokenIdentifier, expiryTime);
om.getMetadataManager().getDelegationTokenTable().put(ozoneTokenIdentifier, renewDate);
}
}

0 comments on commit 0066526

Please sign in to comment.