fix(domain): refuse three non-canonical v3 shapes, R5.5 LOW fixes, R5.6 plan
check_v3_shape at read_report_document v3 and parse_envelope (sheet, practitioner as non-objects, severity as non-string); Protocol errors final; DEV address must be an own unicast address. SQL confirm function and DEV keys characterised, no change.
This commit is contained in:
1 parent
13db5539a3
commit
d502dfa923
11 files changed
+369
-37
No files matched your search
@@ -107,11 +107,18 @@ fn required_env(name: &str) -> Result<String, UploadError> {
|
||||
.ok_or_else(|| refuse(UploadKind::Destination, format!("{name} is required")))
|
||||
}
|
||||
|
||||
/// The DEV address counts only if it is one of this machine's own addresses (a socket can be
|
||||
/// bound to it); otherwise it is ignored and only loopback stays allowed.
|
||||
/// The DEV address counts only if it is one of this machine's own unicast addresses: a socket
|
||||
/// binds to it, and connecting it to that address (no packet is sent) keeps it as the local
|
||||
/// end. A subnet broadcast binds but refuses the connect (no `SO_BROADCAST`). Otherwise the
|
||||
/// DEV address is ignored and only loopback stays allowed.
|
||||
fn own_address(host: &str) -> bool {
|
||||
host.parse::<std::net::IpAddr>()
|
||||
.is_ok_and(|ip| std::net::UdpSocket::bind((ip, 0)).is_ok())
|
||||
let Ok(ip) = host.parse::<std::net::IpAddr>() else {
|
||||
return false;
|
||||
};
|
||||
let Ok(socket) = std::net::UdpSocket::bind((ip, 0)) else {
|
||||
return false;
|
||||
};
|
||||
socket.connect((ip, 9)).is_ok() && socket.local_addr().is_ok_and(|a| a.ip() == ip)
|
||||
}
|
||||
|
||||
fn connect() -> Result<Storage, UploadError> {
|
||||
@@ -221,3 +228,41 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::own_address;
|
||||
|
||||
/// `inet` and `brd` addresses of this host, as `ip -4 -o addr` prints them.
|
||||
fn host_addresses() -> (Vec<String>, Vec<String>) {
|
||||
let listing = std::process::Command::new("ip")
|
||||
.args(["-4", "-o", "addr"])
|
||||
.output()
|
||||
.map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
|
||||
.unwrap_or_default();
|
||||
let field = |line: &str, name: &str| {
|
||||
let mut words = line.split_whitespace();
|
||||
words.find(|w| *w == name)?;
|
||||
Some(words.next()?.split('/').next()?.to_owned())
|
||||
};
|
||||
let lines: Vec<&str> = listing.lines().collect();
|
||||
let unicast = lines.iter().filter_map(|l| field(l, "inet")).collect();
|
||||
let broadcast = lines.iter().filter_map(|l| field(l, "brd")).collect();
|
||||
(unicast, broadcast)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_an_own_unicast_address_counts_as_the_dev_address() {
|
||||
assert!(own_address("127.0.0.1"));
|
||||
for refused in ["255.255.255.255", "203.0.113.7", "not-an-ip", ""] {
|
||||
assert!(!own_address(refused), "{refused}");
|
||||
}
|
||||
let (unicast, broadcast) = host_addresses();
|
||||
for address in &unicast {
|
||||
assert!(own_address(address), "{address}");
|
||||
}
|
||||
for address in &broadcast {
|
||||
assert!(!own_address(address), "broadcast {address}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,13 +193,13 @@ fn is_transient(error: &ureq::Error) -> bool {
|
||||
| ureq::Error::Timeout(_)
|
||||
| ureq::Error::HostNotFound
|
||||
| ureq::Error::ConnectionFailed
|
||||
| ureq::Error::Protocol(_)
|
||||
)
|
||||
}
|
||||
|
||||
/// Not retried: a body over its cap is a destination holding something it should not (an
|
||||
/// object larger than any drawing), anything else a request the tool cannot build (a key with
|
||||
/// characters a header refuses). The key itself is never part of the message.
|
||||
/// object larger than any drawing); anything else is a request the tool cannot build or an
|
||||
/// answer it cannot read (a key a header refuses, a malformed HTTP answer: `Protocol`), the
|
||||
/// same on every attempt. The key itself is never part of the message.
|
||||
fn final_error(error: &ureq::Error) -> UploadError {
|
||||
match error {
|
||||
ureq::Error::BodyExceedsLimit(limit) => refuse(
|
||||
|
||||
Reference in new issue
Block a user