Skip to content

Commit 400ca81

Browse files
authored
Merge pull request #924 from fabriziosestito/fix/cannot-run-single-test
fix(integration tests): cannot run single integration test
2 parents cac9098 + a11fe44 commit 400ca81

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

tests/common/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ use std::{
99
};
1010
use tempfile::tempdir;
1111

12+
use std::sync::Once;
13+
static START: Once = Once::new();
14+
15+
/// Common setup for tests. This function should be called at the beginning of each test.
16+
pub(crate) fn setup() {
17+
START.call_once(|| {
18+
// Starting from rustls 0.22, each application must set its default crypto provider.
19+
// This setup is done inside of the `main` function of the policy server,
20+
// which is not called in this test.
21+
// Hence we have to setup the crypto provider here.
22+
let crypto_provider = rustls::crypto::ring::default_provider();
23+
crypto_provider
24+
.install_default()
25+
.expect("Failed to install crypto provider");
26+
});
27+
}
28+
1229
pub(crate) fn default_test_config() -> Config {
1330
let policies = HashMap::from([
1431
(

tests/integration_test.rs

+36-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
time::Duration,
1111
};
1212

13-
use common::app;
13+
use common::{app, setup};
1414

1515
use axum::{
1616
body::Body,
@@ -43,6 +43,8 @@ use crate::common::default_test_config;
4343

4444
#[tokio::test]
4545
async fn test_validate() {
46+
setup();
47+
4648
let config = default_test_config();
4749
let app = app(config).await;
4850

@@ -86,6 +88,8 @@ async fn test_validate() {
8688
true,
8789
)]
8890
async fn test_validate_policy_group(#[case] payload: &str, #[case] expected_allowed: bool) {
91+
setup();
92+
8993
let config = default_test_config();
9094
let app = app(config).await;
9195

@@ -147,6 +151,8 @@ async fn test_validate_policy_group(#[case] payload: &str, #[case] expected_allo
147151

148152
#[tokio::test]
149153
async fn test_validate_policy_not_found() {
154+
setup();
155+
150156
let config = default_test_config();
151157
let app = app(config).await;
152158

@@ -166,6 +172,8 @@ async fn test_validate_policy_not_found() {
166172

167173
#[tokio::test]
168174
async fn test_validate_invalid_payload() {
175+
setup();
176+
169177
let config = default_test_config();
170178
let app = app(config).await;
171179

@@ -183,6 +191,8 @@ async fn test_validate_invalid_payload() {
183191

184192
#[tokio::test]
185193
async fn test_validate_raw() {
194+
setup();
195+
186196
let config = default_test_config();
187197
let app = app(config).await;
188198

@@ -211,6 +221,8 @@ async fn test_validate_raw() {
211221

212222
#[tokio::test]
213223
async fn test_validate_policy_group_does_not_do_mutation() {
224+
setup();
225+
214226
let config = default_test_config();
215227
let app = app(config).await;
216228

@@ -264,6 +276,8 @@ async fn test_validate_policy_group_does_not_do_mutation() {
264276

265277
#[tokio::test]
266278
async fn test_validate_raw_policy_not_found() {
279+
setup();
280+
267281
let config = default_test_config();
268282
let app = app(config).await;
269283

@@ -283,6 +297,8 @@ async fn test_validate_raw_policy_not_found() {
283297

284298
#[tokio::test]
285299
async fn test_validate_raw_invalid_payload() {
300+
setup();
301+
286302
let config = default_test_config();
287303
let app = app(config).await;
288304

@@ -300,6 +316,8 @@ async fn test_validate_raw_invalid_payload() {
300316

301317
#[tokio::test]
302318
async fn test_audit() {
319+
setup();
320+
303321
let config = default_test_config();
304322
let app = app(config).await;
305323

@@ -332,6 +350,8 @@ async fn test_audit() {
332350

333351
#[tokio::test]
334352
async fn test_audit_policy_not_found() {
353+
setup();
354+
335355
let config = default_test_config();
336356
let app = app(config).await;
337357

@@ -351,6 +371,8 @@ async fn test_audit_policy_not_found() {
351371

352372
#[tokio::test]
353373
async fn test_audit_invalid_payload() {
374+
setup();
375+
354376
let config = default_test_config();
355377
let app = app(config).await;
356378

@@ -368,6 +390,8 @@ async fn test_audit_invalid_payload() {
368390

369391
#[tokio::test]
370392
async fn test_timeout_protection_accept() {
393+
setup();
394+
371395
let config = default_test_config();
372396
let app = app(config).await;
373397

@@ -390,6 +414,8 @@ async fn test_timeout_protection_accept() {
390414

391415
#[tokio::test]
392416
async fn test_timeout_protection_reject() {
417+
setup();
418+
393419
let config = default_test_config();
394420
let app = app(config).await;
395421

@@ -422,6 +448,8 @@ async fn test_timeout_protection_reject() {
422448

423449
#[tokio::test]
424450
async fn test_verified_policy() {
451+
setup();
452+
425453
let verification_cfg_yml = r#"---
426454
allOf:
427455
- kind: pubKey
@@ -477,6 +505,8 @@ async fn test_verified_policy() {
477505

478506
#[tokio::test]
479507
async fn test_policy_with_invalid_settings() {
508+
setup();
509+
480510
let mut config = default_test_config();
481511
config.policies.insert(
482512
"invalid_settings".to_owned(),
@@ -523,6 +553,8 @@ async fn test_policy_with_invalid_settings() {
523553

524554
#[tokio::test]
525555
async fn test_policy_with_wrong_url() {
556+
setup();
557+
526558
let mut config = default_test_config();
527559
config.policies.insert(
528560
"wrong_url".to_owned(),
@@ -653,14 +685,7 @@ mod certificate_reload_helpers {
653685
async fn test_detect_certificate_rotation() {
654686
use certificate_reload_helpers::*;
655687

656-
// Starting from rustls 0.22, each application must set its default crypto provider.
657-
// This setup is done inside of the `main` function of the policy server,
658-
// which is not called in this test.
659-
// Hence we have to setup the crypto provider here.
660-
let crypto_provider = rustls::crypto::ring::default_provider();
661-
crypto_provider
662-
.install_default()
663-
.expect("Failed to install crypto provider");
688+
setup();
664689

665690
let certs_dir = tempfile::tempdir().unwrap();
666691
let cert_file = certs_dir.path().join("policy-server.pem");
@@ -734,6 +759,8 @@ async fn test_detect_certificate_rotation() {
734759

735760
#[tokio::test]
736761
async fn test_otel() {
762+
setup();
763+
737764
let mut otelc_config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
738765
otelc_config_path.push("tests/data/otel-collector-config.yaml");
739766

0 commit comments

Comments
 (0)