5959import org .apache .hadoop .security .token .Token ;
6060import org .apache .hadoop .util .Time ;
6161
62- import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_RATIS_ENABLE_KEY ;
6362import static org .apache .hadoop .ozone .protocol .proto .OzoneManagerProtocolProtos .OMTokenProto .Type .S3AUTHINFO ;
6463import static org .assertj .core .api .Assertions .assertThat ;
6564import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -132,14 +131,6 @@ public void setUp() throws Exception {
132131
133132 private OzoneConfiguration createNewTestPath () throws IOException {
134133 OzoneConfiguration config = new OzoneConfiguration ();
135- // When ratis is enabled, tokens are not updated to the store directly by
136- // OzoneDelegationTokenSecretManager. Tokens are updated via Ratis
137- // through the DoubleBuffer. Hence, to test
138- // OzoneDelegationTokenSecretManager, we should disable OM Ratis.
139- // TODO: Once HA and non-HA code paths are merged in
140- // OzoneDelegationTokenSecretManager, this test should be updated to
141- // test both ratis enabled and disabled case.
142- config .setBoolean (OZONE_OM_RATIS_ENABLE_KEY , false );
143134 File newFolder = folder .toFile ();
144135 if (!newFolder .exists ()) {
145136 assertTrue (newFolder .mkdirs ());
@@ -257,13 +248,15 @@ private void testRenewTokenSuccessHelper(boolean restartSecretManager)
257248 Token <OzoneTokenIdentifier > token = secretManager .createToken (TEST_USER ,
258249 TEST_USER ,
259250 TEST_USER );
251+ addToTokenStore (token );
260252 Thread .sleep (10 * 5 );
261253
262254 if (restartSecretManager ) {
263255 restartSecretManager ();
264256 }
265257
266258 long renewalTime = secretManager .renewToken (token , TEST_USER .toString ());
259+ addToTokenStore (token );
267260 assertThat (renewalTime ).isGreaterThan (0 );
268261 }
269262
@@ -287,6 +280,7 @@ public void testRenewTokenFailure() throws Exception {
287280 secretManager .start (certificateClient );
288281 Token <OzoneTokenIdentifier > token = secretManager .createToken (TEST_USER ,
289282 TEST_USER , TEST_USER );
283+ addToTokenStore (token );
290284 AccessControlException exception =
291285 assertThrows (AccessControlException .class ,
292286 () -> secretManager .renewToken (token , "rougeUser" ));
@@ -354,6 +348,7 @@ public void testCancelTokenSuccess() throws Exception {
354348 secretManager .start (certificateClient );
355349 Token <OzoneTokenIdentifier > token = secretManager .createToken (TEST_USER ,
356350 TEST_USER , TEST_USER );
351+ addToTokenStore (token );
357352 secretManager .cancelToken (token , TEST_USER .toString ());
358353 }
359354
@@ -512,4 +507,11 @@ private void validateHash(byte[] hash, byte[] identifier) throws Exception {
512507 .setSecretKeyClient (secretKeyClient )
513508 .build ();
514509 }
510+
511+ private void addToTokenStore (Token <OzoneTokenIdentifier > token ) throws IOException {
512+ OzoneTokenIdentifier ozoneTokenIdentifier = OzoneTokenIdentifier .
513+ readProtoBuf (token .getIdentifier ());
514+ long renewDate = secretManager .updateToken (token , ozoneTokenIdentifier , expiryTime );
515+ om .getMetadataManager ().getDelegationTokenTable ().put (ozoneTokenIdentifier , renewDate );
516+ }
515517}
0 commit comments