eclipse-score / eclipse-score/inc_security_crypto
C++ Unit Test Environment Decoupling & Refactoring
- Dominant language
- C++
- Stars
- 3
- Forks
- 15
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 23
Description
### What
Child of #49
**Description:**
Currently, C++ unit tests handle PKCS#11 token initialization inconsistently and fail when the Rust backend is selected:
1. test_pkcs11_multi_token.cpp and test_pkcs11_provider.cpp use unmaintainable #ifndef USE_RUST_PKCS11 preprocessor macros to skip token initialization entirely.
2. test_pkcs11_key_handler.cpp relies on SofthsmTestFixture. This fixture hardcodes the environment setup for SoftHSM (e.g., setting SOFTHSM2_CONF). When linked against the Rust backend, the test crashes because the Rust backend's required environment variable (CRYPTOKI_STORE) is never set, causing C_InitToken to fail.
We need to completely remove all #ifndef USE_RUST_PKCS11 preprocessor macro blocks and refactor the SofthsmTestFixture. By abstracting the test environment setup, selecting the PKCS#11 backend at Bazel build-time will automatically inject the correct environment variables and setup logic (SoftHSM vs. Rust), keeping the generic C++ test source files completely clean, decoupled, and vendor-neutral
This resolved the issue discussed here https://github.com/eclipse-score/inc_security_crypto/pull/49#:~:text=score/crypto/src/daemon,for%20test%20adaptation%20based
### Acceptance Criteria (DoD)
[ ]Zero Macros: Absolutely zero #ifndef USE_RUST_PKCS11 or #ifdef preprocessor blocks remain inside test_pkcs11_multi_token.cpp and test_pkcs11_provider.cpp.
[ ] Fixture Decoupling: The shared test fixture (SofthsmTestFixture) is replaced with a polymorphic interface that sets the correct environment variables (SOFTHSM2_CONF vs CRYPTOKI_STORE) before calling C_InitToken.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with test_pkcs11_multi_token.cpp, test_pkcs11_provider.cpp, and test_pkcs11_key_handler.cpp, then trace SofthsmTestFixture and the Bazel test setup. Identify how the selected backend supplies SOFTHSM2_CONF or CRYPTOKI_STORE before C_InitToken. Done means the shared fixture is replaced by a polymorphic environment setup and the two named tests contain no USE_RUST_PKCS11 preprocessor blocks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- build-system, security, testing
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100