Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/compilation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout code
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
checks: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Conan
uses: conan-io/setup-conan@v1

- name: Create default Conan profile
run: conan profile detect --force

- name: Create build directory
run: mkdir -p src/build

- name: Install dependencies
run: conan install src --output-folder=src/build --build=missing

- name: Configure CMake
working-directory: src
run: cmake --preset conan-release

- name: Build
working-directory: src
run: cmake --build --preset conan-release

- name: Run unit tests
working-directory: src
run: |
echo "Running SHA implementation tests..."
./run_all_ut.sh Release
# Also generate XML output for test reporting
Comment on lines +44 to +45
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are being run twice - once via run_all_ut.sh and again directly with --gtest_output=xml. This means the test suite executes twice on every run, doubling the CI execution time unnecessarily. Consider removing line 44 and modifying run_all_ut.sh to accept an optional parameter for generating XML output, or just run the test executable directly with the XML flag.

Suggested change
./run_all_ut.sh Release
# Also generate XML output for test reporting

Copilot uses AI. Check for mistakes.
./build/Release/ut_sha_functions --gtest_output=xml:test-results.xml
continue-on-error: false
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow explicitly sets continue-on-error: false which is already the default behavior for GitHub Actions steps. This line is redundant and can be removed without changing functionality.

Suggested change
continue-on-error: false

Copilot uses AI. Check for mistakes.

- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
src/test-results.xml
check_name: "Unit Test Results"
comment_mode: "off"

- name: Test Summary
if: always()
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Test Summary step always shows success even if tests fail. Since the "Run unit tests" step has continue-on-error: false, failures will be caught, but this message is misleading. Consider making it conditional or reflecting the actual test status using GitHub Actions expressions like if: success() instead of if: always().

Suggested change
if: always()
if: success()

Copilot uses AI. Check for mistakes.
run: echo "✅ All tests completed successfully"
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Italian: Implementazione Secure Hash Algorithm (SHA)

[![Cmake compilation Conan](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/compilation.yaml/badge.svg)](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/compilation.yaml)
[![Run Tests](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/test.yaml/badge.svg)](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/test.yaml)

Corso di Crittografia presso Unipr.

Expand Down Expand Up @@ -42,3 +43,32 @@ cmake --build build

> [!NOTE]
> Per non copia e incollare i singoli comandi si può usare lo script src/compile.sh

## Esecuzione dei test

Dopo aver compilato il progetto, è possibile eseguire i test unitari:

### Eseguire tutti i test

```bash
cd src && ./run_all_ut.sh
```

### Eseguire i test manualmente

```bash
cd src && ./build/Release/ut_sha_functions
```

### Eseguire i test con output XML (per CI/CD)

```bash
cd src && ./build/Release/ut_sha_functions --gtest_output=xml:test-results.xml
```

I test verificano la correttezza dell'implementazione SHA-1 e SHA-256 confrontandola con la libreria OpenSSL, includendo:
- Test con stringhe vuote, corte, lunghe e molto lunghe
- Test con caratteri speciali e non-ASCII
- Test di determinismo
- Test dell'effetto valanga (avalanche effect)
- Test di performance
Comment on lines +69 to +74
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation mentions SHA-0 in line 8 ("In questo progetto è stata effettuata l'implementazione degli algoritmi SHA-0, SHA-1 e SHA-256"), but the test verification section only mentions SHA-1 and SHA-256. If SHA-0 is not being tested, this inconsistency could confuse users about what's covered by the test suite.

Copilot uses AI. Check for mistakes.
33 changes: 28 additions & 5 deletions src/run_all_ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,32 @@ set -e
# Nella cartella ./build avviare tutti gli eseguibili che iniziano con ut_
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 5 is in Italian ("Nella cartella ./build avviare tutti gli eseguibili che iniziano con ut_") but no longer accurately describes the script's behavior. The script now searches in multiple locations and accepts a build type parameter, which is not mentioned in the comment. Consider updating the comment to reflect the current functionality.

Suggested change
# Nella cartella ./build avviare tutti gli eseguibili che iniziano con ut_
# Script per eseguire tutti gli eseguibili di test che iniziano con ut_
# Cerca nelle cartelle di build (es. ./build/<BUILD_TYPE> e ./build) usando un BUILD_TYPE opzionale (default: Release)

Copilot uses AI. Check for mistakes.

BUILD_DIR="build"
BUILD_TYPE="${1:-Release}" # Default to Release if not specified

if [ -d "$BUILD_DIR" ]; then
for file in "$BUILD_DIR"/ut_*; do
./"$file"
done
fi
# Cerca gli eseguibili di test nelle diverse possibili locazioni
TEST_LOCATIONS=(
"$BUILD_DIR/$BUILD_TYPE"
"$BUILD_DIR"
)

echo "Searching for test executables (build type: $BUILD_TYPE)..."

TESTS_FOUND=0
for location in "${TEST_LOCATIONS[@]}"; do
if [ -d "$location" ]; then
for file in "$location"/ut_*; do
if [ -x "$file" ]; then
echo "Running test: $file"
"$file"
TESTS_FOUND=$((TESTS_FOUND + 1))
fi
Comment on lines +21 to +26
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script searches for test executables matching the pattern ut_*, but there's no validation that the matched files are actually executable files (not directories). The check if [ -x "$file" ] helps, but the glob pattern "$location"/ut_* could match a non-existent file if no files match, causing the script to try to execute a literal string like "build/Release/ut_*". Consider adding a check if [ -f "$file" ] before the executable check.

Copilot uses AI. Check for mistakes.
done
fi
done

if [ $TESTS_FOUND -eq 0 ]; then
echo "No test executables found. Please build the project first."
exit 1
fi

echo "All tests completed successfully! ($TESTS_FOUND test suite(s) executed)"
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message "All tests completed successfully!" is misleading because it will be printed even if tests fail. The script uses set -e which should cause it to exit on test failure, but the message assumes success. Consider making the success message conditional or removing it since the exit code already indicates success.

Suggested change
echo "All tests completed successfully! ($TESTS_FOUND test suite(s) executed)"
echo "Test execution completed. ($TESTS_FOUND test suite(s) executed)"

Copilot uses AI. Check for mistakes.
Loading