# Black-box CLI tests for opaque-keytab. Each test spawns the binary
# in a mkdtemp-isolated directory and inspects the filesystem result.

add_executable(test-opaque-keytab test-opaque-keytab.c)

target_compile_definitions(test-opaque-keytab PRIVATE _POSIX_C_SOURCE=200809L)

# Test asserts the size of records/.pad equals OPAQUE_USER_RECORD_LEN,
# which is defined in <opaque.h>, and builds valid record fixtures (a
# random scalar and its public element) with libsodium, because `import`
# validates the record.
target_link_libraries(test-opaque-keytab PRIVATE PkgConfig::LIBOPAQUE PkgConfig::SODIUM)

# The binary under test is passed as argv[1] so the test can locate it
# regardless of build-tree layout.
add_test(NAME opaque_keytab_unit
    COMMAND test-opaque-keytab "$<TARGET_FILE:opaque-keytab>")

# Test-only record auditor for tests/integration/verify-record.sh; it reads
# a user's password, so it is never installed (RFC 9807 §10.11, decision D11
# of docs/plans/rfc9807_conformance_plan.md).
add_executable(test-verify-record test-verify-record.c)
target_compile_definitions(test-verify-record PRIVATE _POSIX_C_SOURCE=200809L)
target_link_libraries(test-verify-record PRIVATE opaque-mech PkgConfig::LIBOPAQUE PkgConfig::SODIUM)

# pkg-config supplies libopaque/liboprf as -L/-l flags, so no RPATH is
# recorded and the loader cannot find them from their install prefix.
set_tests_properties(opaque_keytab_unit PROPERTIES
    ENVIRONMENT "LD_LIBRARY_PATH=${LIBOPAQUE_LIBRARY_DIRS}")
