perform some validation of the repository argument
This commit is contained in:
parent
1429b6bedf
commit
1cb7ee40fe
67
Cargo.lock
generated
67
Cargo.lock
generated
@ -142,6 +142,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_with",
|
"serde_with",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -172,6 +173,15 @@ version = "1.0.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "form_urlencoded"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
||||||
|
dependencies = [
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.12.3"
|
version = "0.12.3"
|
||||||
@ -219,6 +229,16 @@ version = "1.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-bidi",
|
||||||
|
"unicode-normalization",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.9.3"
|
version = "1.9.3"
|
||||||
@ -304,6 +324,12 @@ version = "1.19.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "percent-encoding"
|
||||||
|
version = "2.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "powerfmt"
|
name = "powerfmt"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@ -478,12 +504,53 @@ dependencies = [
|
|||||||
"time-core",
|
"time-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tinyvec_macros"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-bidi"
|
||||||
|
version = "0.3.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.12"
|
version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-normalization"
|
||||||
|
version = "0.1.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
||||||
|
dependencies = [
|
||||||
|
"tinyvec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "url"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
|
||||||
|
dependencies = [
|
||||||
|
"form_urlencoded",
|
||||||
|
"idna",
|
||||||
|
"percent-encoding",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.91"
|
version = "0.2.91"
|
||||||
|
@ -11,6 +11,7 @@ serde = { version = "1.0.196", features = ["derive"] }
|
|||||||
serde_json = "1.0.113"
|
serde_json = "1.0.113"
|
||||||
serde_with = "3.6.1"
|
serde_with = "3.6.1"
|
||||||
tempfile = "3.9.0"
|
tempfile = "3.9.0"
|
||||||
|
url = "2.5.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
@ -37,20 +37,20 @@ impl Container {
|
|||||||
.arg(&image_tag)
|
.arg(&image_tag)
|
||||||
.arg(docker_build_dir);
|
.arg(docker_build_dir);
|
||||||
|
|
||||||
let srcdir = if let Implementation::Hickory { url } = implementation {
|
let repo = if let Implementation::Hickory(repo) = implementation {
|
||||||
Some(url)
|
Some(repo)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
implementation.once().call_once(|| {
|
implementation.once().call_once(|| {
|
||||||
if let Some(srcdir) = srcdir {
|
if let Some(repo) = repo {
|
||||||
let mut cp_r = Command::new("git");
|
let mut cp_r = Command::new("git");
|
||||||
cp_r.args([
|
cp_r.args([
|
||||||
"clone",
|
"clone",
|
||||||
"--depth",
|
"--depth",
|
||||||
"1",
|
"1",
|
||||||
srcdir,
|
repo.as_str(),
|
||||||
&docker_build_dir.join("src").display().to_string(),
|
&docker_build_dir.join("src").display().to_string(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
//! A test framework for all things DNS
|
//! A test framework for all things DNS
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
use std::path::Path;
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
|
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
pub use crate::container::Network;
|
pub use crate::container::Network;
|
||||||
pub use crate::fqdn::FQDN;
|
pub use crate::fqdn::FQDN;
|
||||||
pub use crate::resolver::Resolver;
|
pub use crate::resolver::Resolver;
|
||||||
@ -24,7 +28,33 @@ pub mod zone_file;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Implementation {
|
pub enum Implementation {
|
||||||
Unbound,
|
Unbound,
|
||||||
Hickory { url: String },
|
Hickory(Repository<'static>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Repository<'a> {
|
||||||
|
inner: Cow<'a, str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Repository<'_> {
|
||||||
|
fn as_str(&self) -> &str {
|
||||||
|
&self.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// checks that `input` looks like a valid repository which can be either local or remote
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// this function panics if `input` is not a local `Path` that exists or a well-formed URL
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub fn Repository(input: impl Into<Cow<'static, str>>) -> Repository<'static> {
|
||||||
|
let input = input.into();
|
||||||
|
assert!(
|
||||||
|
Path::new(&*input).exists() || Url::parse(&input).is_ok(),
|
||||||
|
"{input} is not a valid repository"
|
||||||
|
);
|
||||||
|
Repository { inner: input }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Implementation {
|
impl Implementation {
|
||||||
@ -74,9 +104,7 @@ pub fn subject() -> Implementation {
|
|||||||
|
|
||||||
if subject.starts_with("hickory") {
|
if subject.starts_with("hickory") {
|
||||||
if let Some(url) = subject.strip_prefix("hickory ") {
|
if let Some(url) = subject.strip_prefix("hickory ") {
|
||||||
Implementation::Hickory {
|
Implementation::Hickory(Repository(url.to_string()))
|
||||||
url: url.to_string(),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
panic!("the syntax of DNS_TEST_SUBJECT is 'hickory $URL', e.g. 'hickory /tmp/hickory' or 'hickory https://github.com/owner/repo'")
|
panic!("the syntax of DNS_TEST_SUBJECT is 'hickory $URL', e.g. 'hickory /tmp/hickory' or 'hickory https://github.com/owner/repo'")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user