Skip to content

Commit

Permalink
fix: make correlated doc id's truly unique
Browse files Browse the repository at this point in the history
This requires the index to be "always" rebuilt. Otherwise, the stale
data in the index increments the advisory count with each test
invocation.

Signed-off-by: Jim Crossley <jim@crossleys.org>
  • Loading branch information
jcrossley3 committed Sep 29, 2023
1 parent 7732198 commit c4ce3be
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ spog-api = { path = "../spog/api", optional = true }
trustification-infrastructure = { path = "../infrastructure", optional = true }
trustification-storage = { path = "../storage", optional = true }
trustification-index = { path = "../index", optional = true }
trustification-indexer = { path = "../indexer", optional = true }

clap = { version = "4", features = ["derive"] }

Expand All @@ -45,4 +46,4 @@ spog-model = { path = "../spog/model" }

[features]
default = ["with-services"]
with-services = ["bombastic-api", "bombastic-indexer", "vexination-api", "vexination-indexer", "spog-api", "trustification-storage", "trustification-index", "trustification-infrastructure" ]
with-services = ["bombastic-api", "bombastic-indexer", "vexination-api", "vexination-indexer", "spog-api", "trustification-storage", "trustification-index", "trustification-indexer", "trustification-infrastructure" ]
25 changes: 13 additions & 12 deletions integration-tests/src/vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;
use crate::{config::Config, runner::Runner};
use async_trait::async_trait;
use test_context::AsyncTestContext;
use trustification_indexer::ReindexMode;

#[async_trait]
impl AsyncTestContext for VexinationContext {
Expand Down Expand Up @@ -146,15 +147,14 @@ impl VexinationContext {
fn vexination_indexer() -> vexination_indexer::Run {
vexination_indexer::Run {
stored_topic: "vex-stored".into(),
failed_topic: "vex-failed".into(),
indexed_topic: "vex-indexed".into(),
failed_topic: "vex-failed".into(),
devmode: true,
reindex: Default::default(),
index: IndexConfig {
index_dir: None,
index_writer_memory_bytes: 32 * 1024 * 1024,
mode: Default::default(),
sync_interval: Duration::from_secs(2).into(),
reindex: ReindexMode::Always,
bus: EventBusConfig {
event_bus: EventBusType::Kafka,
kafka_bootstrap_servers: KAFKA_BOOTSTRAP_SERVERS.into(),
..Default::default()
},
storage: StorageConfig {
region: None,
Expand All @@ -163,17 +163,18 @@ fn vexination_indexer() -> vexination_indexer::Run {
access_key: Some("admin".into()),
secret_key: Some("password".into()),
},
bus: EventBusConfig {
event_bus: EventBusType::Kafka,
kafka_bootstrap_servers: KAFKA_BOOTSTRAP_SERVERS.into(),
..Default::default()
},
infra: InfrastructureConfig {
infrastructure_enabled: false,
infrastructure_bind: "127.0.0.1".into(),
infrastructure_workers: 1,
enable_tracing: false,
},
index: IndexConfig {
index_dir: None,
index_writer_memory_bytes: 32 * 1024 * 1024,
mode: Default::default(),
sync_interval: Duration::from_secs(2).into(),
},
}
}

Expand Down
21 changes: 12 additions & 9 deletions integration-tests/tests/spog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use integration_tests::{SpogContext, Urlifier};
use integration_tests::{id, SpogContext, Urlifier};
use reqwest::StatusCode;
use serde_json::{json, Value};
use test_context::test_context;
Expand Down Expand Up @@ -114,38 +114,41 @@ async fn spog_crda_integration(context: &mut SpogContext) {
#[ntest::timeout(120_000)]
async fn spog_search_correlation(context: &mut SpogContext) {
let input = serde_json::from_str(include_str!("testdata/correlation/stf-1.5.json")).unwrap();
let sbom_id = "test-stf-1.5-correlation";
context.bombastic.upload_sbom(sbom_id, &input).await;
let sbom_id = id("test-search-correlation");
context.bombastic.upload_sbom(&sbom_id, &input).await;

let input = serde_json::from_str(include_str!("testdata/correlation/rhsa-2023_1529.json")).unwrap();
let mut input: serde_json::Value =
serde_json::from_str(include_str!("testdata/correlation/rhsa-2023_1529.json")).unwrap();
let vex_id = id("test-search-correlation");
input["document"]["tracking"]["id"] = json!(vex_id);
context.vexination.upload_vex(&input).await;

let client = reqwest::Client::new();
// Ensure we can search for the data. We want to allow the
// indexer time to do its thing, so might need to retry
loop {
let response = client
.get(context.urlify("/api/v1/package/search?q=id%3Atest-stf-1.5-correlation"))
.get(context.urlify(format!("/api/v1/package/search?q=id%3A{sbom_id}")))
.inject_token(&context.provider.provider_user)
.await
.unwrap()
.send()
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.status(), StatusCode::OK, "unexpected status from search");
let payload: Value = response.json().await.unwrap();
if payload["total"].as_u64().unwrap() >= 1 {
assert_eq!(payload["result"][0]["name"], json!("stf-1.5"));
assert_eq!(payload["result"][0]["name"], json!("stf-1.5"), "unexpected name");

let data: spog_model::search::PackageSummary =
serde_json::from_value(payload["result"][0].clone()).unwrap();
// println!("Data: {:?}", data);
// we need to have some information
assert!(data.advisories.is_some());
assert!(data.advisories.is_some(), "missing advisories");
// Data might not be available until vex index is synced
let advisories = data.advisories.unwrap();
if advisories > 0 {
assert_eq!(advisories, 1);
assert_eq!(advisories, 1, "too many advisories found");
break;
}
}
Expand Down

0 comments on commit c4ce3be

Please sign in to comment.