@Test @RunWithCustomExecutor public void testVerifyMerkleTreeWithIncorrectTraceabilityEventThenFATAL() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); in = new ArrayList<>(); in.add(new IOParameter() .setUri(new ProcessingUri(UriPrefix.MEMORY, "TraceabilityOperationDetails/EVENT_DETAIL_DATA.json"))); handlerIO.addOutIOParameters(in); handlerIO.addOutputResult(0, PropertiesUtils.getResourceFile(FAKE_DETAIL_EVENT_TRACEABILITY), false); handlerIO.reset(); handlerIO.addInIOParameters(in); verifyMerkleTreeActionHandler = new VerifyMerkleTreeActionHandler(); final ItemStatus response = verifyMerkleTreeActionHandler.execute(params, handlerIO); assertEquals(StatusCode.FATAL, response.getGlobalStatus()); }
@Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream operationsInputStream = null; try { TraceabilityEvent traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK), TraceabilityEvent.class); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + DATA_FILE; operationsInputStream = handler.getInputStreamFromWorkspace(operationFilePath); MerkleTreeAlgo merkleTreeAlgo = computeMerkleTree(operationsInputStream); final String currentRootHash = currentRootHash(merkleTreeAlgo); final ItemStatus subSecuredItem = compareToSecuredHash( handler, currentRootHash); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_SAVED_HASH, subSecuredItem); final ItemStatus subLoggedItemStatus = compareToLoggedHash(params, currentRootHash, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_INDEXED_HASH, subLoggedItemStatus); } catch (Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(operationsInputStream); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }
VerifyMerkleTreeActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream operationsInputStream = null; try { TraceabilityEvent traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK), TraceabilityEvent.class); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + DATA_FILE; operationsInputStream = handler.getInputStreamFromWorkspace(operationFilePath); MerkleTreeAlgo merkleTreeAlgo = computeMerkleTree(operationsInputStream); final String currentRootHash = currentRootHash(merkleTreeAlgo); final ItemStatus subSecuredItem = compareToSecuredHash( handler, currentRootHash); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_SAVED_HASH, subSecuredItem); final ItemStatus subLoggedItemStatus = compareToLoggedHash(params, currentRootHash, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_INDEXED_HASH, subLoggedItemStatus); } catch (Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(operationsInputStream); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); } }
VerifyMerkleTreeActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream operationsInputStream = null; try { TraceabilityEvent traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK), TraceabilityEvent.class); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + DATA_FILE; operationsInputStream = handler.getInputStreamFromWorkspace(operationFilePath); MerkleTreeAlgo merkleTreeAlgo = computeMerkleTree(operationsInputStream); final String currentRootHash = currentRootHash(merkleTreeAlgo); final ItemStatus subSecuredItem = compareToSecuredHash( handler, currentRootHash); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_SAVED_HASH, subSecuredItem); final ItemStatus subLoggedItemStatus = compareToLoggedHash(params, currentRootHash, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_INDEXED_HASH, subLoggedItemStatus); } catch (Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(operationsInputStream); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }  }
VerifyMerkleTreeActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream operationsInputStream = null; try { TraceabilityEvent traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK), TraceabilityEvent.class); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + DATA_FILE; operationsInputStream = handler.getInputStreamFromWorkspace(operationFilePath); MerkleTreeAlgo merkleTreeAlgo = computeMerkleTree(operationsInputStream); final String currentRootHash = currentRootHash(merkleTreeAlgo); final ItemStatus subSecuredItem = compareToSecuredHash( handler, currentRootHash); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_SAVED_HASH, subSecuredItem); final ItemStatus subLoggedItemStatus = compareToLoggedHash(params, currentRootHash, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_INDEXED_HASH, subLoggedItemStatus); } catch (Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(operationsInputStream); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }  static String getId(); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler); static MerkleTreeAlgo computeMerkleTree(InputStream inputStream); @Override void checkMandatoryIOParameter(HandlerIO handler); }
VerifyMerkleTreeActionHandler extends ActionHandler { @Override public ItemStatus execute(WorkerParameters params, HandlerIO handler) { final ItemStatus itemStatus = new ItemStatus(HANDLER_ID); InputStream operationsInputStream = null; try { TraceabilityEvent traceabilityEvent = JsonHandler.getFromFile((File) handler.getInput(TRACEABILITY_EVENT_DETAIL_RANK), TraceabilityEvent.class); String operationFilePath = SedaConstants.TRACEABILITY_OPERATION_DIRECTORY + "/" + DATA_FILE; operationsInputStream = handler.getInputStreamFromWorkspace(operationFilePath); MerkleTreeAlgo merkleTreeAlgo = computeMerkleTree(operationsInputStream); final String currentRootHash = currentRootHash(merkleTreeAlgo); final ItemStatus subSecuredItem = compareToSecuredHash( handler, currentRootHash); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_SAVED_HASH, subSecuredItem); final ItemStatus subLoggedItemStatus = compareToLoggedHash(params, currentRootHash, traceabilityEvent); itemStatus.setItemsStatus(HANDLER_SUB_ACTION_COMPARE_WITH_INDEXED_HASH, subLoggedItemStatus); } catch (Exception e) { LOGGER.error(e); itemStatus.increment(StatusCode.FATAL); } finally { IOUtils.closeQuietly(operationsInputStream); } return new ItemStatus(HANDLER_ID).setItemsStatus(HANDLER_ID, itemStatus); }  static String getId(); @Override ItemStatus execute(WorkerParameters params, HandlerIO handler); static MerkleTreeAlgo computeMerkleTree(InputStream inputStream); @Override void checkMandatoryIOParameter(HandlerIO handler);  }