Fix test environment variables.

This commit is contained in:
Tim Bruijnzeels
2020-12-10 15:39:06 +01:00
parent 6c50869241
commit 0f54bf73ef
8 changed files with 49 additions and 32 deletions
+2 -3
View File
@@ -8,10 +8,9 @@
extern crate krill;
use std::env;
use std::sync::Arc;
use krill::constants::KRILL_ENV_TESTBED_ENABLED;
use krill::constants::testbed_enabled;
use krill::daemon::http::server;
use krill::daemon::krillserver::KrillMode;
@@ -19,7 +18,7 @@ use krill::daemon::krillserver::KrillMode;
async fn main() {
match server::parse_config() {
Ok(config) => {
let mode = if env::var(KRILL_ENV_TESTBED_ENABLED).is_ok() {
let mode = if testbed_enabled() {
KrillMode::Testbed
} else {
KrillMode::Ca
+3 -3
View File
@@ -1,4 +1,4 @@
use std::{env, fmt};
use std::fmt;
use chrono::Duration;
use tokio::sync::RwLock;
@@ -11,7 +11,7 @@ use crate::commons::bgp::{
BgpAnalysisEntry, BgpAnalysisReport, BgpAnalysisState, BgpAnalysisSuggestion, IpRange, RisDumpError, RisDumpLoader,
ValidatedAnnouncement,
};
use crate::constants::{BGP_RIS_REFRESH_MINUTES, KRILL_ENV_TEST_ANN};
use crate::constants::{test_announcements_enabled, BGP_RIS_REFRESH_MINUTES};
//------------ BgpAnalyser -------------------------------------------------
@@ -23,7 +23,7 @@ pub struct BgpAnalyser {
impl BgpAnalyser {
pub fn new(ris_enabled: bool, ris_v4_uri: &str, ris_v6_uri: &str) -> Self {
if env::var(KRILL_ENV_TEST_ANN).is_ok() {
if test_announcements_enabled() {
Self::with_test_announcements()
} else {
let dumploader = if ris_enabled {
+27 -5
View File
@@ -13,17 +13,39 @@ pub const KRILL_DEFAULT_CONFIG_FILE: &str = "./defaults/krill.conf";
#[cfg(feature = "multi-user")]
pub const KRILL_DEFAULT_CONFIG_FILE: &str = "./defaults/krill-multi-user.conf";
pub const KRILL_ENV_TEST_ANN: &str = "KRILL_TEST_ANN";
pub const KRILL_ENV_TEST_UNIT_DATA: &str = "KRILL_TEST_UNIT_DATA";
const KRILL_ENV_TEST: &str = "KRILL_TEST";
const KRILL_ENV_TEST_ANN: &str = "KRILL_TEST_ANN";
const KRILL_ENV_TESTBED_ENABLED: &str = "KRILL_TESTBED_ENABLED";
pub const KRILL_ENV_UPGRADE_ONLY: &str = "KRILL_UPGRADE_ONLY";
pub const KRILL_ENV_FORCE_RECOVER: &str = "KRILL_FORCE_RECOVER";
pub const KRILL_ENV_REPO_ENABLED: &str = "KRILL_REPO_ENABLED";
pub const KRILL_ENV_TESTBED_ENABLED: &str = "KRILL_TESTBED_ENABLED";
pub const KRILL_ENV_USE_TA: &str = "KRILL_USE_TA";
pub const KRILL_ENV_LOG_LEVEL: &str = "KRILL_LOG_LEVEL";
pub const KRILL_ENV_AUTH_TOKEN: &str = "KRILL_AUTH_TOKEN";
pub const KRILL_ENV_SERVER_PORT: &str = "KRILL_SERVER_PORT";
pub fn enable_test_mode() {
std::env::set_var(KRILL_ENV_TEST, "1");
}
pub fn test_mode_enabled() -> bool {
std::env::var(KRILL_ENV_TEST).is_ok()
}
pub fn enable_testbed() {
std::env::set_var(KRILL_ENV_TESTBED_ENABLED, "1");
}
pub fn testbed_enabled() -> bool {
std::env::var(KRILL_ENV_TESTBED_ENABLED).is_ok()
}
pub fn enable_test_announcements() {
std::env::set_var(KRILL_ENV_TEST_ANN, "1");
}
pub fn test_announcements_enabled() -> bool {
std::env::var(KRILL_ENV_TEST_ANN).is_ok()
}
pub const CASERVER_DIR: &str = "cas";
pub const PUBSERVER_DFLT: &str = "0";
+2 -1
View File
@@ -25,6 +25,7 @@ use crate::commons::eventsourcing::{Aggregate, StoredEvent};
use crate::commons::remote::rfc6492;
use crate::commons::remote::rfc8183;
use crate::commons::KrillResult;
use crate::constants::test_mode_enabled;
use crate::daemon::ca::events::ChildCertificateUpdates;
use crate::daemon::ca::rc::PublishMode;
use crate::daemon::ca::{
@@ -659,7 +660,7 @@ impl CertAuth {
let (rcn, limit, csr) = request.unpack();
let csr_info = CsrInfo::try_from(&csr)?;
if !csr_info.global_uris() && cfg!(not(debug_assertions)) {
if !csr_info.global_uris() && !test_mode_enabled() {
return Err(Error::invalid_csr(
"MUST use hostnames in URIs for certificate requests.",
));
-4
View File
@@ -367,10 +367,6 @@ impl Config {
0
}
}
pub fn testbed_enabled(&self) -> bool {
env::var(KRILL_ENV_TESTBED_ENABLED).is_ok()
}
}
/// # Create
+7 -8
View File
@@ -9,8 +9,9 @@ use tokio::runtime::Runtime;
use rpki::x509::Time;
use crate::commons::{actor::Actor, api::Handle};
use crate::commons::bgp::BgpAnalyser;
use crate::commons::{actor::Actor, api::Handle};
use crate::constants::test_mode_enabled;
#[cfg(feature = "multi-user")]
use crate::daemon::auth::common::session::LoginSessionCache;
use crate::daemon::ca::CaServer;
@@ -68,7 +69,6 @@ impl Scheduler {
event_queue,
caserver.clone(),
pubserver.clone(),
config.testbed_enabled(),
actor.clone(),
));
@@ -77,7 +77,8 @@ impl Scheduler {
}
let announcements_refresh = make_announcements_refresh(bgp_analyser);
let archive_old_commands = make_archive_old_commands(caserver, pubserver, config.archive_threshold_days, actor.clone());
let archive_old_commands =
make_archive_old_commands(caserver, pubserver, config.archive_threshold_days, actor.clone());
#[cfg(feature = "multi-user")]
let login_cache_sweeper_sh = make_login_cache_sweeper_sh(login_session_cache);
@@ -98,7 +99,6 @@ fn make_cas_event_triggers(
event_queue: Arc<EventQueueListener>,
caserver: Arc<CaServer>,
pubserver: Option<Arc<PubServer>>,
test_mode: bool,
actor: Actor,
) -> ScheduleHandle {
let mut scheduler = clokwerk::Scheduler::new();
@@ -127,11 +127,11 @@ fn make_cas_event_triggers(
}
QueueEvent::Delta(handle, _version) => {
try_publish(&event_queue, caserver.clone(), pubserver.clone(), handle, test_mode, &actor).await
try_publish(&event_queue, caserver.clone(), pubserver.clone(), handle, &actor).await
}
QueueEvent::ReschedulePublish(handle, last_try) => {
if Time::five_minutes_ago().timestamp() > last_try.timestamp() {
try_publish(&event_queue, caserver.clone(), pubserver.clone(), handle, test_mode, &actor).await
try_publish(&event_queue, caserver.clone(), pubserver.clone(), handle, &actor).await
} else {
event_queue.push_back(QueueEvent::ReschedulePublish(handle, last_try));
}
@@ -217,14 +217,13 @@ async fn try_publish(
caserver: Arc<CaServer>,
pubserver: Option<Arc<PubServer>>,
ca: Handle,
test_mode: bool,
actor: &Actor,
) {
info!("Try to publish for '{}'", ca);
let publisher = CaPublisher::new(caserver.clone(), pubserver);
if let Err(e) = publisher.publish(&ca, actor).await {
if test_mode {
if test_mode_enabled() {
error!("Failed to publish for '{}', error: {}", ca, e);
} else {
error!("Failed to publish for '{}' will reschedule, error: {}", ca, e);
+4 -2
View File
@@ -20,7 +20,9 @@ use crate::commons::eventsourcing::Aggregate;
use crate::commons::remote::rfc8183;
use crate::commons::util::file;
use crate::commons::KrillResult;
use crate::constants::{REPOSITORY_NOTIFICATION_RETAIN_SECONDS, REPOSITORY_RRDP_DIR, REPOSITORY_RSYNC_DIR};
use crate::constants::{
test_mode_enabled, REPOSITORY_NOTIFICATION_RETAIN_SECONDS, REPOSITORY_RRDP_DIR, REPOSITORY_RSYNC_DIR,
};
use crate::pubd::events::RrdpSessionReset;
use crate::pubd::publishers::Publisher;
use crate::pubd::{Cmd, CmdDet, Evt, EvtDet, Ini, RrdpUpdate};
@@ -265,7 +267,7 @@ impl RrdpServer {
let mut retain_secs = REPOSITORY_NOTIFICATION_RETAIN_SECONDS;
if cfg!(test) {
if test_mode_enabled() {
retain_secs = 1;
}
+4 -6
View File
@@ -1,12 +1,12 @@
//! Helper functions for testing Krill.
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use std::{env, fs};
use bytes::Bytes;
@@ -30,7 +30,6 @@ use crate::commons::crypto::SignSupport;
use crate::commons::remote::rfc8183;
use crate::commons::remote::rfc8183::{ChildRequest, RepositoryResponse};
use crate::commons::util::httpclient;
use crate::constants::{KRILL_ENV_TESTBED_ENABLED, KRILL_ENV_TEST_ANN, KRILL_ENV_TEST_UNIT_DATA};
use crate::daemon::ca::{ta_handle, ResourceTaggedAttestation, RtaContentRequest, RtaPrepareRequest};
use crate::daemon::http::server;
@@ -75,10 +74,9 @@ pub async fn server_ready(uri: &str) -> bool {
}
fn test_config(dir: &PathBuf) -> Config {
env::set_var(KRILL_ENV_TEST_UNIT_DATA, dir.to_string_lossy().to_string());
env::set_var(KRILL_ENV_TEST_ANN, "1");
env::set_var(KRILL_ENV_TESTBED_ENABLED, "1");
crate::constants::enable_test_mode();
crate::constants::enable_testbed();
crate::constants::enable_test_announcements();
Config::test(dir)
}