Skip to content

Commit 7abe2db

Browse files
author
bram
committed
Added better tests and secure logging
1 parent db0d69a commit 7abe2db

11 files changed

Lines changed: 310 additions & 224 deletions

File tree

.github/workflows/build-and-release.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,19 @@ jobs:
364364
xvfb-run --auto-servernum --server-args="-screen 0 1024x768x24" cmake --build build --target all
365365
cd build
366366
mkdir -p Testing/Temporary
367-
echo "Running tests with minimal output..."
368-
xvfb-run --auto-servernum --server-args="-screen 0 1024x768x24" ./OpenCryptUITest -v2 | tee Testing/Temporary/LastTest.log
367+
chmod +x run_tests.sh
368+
echo "Running tests with filtered output..."
369+
xvfb-run --auto-servernum --server-args="-screen 0 1024x768x24" ./run_tests.sh -v2 | tee Testing/Temporary/LastTest.log
369370
370371
- name: Run tests (macOS)
371372
if: matrix.os == 'macos-latest'
372373
run: |
373374
cmake --build build --target all
374375
cd build
375376
mkdir -p Testing/Temporary
376-
echo "Running tests with minimal output..."
377-
./OpenCryptUITest -v2 | tee Testing/Temporary/LastTest.log
377+
chmod +x run_tests.sh
378+
echo "Running tests with filtered output..."
379+
./run_tests.sh -v2 | tee Testing/Temporary/LastTest.log
378380
379381
- name: Run tests (Windows)
380382
if: matrix.os == 'windows-latest'
@@ -383,13 +385,25 @@ jobs:
383385
cmake --build build --target all
384386
cd build
385387
mkdir -p Testing/Temporary
386-
echo "Running tests with minimal output..."
388+
echo "Running tests with filtered output..."
387389
export QT_QPA_PLATFORM=minimal
388390
389391
if [ -f "./OpenCryptUITest.exe" ]; then
390392
chmod +x ./OpenCryptUITest.exe
391-
# Use -v2 instead of -v4, as -v4 is not a valid option for QtTest
392-
./OpenCryptUITest.exe -v2 | tee Testing/Temporary/LastTest.log
393+
# Create a Windows-specific run_tests.bat script
394+
cat > run_tests.bat << EOF
395+
@echo off
396+
:: Set Qt logging rules to disable Qt internal categories
397+
set QT_LOGGING_RULES=qt.*=false
398+
set QT_MESSAGE_PATTERN=[%{type}] %{message}
399+
400+
:: Run the test with filtering
401+
.\OpenCryptUITest.exe %*
402+
EOF
403+
chmod +x run_tests.bat
404+
405+
# Run the tests using our script
406+
./run_tests.bat -v2 | tee Testing/Temporary/LastTest.log
393407
else
394408
echo "ERROR: OpenCryptUITest.exe not found!" | tee Testing/Temporary/LastTest.log
395409
echo "Directory contents: $(ls -la)" | tee -a Testing/Temporary/LastTest.log

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ set_target_properties(OpenCryptUI PROPERTIES POSITION_INDEPENDENT_CODE ON)
143143

144144
target_compile_options(OpenCryptUI PRIVATE -fPIC)
145145

146+
# Disable logging for main application
147+
target_compile_definitions(OpenCryptUI PRIVATE
148+
-DNO_LOGGING
149+
)
150+
146151
target_include_directories(OpenCryptUI PRIVATE
147152
${CMAKE_CURRENT_SOURCE_DIR}/include
148153
${CMAKE_CURRENT_SOURCE_DIR}/src
@@ -189,6 +194,12 @@ set_target_properties(OpenCryptUITest PROPERTIES POSITION_INDEPENDENT_CODE ON)
189194

190195
target_compile_options(OpenCryptUITest PRIVATE -fPIC)
191196

197+
# Always enable logging for tests
198+
target_compile_definitions(OpenCryptUITest PRIVATE
199+
-DTEST_MODE
200+
-DENABLE_LOGGING
201+
)
202+
192203
target_include_directories(OpenCryptUITest PRIVATE
193204
${CMAKE_CURRENT_SOURCE_DIR}/include
194205
${CMAKE_CURRENT_SOURCE_DIR}/src
@@ -217,6 +228,16 @@ target_link_libraries(OpenCryptUITest PRIVATE
217228
enable_testing()
218229
add_test(NAME OpenCryptUITest COMMAND OpenCryptUITest)
219230

231+
# Copy test runner script
232+
configure_file(
233+
${CMAKE_CURRENT_SOURCE_DIR}/scripts/run_tests.sh
234+
${CMAKE_CURRENT_BINARY_DIR}/run_tests.sh
235+
COPYONLY
236+
)
237+
# Make the script executable
238+
file(CHMOD ${CMAKE_CURRENT_BINARY_DIR}/run_tests.sh
239+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
240+
220241
# Print paths for debugging
221242
message(STATUS "Qt5_DIR: ${Qt5_DIR}")
222243
message(STATUS "OPENSSL_ROOT_DIR: ${OPENSSL_ROOT_DIR}")

include/logging/secure_logger.h

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,39 @@ class SecureLogger {
5353
#include <QProcessEnvironment>
5454
#include <QCoreApplication>
5555

56-
// Check if we're in release mode (compiled with NDEBUG and not in CI/test)
56+
// Check if we're in release mode (no logging mode)
5757
inline bool isReleaseMode() {
5858
static bool checked = false;
5959
static bool inRelease = false;
6060
if (!checked) {
61-
// Release mode if:
61+
// Release mode (no logging) if:
6262
// 1. NO_LOGGING environment var exists OR
63-
// 2. App was compiled with NDEBUG and we're NOT in CI environment
63+
// 2. NO_LOGGING defined at compile time
64+
// 3. App was compiled with NDEBUG and we're NOT in CI environment
65+
// 4. NOT explicitly ENABLE_LOGGING defined (for tests)
6466
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
6567
bool isCI = env.contains("CI") || env.contains("GITHUB_ACTIONS") ||
6668
env.contains("GITLAB_CI") || env.contains("TRAVIS");
6769

68-
// Explicitly disabled or release build outside CI
69-
inRelease = env.contains("NO_LOGGING") ||
70-
(
71-
#ifdef NDEBUG
72-
true &&
73-
#else
74-
false &&
75-
#endif
76-
!isCI
77-
);
70+
// Check if logging is explicitly enabled for tests
71+
#ifdef ENABLE_LOGGING
72+
inRelease = false;
73+
#else
74+
// Explicitly disabled or release build outside CI
75+
#ifdef NO_LOGGING
76+
inRelease = true;
77+
#else
78+
inRelease = env.contains("NO_LOGGING") ||
79+
(
80+
#ifdef NDEBUG
81+
true &&
82+
#else
83+
false &&
84+
#endif
85+
!isCI
86+
);
87+
#endif
88+
#endif
7889
checked = true;
7990
}
8091
return inRelease;

include/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private slots:
7676
void on_actionAboutKDFs_triggered();
7777
void on_actionAboutIterations_triggered();
7878
void applyTheme(const QString &theme);
79-
void on_cryptoProviderComboBox_currentIndexChanged(const QString &providerName);
79+
void on_m_cryptoProviderComboBox_currentIndexChanged(const QString &providerName);
8080
void showProviderCapabilities();
8181

8282
// Password security and security UI

scripts/run_tests.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Run tests with suppressed Qt warnings
4+
# This script completely filters out Qt's internal debug logs
5+
# while preserving the actual test results
6+
7+
# Suppress all Qt internal categories
8+
export QT_LOGGING_RULES="qt.*=false"
9+
10+
# Simplify output pattern
11+
export QT_MESSAGE_PATTERN="[%{type}] %{message}"
12+
13+
# Run the tests and filter output
14+
./OpenCryptUITest "$@" 2>&1 | grep -v "^QDEBUG : TestOpenCryptUI::initTestCase() \[debug\] qt\." | grep -v "^QDEBUG : TestOpenCryptUI::initTestCase() \[debug\] QFont::"

src/encryptionworker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ void EncryptionWorker::process()
276276
double mbps = fileSizeMB / seconds;
277277

278278
SECURE_LOG(INFO, "EncryptionWorker",
279-
QString("Operation completed successfully in %.2f seconds (%.2f MB/s)")
280-
.arg(seconds).arg(mbps));
279+
QString("Operation completed successfully in %1 seconds (%2 MB/s)")
280+
.arg(seconds, 0, 'f', 2).arg(mbps, 0, 'f', 2));
281281

282282
emit finished(true, QString());
283283
emit benchmarkResultReady(iterations, mbps, seconds * 1000, algorithm, kdf);

src/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "mainwindow.h"
22
#include <QApplication>
3+
#include <QLoggingCategory>
34
#include <openssl/crypto.h>
45
#include "version.h"
56
#include "logging/secure_logger.h"
@@ -16,10 +17,20 @@ int main(int argc, char *argv[])
1617
// Configure logging - simplified approach
1718
SecureLogger& logger = SecureLogger::getInstance();
1819

20+
// Configure Qt logging rules to disable internal Qt logs
21+
QLoggingCategory::setFilterRules(
22+
"qt.*.debug=false\n"
23+
"qt.*.info=false\n"
24+
"qt.*.warning=false"
25+
);
26+
1927
// No logging in the main application (OpenCryptUI)
2028
// All logging is done in the test version (OpenCryptUITest)
2129
logger.setLogLevel(SecureLogger::LogLevel::ERROR_LEVEL);
2230
logger.setLogToFile(false);
31+
32+
// This is a test log message to verify logging configuration
33+
SECURE_LOG(INFO, "MainApplication", "Application starting - this should only appear in test mode");
2334

2435
QApplication app(argc, argv);
2536

0 commit comments

Comments
 (0)