-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpp: Add tests * Rename c++ folder to cpp * Add tests --------- Co-authored-by: Philip Stadermann <[email protected]> Co-authored-by: Fröhling, Maximilian <[email protected]>
- Loading branch information
1 parent
0619fd5
commit 0f538f7
Showing
17 changed files
with
263 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: vaas-cpp-toolchain-ci | ||
on: | ||
push: | ||
tags: | ||
- "cpp-toolchain*" | ||
paths: | ||
- "cpp/Dockerfile.build" | ||
- ".github/workflows/ci-cpp-toolchain.yaml" | ||
|
||
jobs: | ||
cpp-toolchain: | ||
name: Build & Push C++ toolchain | ||
permissions: | ||
contents: read | ||
packages: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
cpp/Dockerfile.build | ||
sparse-checkout-cone-mode: false | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: set version | ||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/cpp-toolchain}" >> $GITHUB_ENV | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
ghcr.io/gdatasoftwareag/vaas/cpp-toolchain | ||
tags: | | ||
type=semver,pattern={{version}},value=${{ env.RELEASE_VERSION }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ env.RELEASE_VERSION }} | ||
type=semver,pattern={{major}},value=${{ env.RELEASE_VERSION }} | ||
flavor: | | ||
latest=auto | ||
- name: login to ghcr.io/gdatasoftwareag | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ secrets.GHCR_IO_GDATASOFTWAREAG_USERNAME }} | ||
password: ${{ secrets.GHCR_IO_GDATASOFTWAREAG_PASSWORD }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: "cpp/" | ||
file: "cpp/Dockerfile.build" | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: vaas-cpp-ci | ||
on: | ||
push: | ||
paths: | ||
- "cpp/**" | ||
- ".github/workflows/ci-cpp.yaml" | ||
pull_request: | ||
paths: | ||
- "cpp/**" | ||
- ".github/workflows/ci-cpp.yaml" | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
type: choice | ||
description: "Test environment" | ||
options: | ||
- production | ||
- staging | ||
- develop | ||
default: "production" | ||
|
||
env: | ||
CLIENT_ID: ${{ secrets.CLIENT_ID }} | ||
CLIENT_SECRET: ${{secrets.CLIENT_SECRET}} | ||
VAAS_URL: "https://upload.production.vaas.gdatasecurity.de" | ||
TOKEN_URL: "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token" | ||
VAAS_CLIENT_ID: ${{ secrets.VAAS_CLIENT_ID }} | ||
VAAS_USER_NAME: ${{ secrets.VAAS_USER_NAME }} | ||
VAAS_PASSWORD: ${{secrets.VAAS_PASSWORD}} | ||
|
||
jobs: | ||
cpp-build: | ||
name: Build & Test C++ SDK | ||
runs-on: ubuntu-latest | ||
container: ghcr.io/gdatasoftwareag/vaas/cpp-toolchain | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Scan for Viruses | ||
uses: ./.github/actions/vaas-scan-action | ||
with: | ||
VAAS_CLIENT_ID: ${{ secrets.VAAS_SCAN_CLIENT_ID }} | ||
VAAS_CLIENT_SECRET: ${{ secrets.VAAS_SCAN_CLIENT_SECRET }} | ||
|
||
- name: set staging environment | ||
if: (inputs.environment == 'staging' || (startsWith(github.ref, 'refs/tags/cpp') && endsWith(github.ref, '-beta'))) | ||
run: | | ||
echo "CLIENT_ID=${{ secrets.STAGING_CLIENT_ID }}" >> $GITHUB_ENV | ||
echo "CLIENT_SECRET=${{ secrets.STAGING_CLIENT_SECRET }}" >> $GITHUB_ENV | ||
echo "VAAS_URL=https://upload.staging.vaas.gdatasecurity.de" >> $GITHUB_ENV | ||
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token" >> $GITHUB_ENV | ||
echo "VAAS_CLIENT_ID=${{ secrets.STAGING_VAAS_CLIENT_ID }}" >> $GITHUB_ENV | ||
echo "VAAS_USER_NAME=${{ secrets.STAGING_VAAS_USER_NAME }}" >> $GITHUB_ENV | ||
echo "VAAS_PASSWORD=${{ secrets.STAGING_VAAS_PASSWORD }}" >> $GITHUB_ENV | ||
- name: set develop environment | ||
if: (inputs.environment == 'develop' || (startsWith(github.ref, 'refs/tags/cpp') && endsWith(github.ref, '-alpha'))) | ||
run: | | ||
echo "CLIENT_ID=${{ secrets.DEVELOP_CLIENT_ID }}" >> $GITHUB_ENV | ||
echo "CLIENT_SECRET=${{ secrets.DEVELOP_CLIENT_SECRET }}" >> $GITHUB_ENV | ||
echo "VAAS_URL=https://upload.develop.vaas.gdatasecurity.de" >> $GITHUB_ENV | ||
echo "TOKEN_URL=https://account-staging.gdata.de/realms/vaas-develop/protocol/openid-connect/token" >> $GITHUB_ENV | ||
echo "VAAS_CLIENT_ID=${{ secrets.DEVELOP_VAAS_CLIENT_ID }}" >> $GITHUB_ENV | ||
echo "VAAS_USER_NAME=${{ secrets.DEVELOP_VAAS_USER_NAME }}" >> $GITHUB_ENV | ||
echo "VAAS_PASSWORD=${{ secrets.DEVELOP_VAAS_PASSWORD }}" >> $GITHUB_ENV | ||
# https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache | ||
- name: Export GitHub Actions cache environment variables | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); | ||
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); | ||
- name: Build C++ SDK | ||
env: | ||
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" | ||
run: | | ||
./build.sh | ||
working-directory: cpp | ||
|
||
- name: Test C++ SDK | ||
run: | | ||
./test.sh | ||
working-directory: cpp |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#### Base Image | ||
FROM ubuntu:24.04 | ||
|
||
RUN apt-get update -qq && \ | ||
# install dependencies | ||
apt-get install -y --no-install-recommends git ca-certificates curl zip unzip tar build-essential cmake make pkg-config libssl3 libssl-dev linux-libc-dev && \ | ||
# install vcpkg | ||
cd /usr/local && \ | ||
git clone https://github.com/microsoft/vcpkg.git && \ | ||
cd vcpkg && ./bootstrap-vcpkg.sh | ||
|
||
ENV VCPKG_ROOT="/usr/local/vcpkg/" | ||
ENV PATH="$VCPKG_ROOT:$PATH" | ||
|
||
|
||
ENTRYPOINT ["/bin/bash"] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -ex | ||
cmake --preset release | ||
cmake --build build |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
set -ex | ||
./build/vaas_test --exit=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT | ||
#include "vaas.h" | ||
#include <doctest/doctest.h> | ||
|
||
static char* program; | ||
|
||
int main(int argc, char** argv) { | ||
program = argv[0]; | ||
doctest::Context context; | ||
context.applyCommandLine(argc, argv); | ||
|
||
int res = context.run(); // run doctest | ||
|
||
// important - query flags (and --exit) rely on the user doing this | ||
if (context.shouldExit()) { | ||
// propagate the result of the tests | ||
return res; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
vaas::Vaas initVaas() { | ||
const auto vaasUrl = std::getenv("VAAS_URL") | ||
? std::getenv("VAAS_URL") | ||
: "https://upload.staging.vaas.gdatasecurity.de"; | ||
const auto tokenUrl = std::getenv("TOKEN_URL") | ||
? std::getenv("TOKEN_URL") | ||
: "https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token"; | ||
const auto clientId = std::getenv("CLIENT_ID") | ||
? std::getenv("CLIENT_ID") | ||
: throw std::runtime_error("CLIENT_ID must be set"); | ||
const auto clientSecret = std::getenv("CLIENT_SECRET") | ||
? std::getenv("CLIENT_SECRET") | ||
: throw std::runtime_error("CLIENT_SECRET must be set"); | ||
return vaas::Vaas(vaasUrl, tokenUrl, clientId, clientSecret); | ||
} | ||
|
||
class VaasTestFixture { | ||
protected: | ||
vaas::Vaas vaas; | ||
|
||
VaasTestFixture() : vaas(initVaas()) { | ||
} | ||
}; | ||
|
||
TEST_CASE_FIXTURE(VaasTestFixture, "forFile_withCleanFile_returnsClean") { | ||
auto report = vaas.forFile(program); | ||
CHECK(report.verdict == vaas::VaasReport::Verdict::Clean); | ||
} | ||
|
||
/* TODO: Currently broken | ||
TEST_CASE_FIXTURE(VaasTestFixture, "forHash_withMaliciousFile_returnsMalicious") { | ||
auto report = vaas.forHash("275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f"); | ||
CHECK(report.verdict == vaas::VaasReport::Verdict::Malicious); | ||
} | ||
*/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
] | ||
}, | ||
"jsoncpp", | ||
"openssl" | ||
"openssl", | ||
"doctest" | ||
], | ||
"version": "0.0.0", | ||
"name": "vaas" | ||
|