### Question:
TarContainerPacker implements ContainerPacker<KeyValueContainerData> { @Override public byte[] unpackContainerData(Container<KeyValueContainerData> container, InputStream input) throws IOException { byte[] descriptorFileContent = null; KeyValueContainerData containerData = container.getContainerData(); Path dbRoot = containerData.getDbFile().toPath(); Path chunksRoot = Paths.get(containerData.getChunksPath()); try (InputStream decompressed = decompress(input); ArchiveInputStream archiveInput = untar(decompressed)) { ArchiveEntry entry = archiveInput.getNextEntry(); while (entry != null) { String name = entry.getName(); long size = entry.getSize(); if (name.startsWith(DB_DIR_NAME + "/")) { Path destinationPath = dbRoot .resolve(name.substring(DB_DIR_NAME.length() + 1)); extractEntry(archiveInput, size, dbRoot, destinationPath); } else if (name.startsWith(CHUNKS_DIR_NAME + "/")) { Path destinationPath = chunksRoot .resolve(name.substring(CHUNKS_DIR_NAME.length() + 1)); extractEntry(archiveInput, size, chunksRoot, destinationPath); } else if (CONTAINER_FILE_NAME.equals(name)) { descriptorFileContent = readEntry(archiveInput, size); } else { throw new IllegalArgumentException( "Unknown entry in the tar file: " + "" + name); } entry = archiveInput.getNextEntry(); } return descriptorFileContent; } catch (CompressorException e) { throw new IOException( "Can't uncompress the given container: " + container .getContainerData().getContainerID(), e); } }  @Override byte[] unpackContainerData(Container<KeyValueContainerData> container,
      InputStream input); @Override void pack(Container<KeyValueContainerData> container,
      OutputStream output); @Override byte[] unpackContainerDescriptor(InputStream input);  }### Answer:
@Test public void unpackContainerDataWithValidRelativeDbFilePath() throws Exception { KeyValueContainerData sourceContainerData = createContainer(SOURCE_CONTAINER_ROOT); String fileName = "sub/dir/" + TEST_DB_FILE_NAME; File file = writeDbFile(sourceContainerData, fileName); String entryName = TarContainerPacker.DB_DIR_NAME + "/" + fileName; File containerFile = packContainerWithSingleFile(file, entryName); KeyValueContainerData dest = unpackContainerData(containerFile); assertExampleMetadataDbIsGood(dest.getDbFile().toPath(), fileName); }
@Test public void unpackContainerDataWithValidRelativeChunkFilePath() throws Exception { KeyValueContainerData sourceContainerData = createContainer(SOURCE_CONTAINER_ROOT); String fileName = "sub/dir/" + TEST_CHUNK_FILE_NAME; File file = writeChunkFile(sourceContainerData, fileName); String entryName = TarContainerPacker.CHUNKS_DIR_NAME + "/" + fileName; File containerFile = packContainerWithSingleFile(file, entryName); KeyValueContainerData dest = unpackContainerData(containerFile); assertExampleChunkFileIsGood(Paths.get(dest.getChunksPath()), fileName); }
@Test public void unpackContainerDataWithInvalidRelativeDbFilePath() throws Exception { KeyValueContainerData sourceContainerData = createContainer(SOURCE_CONTAINER_ROOT); String fileName = "../db_file"; File file = writeDbFile(sourceContainerData, fileName); String entryName = TarContainerPacker.DB_DIR_NAME + "/" + fileName; File containerFile = packContainerWithSingleFile(file, entryName); LambdaTestUtils.intercept(IllegalArgumentException.class, () -> unpackContainerData(containerFile)); }
@Test public void unpackContainerDataWithInvalidRelativeChunkFilePath() throws Exception { KeyValueContainerData sourceContainerData = createContainer(SOURCE_CONTAINER_ROOT); String fileName = "../chunk_file"; File file = writeChunkFile(sourceContainerData, fileName); String entryName = TarContainerPacker.CHUNKS_DIR_NAME + "/" + fileName; File containerFile = packContainerWithSingleFile(file, entryName); LambdaTestUtils.intercept(IllegalArgumentException.class, () -> unpackContainerData(containerFile)); }