### Question:
OzoneBlockTokenSecretManager extends
    OzoneSecretManager<OzoneBlockTokenIdentifier> { public Token<OzoneBlockTokenIdentifier> generateToken(String user, String blockId, EnumSet<AccessModeProto> modes, long maxLength) { OzoneBlockTokenIdentifier tokenIdentifier = createIdentifier(user, blockId, modes, maxLength); if (LOG.isTraceEnabled()) { long expiryTime = tokenIdentifier.getExpiryDate(); String tokenId = tokenIdentifier.toString(); LOG.trace("Issued delegation token -> expiryTime:{}, tokenId:{}", expiryTime, tokenId); } return new Token<>(tokenIdentifier.getBytes(), createPassword(tokenIdentifier), tokenIdentifier.getKind(), new Text(blockId)); } OzoneBlockTokenSecretManager(SecurityConfig conf,
      long blockTokenExpirytime, String omCertSerialId); @Override OzoneBlockTokenIdentifier createIdentifier(); OzoneBlockTokenIdentifier createIdentifier(String owner,
      String blockId, EnumSet<AccessModeProto> modes, long maxLength); Token<OzoneBlockTokenIdentifier> generateToken(String user,
      String blockId, EnumSet<AccessModeProto> modes, long maxLength); Token<OzoneBlockTokenIdentifier> generateToken(String blockId,
      EnumSet<AccessModeProto> modes, long maxLength); @Override byte[] retrievePassword(OzoneBlockTokenIdentifier identifier); @Override long renewToken(Token<OzoneBlockTokenIdentifier> token,
      String renewer); @Override OzoneBlockTokenIdentifier cancelToken(Token<OzoneBlockTokenIdentifier>
      token, String canceller); boolean validateToken(OzoneBlockTokenIdentifier identifier); boolean verifySignature(OzoneBlockTokenIdentifier identifier,
      byte[] password); @Override synchronized void start(CertificateClient client); @Override synchronized void stop();  }### Answer:
@Test public void testGenerateToken() throws Exception { Token<OzoneBlockTokenIdentifier> token = secretManager.generateToken( "101", EnumSet.allOf(AccessModeProto.class), 100); OzoneBlockTokenIdentifier identifier = OzoneBlockTokenIdentifier.readFieldsProtobuf(new DataInputStream( new ByteArrayInputStream(token.getIdentifier()))); Assert.assertTrue(identifier.getBlockId().equals("101")); Assert.assertTrue(identifier.getAccessModes().equals(EnumSet .allOf(AccessModeProto.class))); Assert.assertTrue(identifier.getOmCertSerialId().equals(omCertSerialId)); validateHash(token.getPassword(), token.getIdentifier()); }
@Test public void testBlockTokenVerifier() throws Exception { String tokenBlockID = "101"; Token<OzoneBlockTokenIdentifier> token = secretManager.generateToken("testUser", tokenBlockID, EnumSet.allOf(AccessModeProto.class), 100); OzoneBlockTokenIdentifier btIdentifier = OzoneBlockTokenIdentifier.readFieldsProtobuf(new DataInputStream( new ByteArrayInputStream(token.getIdentifier()))); Assert.assertTrue(btIdentifier.getOwnerId().equals("testUser")); Assert.assertTrue(btIdentifier.getBlockId().equals("101")); Assert.assertTrue(btIdentifier.getAccessModes().equals(EnumSet .allOf(AccessModeProto.class))); Assert.assertTrue(btIdentifier.getOmCertSerialId().equals(omCertSerialId)); validateHash(token.getPassword(), btIdentifier.getBytes()); tokenVerifier.verify("testUser", token.encodeToUrlString(), ContainerProtos.Type.PutBlock, "101"); String notAllledBlockID = "NotAllowedBlockID"; LambdaTestUtils.intercept(BlockTokenException.class, "Token for block ID: " + tokenBlockID + " can't be used to access block: " + notAllledBlockID, () -> tokenVerifier.verify("testUser", token.encodeToUrlString(), ContainerProtos.Type.PutBlock, notAllledBlockID)); tokenVerifier.verify(null, null, ContainerProtos.Type.CloseContainer, null); }