Skip to content

Commit

Permalink
fix failed UT
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenSammi committed Nov 5, 2024
1 parent 74a8432 commit da72c3c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,24 +245,14 @@ public void testSecretKeyApiSuccess() throws Exception {
}

/**
* Verify API behavior when block token is not enable.
* Verify API behavior.
*/
@Test
public void testSecretKeyApiNotEnabled() throws Exception {
public void testSecretKeyApi() throws Exception {
startCluster(1);
SecretKeyProtocol secretKeyProtocol = getSecretKeyProtocol();

SCMSecretKeyException ex = assertThrows(SCMSecretKeyException.class,
secretKeyProtocol::getCurrentSecretKey);
assertEquals(SECRET_KEY_NOT_ENABLED, ex.getErrorCode());

ex = assertThrows(SCMSecretKeyException.class,
() -> secretKeyProtocol.getSecretKey(UUID.randomUUID()));
assertEquals(SECRET_KEY_NOT_ENABLED, ex.getErrorCode());

ex = assertThrows(SCMSecretKeyException.class,
secretKeyProtocol::getAllSecretKeys);
assertEquals(SECRET_KEY_NOT_ENABLED, ex.getErrorCode());
assertNull(secretKeyProtocol.getSecretKey(UUID.randomUUID()));
assertEquals(1, secretKeyProtocol.getAllSecretKeys().size());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClientTestImpl;
import org.apache.hadoop.minikdc.MiniKdc;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.client.SecretKeyTestClient;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
import org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory;
Expand Down Expand Up @@ -201,6 +202,7 @@ private void setupEnvironment(boolean aclEnabled,
om.setScmTopologyClient(new ScmTopologyClient(
new ScmBlockLocationTestingClient(null, null, 0)));
om.setCertClient(new CertificateClientTestImpl(conf));
om.setSecretKeyClient(new SecretKeyTestClient());
om.start();

// Get OM client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,9 @@ public NetworkTopology getClusterMap() {
@VisibleForTesting
public void setSecretKeyClient(SecretKeyClient secretKeyClient) {
this.secretKeyClient = secretKeyClient;
blockTokenMgr.setSecretKeyClient(secretKeyClient);
if (blockTokenMgr != null) {
blockTokenMgr.setSecretKeyClient(secretKeyClient);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.annotation.InterfaceStability;
Expand Down Expand Up @@ -107,6 +108,7 @@ public OzoneDelegationTokenSecretManager(Builder b) throws IOException {
OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY,
OMConfigKeys.OZONE_OM_RATIS_ENABLE_DEFAULT);
this.secretKeyClient = b.secretKeyClient;
Preconditions.checkNotNull(this.secretKeyClient);
loadTokenSecretState(store.loadState());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,6 @@ public void testVerifySignatureSuccess() throws Exception {
expiryTime, TOKEN_REMOVER_SCAN_INTERVAL);
secretManager.start(certificateClient);
OzoneTokenIdentifier id = new OzoneTokenIdentifier();
id.setOmCertSerialId(certificateClient.getCertificate()
.getSerialNumber().toString());
id.setMaxDate(Time.now() + 60 * 60 * 24);
id.setOwner(new Text("test"));
id.setSecretKeyId(secretKeyClient.getCurrentSecretKey().getId().toString());
Expand Down

0 comments on commit da72c3c

Please sign in to comment.