Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
61 changes: 50 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,50 @@ env:

jobs:

check:
name: Check
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os:
- windows-2025
- ubuntu-24.04
- macos-15
include:
- os: windows-2025
install: |
git config --system core.longpaths true
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
vcpkg install openssl:x64-windows-static-md

steps:
- uses: actions/checkout@v5
- uses: Swatinem/rust-cache@v2

- name: Cache Theseus Postgresql Installation
uses: actions/cache@v4
with:
path: ~/.theseus/postgresql
key: ${{ runner.os }}-theseus-postgresql-${{ hashFiles('**/Cargo.lock') }}

- name: Install dependencies
if: matrix.install != ''
run: ${{ matrix.install }}

- name: Check
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # for embedded postgresql
run: cargo check
- name: Clippy
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # for embedded postgresql
run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used

ci:
needs:
- check
runs-on: ubuntu-24.04

steps:
Expand Down Expand Up @@ -50,7 +93,7 @@ jobs:
sudo rm -Rf ${GRADLE_HOME}
- run: df -h

- uses: actions/checkout@v4
- uses: actions/checkout@v5
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

- uses: Swatinem/rust-cache@v2

- name: Cache Theseus Postgresql Installation
Expand All @@ -62,27 +105,23 @@ jobs:
- name: Format
run: cargo fmt --check

- name: Check
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # for embedded postgresql
run: cargo check

- name: Clippy
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # for embedded postgresql
run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used

- name: Start minio
run: |
docker compose -f etc/deploy/compose/compose-minio.yaml up -d --wait

- name: Create tmp dir
run: |
sudo mkdir /mnt/trustify
sudo chmod a+rwx /mnt/trustify

- name: Test
run: cargo test --all-features
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # for embedded postgresql
RUST_LOG: info,sqlx=error,sea_orm=error
TRUSTIFY_S3_AWS_REGION: eu-west-1
TRUSTIFY_S3_AWS_BUCKET: guacsec-migration-dumps
TMPDIR: /mnt/trustify

- name: Export and Validate Generated Openapi Spec
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:

- name: Test
# use only one job, trying to reduce memory usage
run: cargo llvm-cov --codecov --jobs 1 --features _test-s3 --output-path codecov.json
run: cargo llvm-cov --codecov --jobs 1 --all-features --output-path codecov.json
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # for embedded postgresql

Expand Down
66 changes: 64 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ actix-web-static-files = "4.0.1"
anyhow = "1.0.72"
async-compression = "0.4.13"
async-recursion = "1"
async-tar = { version = "0.6", default-features = false, features = ["runtime-tokio"] }
async-trait = "0.1.74"
aws-config = { version = "1.8.14", features = ["behavior-version-latest"] }
aws-sdk-s3 = { version = "1.124.0", features = ["behavior-version-latest"] }
Expand Down Expand Up @@ -88,6 +89,7 @@ json-merge-patch = "0.0.1"
jsonpath-rust = "1.0.1"
lenient_semver = "0.4.2"
liblzma = "0.4"
lzma-rust2 = "0.16.1"
libz-sys = "*"
log = "0.4.19"
mime = "0.3.17"
Expand Down Expand Up @@ -159,6 +161,7 @@ utoipa-swagger-ui = "9.0.0"
uuid = "1.7.0"
walkdir = "2.5"
walker-common = "0.15.0"
which = "8"
wiremock = "0.6"
zip = "8"

Expand Down
3 changes: 3 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ rust-version.workspace = true
[dependencies]
actix-web = { workspace = true }
anyhow = { workspace = true }
async-compression = { workspace = true, features = ["gzip", "lzma"] }
bytes = { workspace = true }
bytesize = { workspace = true, features = ["serde"] }
chrono = { workspace = true }
clap = { workspace = true, features = ["derive", "env"] }
cpe = { workspace = true }
deepsize = { workspace = true }
flate2 = { workspace = true }
hex = { workspace = true }
hide = { workspace = true }
human-date-parser = { workspace = true }
humantime = { workspace = true }
itertools = { workspace = true }
lenient_semver = { workspace = true }
log = { workspace = true }
lzma-rust2 = { workspace = true }
native-tls = { workspace = true }
packageurl = { workspace = true }
pem = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion common/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trustify-migration = { workspace = true }
trustify-common = { workspace = true }

anyhow = { workspace = true }
async-compression = { workspace = true, features = ["tokio", "lzma"] }
async-compression = { workspace = true, features = ["tokio", "lzma", "gzip"] }
log = { workspace = true }
postgresql_commands = { workspace = true, features = ["tokio"] }
postgresql_embedded = { workspace = true, features = ["blocking", "tokio"] }
Expand Down
31 changes: 5 additions & 26 deletions common/db/src/embedded.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use anyhow::Context;
use postgresql_embedded::{PostgreSQL, Settings, VersionReq};
use std::{
path::{Path, PathBuf},
pin::Pin,
};
use tokio::io::{AsyncRead, BufReader};
use std::path::{Path, PathBuf};
use tracing::{Instrument, info_span};
use trustify_common::db::Database;
use trustify_common::{db::Database, decompress::decompress_async_read};

/// Create common default settings for the embedded database
pub fn default_settings() -> anyhow::Result<Settings> {
Expand Down Expand Up @@ -76,33 +72,16 @@ pub async fn create_for(
.instrument(info_span!("start database"))
.await?;

let config = crate::config::Database {
username: "postgres".into(),
password: "trustify".into(),
host: "localhost".into(),
name: "test".into(),
port: postgresql.settings().port,
..crate::config::Database::from_env()?
};
let config = crate::config::Database::from_port(postgresql.settings().port)?;

let db = match options.source {
Source::Bootstrap => super::Database::bootstrap(&config)
.await
.context("Bootstrapping the test database")?,
Source::Import(path) => {
log::info!("Importing from: {}", path.display());

let source = tokio::fs::File::open(&path).await?;
let source = BufReader::new(source);
log::info!("Importing database from: {}", path.display());

let source: Pin<Box<dyn AsyncRead + Send>> = match path
.extension()
.and_then(|ext| ext.to_str())
{
None | Some("sql") => Box::pin(source),
Some("xz") => Box::pin(async_compression::tokio::bufread::LzmaDecoder::new(source)),
Some(ext) => anyhow::bail!("Unsupported file type ({ext})"),
};
let source = decompress_async_read(path).await?;
Comment on lines +82 to +84
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Change from failing on unsupported extensions to transparently passing them through may hide format errors

The previous logic failed fast on unsupported extensions, giving clear feedback for cases like .sql.xz/.sql mismatches or unexpected compression types. decompress_async_read now treats unknown extensions as uncompressed, which can defer errors until SQL parsing and make failures harder to diagnose. To keep the earlier, clearer failure mode, consider enforcing an allowlist of extensions here or adding a strict-mode option to decompress_async_read that does so.

Suggested implementation:

        Source::Import(path) => {
            log::info!("Importing database from: {}", path.display());

            // Enforce an allowlist of supported file extensions to fail fast on unexpected formats.
            match path.extension().and_then(|ext| ext.to_str()) {
                None | Some("sql") | Some("xz") => {}
                Some(ext) => anyhow::bail!("Unsupported file type ({ext})"),
            }

            let source = decompress_async_read(path).await?;

            super::Database::import(&config, source)
                .await

If anyhow is not already in scope in this file, add an appropriate import (e.g. use anyhow::bail; and then use bail! instead of anyhow::bail!, or ensure anyhow is available as a crate path). No changes to decompress_async_read are strictly required with this approach, since the allowlist is enforced at the call site.


super::Database::import(&config, source)
.await
Expand Down
11 changes: 11 additions & 0 deletions common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ impl Database {
sslmode = &self.sslmode,
)
}

pub fn from_port(port: u16) -> anyhow::Result<Self> {
Ok(Self {
username: "postgres".into(),
password: "trustify".into(),
host: "localhost".into(),
name: "test".into(),
port,
..Self::from_env()?
})
}
}

#[cfg(test)]
Expand Down
Loading
Loading