Skip to content

Commit ce0294a

Browse files
author
Derek
committed
fix: vector compat integration tests, vault_env env leak fix
1 parent 5817bc0 commit ce0294a

5 files changed

Lines changed: 782 additions & 9 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ out/
2323
test-results/
2424
coverage/
2525

26+
# Temporary/cache
27+
.tmp/
28+
2629
# Rust
2730
target/
2831
Cargo.lock

TODO.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@
88

99
## Current Tasks
1010

11-
### High Priority
12-
13-
- [ ] Update downstream consumers to use `transport-grpc` / `transport-grpc-vector-compat`
14-
- dfe-loader, dfe-archiver, dfe-receiver
15-
16-
### Medium Priority
17-
18-
- [ ] Fix vault_env integration tests (EnvGuard doesn't clear conflicting VAULT_TOKEN)
19-
- [ ] Add Vector compat source/sink integration tests (use fetch-vector.sh from dfe-receiver)
11+
(none)
2012

2113
---
2214

2315
## Completed
2416

17+
- [x] Vector compat integration tests — 6 tests using real Vector binary + VectorCompatClient (fetch-vector.sh + YAML)
18+
- [x] vault_env integration tests fixed — clear_vault_env() prevents VAULT_TOKEN leakage
2519
- [x] Dependency update sweep — all crates to latest, tonic/prost 0.14 migration (v1.8.4)
2620
- [x] Stale hs-rustlib removed from JFrog hypersec-cargo-local and hyperi-cargo-local
2721
- [x] MaskingLayer fixed — writer-based redaction for both JSON and text formats (v1.8.4)

scripts/fetch-vector.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
# Project: hyperi-rustlib
3+
# File: scripts/fetch-vector.sh
4+
# Purpose: Download and cache Vector binary for integration tests
5+
# Language: Bash
6+
#
7+
# License: FSL-1.1-ALv2
8+
# Copyright: (c) 2026 HYPERI PTY LIMITED
9+
#
10+
# Usage:
11+
# ./scripts/fetch-vector.sh # ensure latest, print binary path
12+
# VECTOR_VERSION=0.43.0 ./scripts/fetch-vector.sh # pin specific version
13+
#
14+
# Downloads the latest Vector release only if the cached binary is missing or
15+
# out of date. Prints the absolute path to the vector binary on stdout (last line).
16+
# Status messages go to stderr.
17+
18+
set -euo pipefail
19+
20+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
21+
CACHE_DIR="${REPO_ROOT}/.tmp/vector"
22+
ARCH="$(uname -m)"
23+
24+
# Check what we have cached (read version from binary)
25+
cached_version() {
26+
local bin="${CACHE_DIR}/bin/vector"
27+
if [[ -x "$bin" ]]; then
28+
"$bin" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1
29+
fi
30+
}
31+
32+
# Resolve the desired version
33+
if [[ -n "${VECTOR_VERSION:-}" ]]; then
34+
WANT_VERSION="$VECTOR_VERSION"
35+
else
36+
if command -v gh &>/dev/null; then
37+
WANT_VERSION=$(gh release list --repo vectordotdev/vector --limit 30 --json tagName \
38+
--jq '[.[] | select(.tagName | test("^v[0-9]"))][0].tagName' | sed 's/^v//')
39+
elif command -v jq &>/dev/null; then
40+
WANT_VERSION=$(curl -fsSL "https://api.github.com/repos/vectordotdev/vector/releases?per_page=30" \
41+
| jq -r '[.[] | select(.tag_name | test("^v[0-9]"))][0].tag_name' | sed 's/^v//')
42+
else
43+
echo "ERROR: need either 'gh' or 'jq' to resolve latest version" >&2
44+
exit 1
45+
fi
46+
fi
47+
48+
if [[ -z "$WANT_VERSION" || "$WANT_VERSION" == "null" ]]; then
49+
echo "ERROR: could not resolve Vector version" >&2
50+
exit 1
51+
fi
52+
53+
BINARY="${CACHE_DIR}/bin/vector"
54+
HAVE_VERSION=$(cached_version || true)
55+
56+
# If cached binary matches desired version, use it
57+
if [[ "$HAVE_VERSION" == "$WANT_VERSION" ]]; then
58+
echo "Vector ${WANT_VERSION} already cached" >&2
59+
echo "$BINARY"
60+
exit 0
61+
fi
62+
63+
if [[ -n "$HAVE_VERSION" ]]; then
64+
echo "Updating Vector ${HAVE_VERSION} -> ${WANT_VERSION}" >&2
65+
else
66+
echo "Downloading Vector ${WANT_VERSION} for ${ARCH}..." >&2
67+
fi
68+
69+
# Clean old cache
70+
rm -rf "${CACHE_DIR:?}/bin"
71+
72+
# Download
73+
mkdir -p "${CACHE_DIR}"
74+
TARBALL_NAME="vector-${WANT_VERSION}-${ARCH}-unknown-linux-gnu.tar.gz"
75+
DOWNLOAD_URL="https://github.com/vectordotdev/vector/releases/download/v${WANT_VERSION}/${TARBALL_NAME}"
76+
77+
curl -fSL --progress-bar -o "${CACHE_DIR}/${TARBALL_NAME}" "$DOWNLOAD_URL"
78+
79+
# Extract — tarball contains vector-{ARCH}-unknown-linux-gnu/bin/vector
80+
echo "Extracting..." >&2
81+
tar xzf "${CACHE_DIR}/${TARBALL_NAME}" -C "${CACHE_DIR}"
82+
83+
EXTRACTED_DIR="${CACHE_DIR}/vector-${ARCH}-unknown-linux-gnu"
84+
if [[ -d "$EXTRACTED_DIR" ]]; then
85+
mv "${EXTRACTED_DIR}/bin" "${CACHE_DIR}/bin"
86+
rm -rf "$EXTRACTED_DIR"
87+
fi
88+
89+
# Cleanup tarball
90+
rm -f "${CACHE_DIR}/${TARBALL_NAME}"
91+
92+
# Verify
93+
if [[ ! -x "$BINARY" ]]; then
94+
echo "ERROR: Vector binary not found at ${BINARY} after extraction" >&2
95+
exit 1
96+
fi
97+
98+
echo "Vector ${WANT_VERSION} cached at ${BINARY}" >&2
99+
echo "$BINARY"

tests/env_integration.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,35 @@ mod vault_env {
164164
use super::*;
165165
use hyperi_rustlib::secrets::{OpenBaoAuth, OpenBaoConfig};
166166

167+
/// All vault/openbao env vars that could interfere with tests.
168+
/// Must be cleared before each test to prevent leakage from the host.
169+
const VAULT_ENV_VARS: &[&str] = &[
170+
"VAULT_ADDR",
171+
"VAULT_TOKEN",
172+
"VAULT_SKIP_VERIFY",
173+
"VAULT_NAMESPACE",
174+
"VAULT_ROLE_ID",
175+
"VAULT_SECRET_ID",
176+
"VAULT_K8S_ROLE",
177+
"VAULT_K8S_MOUNT",
178+
"OPENBAO_ADDR",
179+
"OPENBAO_TOKEN",
180+
"BAO_ADDR",
181+
"BAO_TOKEN",
182+
"OPENBAO_ROOT_TOKEN",
183+
];
184+
185+
/// Clear all vault-related env vars so tests start from a clean slate.
186+
fn clear_vault_env() {
187+
for var in VAULT_ENV_VARS {
188+
std::env::remove_var(var);
189+
}
190+
}
191+
167192
#[test]
168193
fn test_vault_from_env_token_auth() {
169194
let _lock = ENV_LOCK.lock().unwrap();
195+
clear_vault_env();
170196
let _guard = EnvGuard::new(&[
171197
("VAULT_ADDR", "https://vault.example.com:8200"),
172198
("VAULT_TOKEN", "s.test-token"),
@@ -181,6 +207,7 @@ mod vault_env {
181207
#[test]
182208
fn test_vault_from_env_approle_auth() {
183209
let _lock = ENV_LOCK.lock().unwrap();
210+
clear_vault_env();
184211
let _guard = EnvGuard::new(&[
185212
("VAULT_ADDR", "https://vault.example.com:8200"),
186213
("VAULT_ROLE_ID", "role-123"),
@@ -202,6 +229,7 @@ mod vault_env {
202229
#[test]
203230
fn test_vault_from_env_k8s_auth() {
204231
let _lock = ENV_LOCK.lock().unwrap();
232+
clear_vault_env();
205233
let _guard = EnvGuard::new(&[
206234
("VAULT_ADDR", "https://vault.example.com:8200"),
207235
("VAULT_K8S_ROLE", "my-k8s-role"),
@@ -218,6 +246,7 @@ mod vault_env {
218246
#[test]
219247
fn test_vault_from_env_openbao_fallback() {
220248
let _lock = ENV_LOCK.lock().unwrap();
249+
clear_vault_env();
221250
let _guard = EnvGuard::new(&[
222251
("OPENBAO_ADDR", "https://openbao:8200"), // Legacy name
223252
("OPENBAO_TOKEN", "s.openbao-token"), // Legacy name
@@ -232,6 +261,7 @@ mod vault_env {
232261
#[test]
233262
fn test_vault_from_env_vault_wins_over_openbao() {
234263
let _lock = ENV_LOCK.lock().unwrap();
264+
clear_vault_env();
235265
let _guard = EnvGuard::new(&[
236266
("VAULT_ADDR", "https://vault-wins:8200"),
237267
("OPENBAO_ADDR", "https://openbao-loses:8200"),
@@ -249,6 +279,7 @@ mod vault_env {
249279
#[test]
250280
fn test_vault_from_env_skip_verify() {
251281
let _lock = ENV_LOCK.lock().unwrap();
282+
clear_vault_env();
252283
let _guard = EnvGuard::new(&[
253284
("VAULT_ADDR", "https://vault:8200"),
254285
("VAULT_TOKEN", "test"),
@@ -263,6 +294,7 @@ mod vault_env {
263294
#[test]
264295
fn test_vault_from_env_namespace() {
265296
let _lock = ENV_LOCK.lock().unwrap();
297+
clear_vault_env();
266298
let _guard = EnvGuard::new(&[
267299
("VAULT_ADDR", "https://vault:8200"),
268300
("VAULT_TOKEN", "test"),
@@ -277,6 +309,7 @@ mod vault_env {
277309
#[test]
278310
fn test_vault_from_env_missing_addr() {
279311
let _lock = ENV_LOCK.lock().unwrap();
312+
clear_vault_env();
280313
let _guard = EnvGuard::new(&[("VAULT_TOKEN", "test")]); // No VAULT_ADDR
281314

282315
let config = OpenBaoConfig::from_env();
@@ -287,6 +320,7 @@ mod vault_env {
287320
#[test]
288321
fn test_vault_from_env_missing_auth() {
289322
let _lock = ENV_LOCK.lock().unwrap();
323+
clear_vault_env();
290324
let _guard = EnvGuard::new(&[("VAULT_ADDR", "https://vault:8200")]); // No auth
291325

292326
let config = OpenBaoConfig::from_env();

0 commit comments

Comments
 (0)