Files
ViewDesignEngine/tests/plugin/package_tool_smoke.cmake

100 lines
5.1 KiB
CMake

# P4-41: vde_plugin_tool package/list/uninstall smoke
cmake_minimum_required(VERSION 3.20)
if(NOT DEFINED VDE_TOOL OR NOT DEFINED VDE_BINARY_DIR)
message(FATAL_ERROR "package_tool_smoke: missing -DVDE_TOOL/-DVDE_BINARY_DIR")
endif()
function(run_checked)
execute_process(COMMAND ${ARGN} RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_VARIABLE _err)
if(NOT _rc EQUAL 0)
message(FATAL_ERROR "command failed (${_rc}): ${ARGN}")
endif()
endfunction()
function(run_expect_fail)
execute_process(COMMAND ${ARGN} RESULT_VARIABLE _rc OUTPUT_VARIABLE _out ERROR_VARIABLE _err)
if(_rc EQUAL 0)
message(FATAL_ERROR "expected failure: ${ARGN}")
endif()
endfunction()
set(_root "${VDE_BINARY_DIR}/package_tool_smoke")
file(REMOVE_RECURSE "${_root}")
file(MAKE_DIRECTORY "${_root}/plugin" "${_root}/install")
file(WRITE "${_root}/plugin/vde-plugin.json" [=[
{
"id": "com.vde.test.pkgtool",
"name": "Package Tool Smoke Plugin",
"version": "1.0.0",
"kind": "format",
"abi": { "major": 1, "minor": 5 },
"entry": {"windows": "pkgtool_test.dll", "linux": "libpkgtool_test.so", "macos": "libpkgtool_test.dylib"},
"capabilities": ["format:pkgtool.read"],
"license": "Apache-2.0"
}
]=])
file(WRITE "${_root}/plugin/pkgtool_test.dll" "PKGTOOL-DLL-BYTES")
file(WRITE "${_root}/plugin/data.txt" "payload\n")
run_checked("${VDE_TOOL}" package "${_root}/plugin" -o "${_root}/a.vdeplugin")
run_checked("${VDE_TOOL}" package "${_root}/plugin" -o "${_root}/b.vdeplugin")
file(SHA256 "${_root}/a.vdeplugin" _sha_a)
file(SHA256 "${_root}/b.vdeplugin" _sha_b)
if(NOT _sha_a STREQUAL _sha_b)
message(FATAL_ERROR "package not deterministic")
endif()
file(READ "${_root}/a.vdeplugin.sha256" _sidecar)
string(REGEX MATCH "^[0-9a-fA-F]+" _sidecar_sha "${_sidecar}")
if(NOT _sidecar_sha STREQUAL _sha_a)
message(FATAL_ERROR "sha256 sidecar mismatch")
endif()
run_checked("${VDE_TOOL}" verify-package "${_root}/a.vdeplugin")
run_checked("${VDE_TOOL}" unpack "${_root}/a.vdeplugin" --dest "${_root}/unpacked")
file(SHA256 "${_root}/plugin/vde-plugin.json" _m1)
file(SHA256 "${_root}/unpacked/vde-plugin.json" _m2)
file(SHA256 "${_root}/plugin/pkgtool_test.dll" _d1)
file(SHA256 "${_root}/unpacked/pkgtool_test.dll" _d2)
if(NOT _m1 STREQUAL _m2 OR NOT _d1 STREQUAL _d2)
message(FATAL_ERROR "unpack round-trip mismatch")
endif()
run_checked("${VDE_TOOL}" list "${_root}/unpacked")
file(MAKE_DIRECTORY "${_root}/install/com.vde.test.pkgtool")
file(COPY "${_root}/unpacked/" DESTINATION "${_root}/install/com.vde.test.pkgtool")
file(MAKE_DIRECTORY "${_root}/install/com.vde.test.other")
file(WRITE "${_root}/install/com.vde.test.other/vde-plugin.json" [=[
{"id":"com.vde.test.other","version":"2.0.0","kind":"format","abi":{"major":1,"minor":5},
"entry":{"windows":"other.dll","linux":"libother.so"},"capabilities":["format:other.read"]}
]=])
file(WRITE "${_root}/install/com.vde.test.other/other.dll" "OTHER")
run_checked("${VDE_TOOL}" uninstall com.vde.test.pkgtool --root "${_root}/install")
if(EXISTS "${_root}/install/com.vde.test.pkgtool")
message(FATAL_ERROR "uninstall did not remove target")
endif()
if(NOT EXISTS "${_root}/install/com.vde.test.other/other.dll")
message(FATAL_ERROR "uninstall removed unrelated plugin")
endif()
run_expect_fail("${VDE_TOOL}" uninstall com.vde.test.pkgtool --root "${_root}/install")
run_expect_fail("${VDE_TOOL}" uninstall "../com.vde.test.other" --root "${_root}/install")
file(MAKE_DIRECTORY "${_root}/install/com.vde.test.fake")
file(WRITE "${_root}/install/com.vde.test.fake/vde-plugin.json" [=[
{"id":"com.vde.test.real","version":"1.0.0","kind":"format","abi":{"major":1,"minor":5},
"entry":{"windows":"fake.dll","linux":"libfake.so"},"capabilities":["format:fake.read"]}
]=])
file(WRITE "${_root}/install/com.vde.test.fake/fake.dll" "FAKE")
run_expect_fail("${VDE_TOOL}" uninstall com.vde.test.fake --root "${_root}/install")
if(NOT EXISTS "${_root}/install/com.vde.test.fake/fake.dll")
message(FATAL_ERROR "id-mismatch uninstall deleted directory")
endif()
file(MAKE_DIRECTORY "${_root}/bad_missing_dll")
file(WRITE "${_root}/bad_missing_dll/vde-plugin.json" [=[
{"id":"com.vde.test.missing","version":"1.0.0","kind":"format","abi":{"major":1,"minor":5},
"entry":{"windows":"missing.dll","linux":"libmissing.so"},"capabilities":["format:missing.read"]}
]=])
run_expect_fail("${VDE_TOOL}" package "${_root}/bad_missing_dll" -o "${_root}/bad.vdeplugin")
file(MAKE_DIRECTORY "${_root}/bad_manifest")
file(WRITE "${_root}/bad_manifest/vde-plugin.json" "{ not valid json")
file(WRITE "${_root}/bad_manifest/bad.dll" "BAD")
run_expect_fail("${VDE_TOOL}" package "${_root}/bad_manifest" -o "${_root}/bad2.vdeplugin")
string(SHA256 _evil_sha "X")
set(_evil_archive "VDEPKG1\n{\"id\":\"x\",\"version\":\"1.0.0\",\"kind\":\"format\",\"abi_major\":1,\"abi_minor\":5,\"entry\":\"x.dll\",\"files\":1}\nFILE ${_evil_sha} 1 ../evil.txt\nX")
file(WRITE "${_root}/evil.vdeplugin" "${_evil_archive}")
run_expect_fail("${VDE_TOOL}" verify-package "${_root}/evil.vdeplugin")
run_expect_fail("${VDE_TOOL}" unpack "${_root}/evil.vdeplugin" --dest "${_root}/evil_out")
message(STATUS "VDE_PluginToolPackageListUninstall: PASS")