put: pre-upload mistake guards adapted from cpaelzer's dput hooks
Stop uploads whose Changed-By is a container or VM identity (ubuntu@, root@) and uploads of native packages carrying debian/patches/series (quilt patches never apply there). Question, through the prompter and defaulting to no, uploads without Launchpad bug references, with placeholder bug numbers (1234, 9999), with a backport suffix not matching the target series, and Ubuntu-marked versions whose Maintainer is not an ubuntu.com address (update-maintainer forgotten). --force skips the guards, together with the duplicate and superseded checks it already bypassed. Two deviations from the hooks: the maintainer check also covers point-update SRU versions (1ubuntu2.3), which dpkg's \dubuntu\d*$ reading misses, and the ~ppa version hook is left out: pkh put uploads to PPAs only, where keeping the archive version (an SRU test build) is a legitimate choice. The archive half belongs with the future archive uploads. parse changed_by, maintainer and launchpad_bugs_fixed from the .changes, and share the source-tree decision with the Section check (the tree-level guards skip when the upload was collected away from the tree).
This commit is contained in:
1 parent
8fceb13bcf
commit
891bacd055
4 files changed
+670
-5
No files matched your search
+1
-1
@@ -367,7 +367,7 @@ fn main() {
|
||||
.about("Upload the built source package to a PPA")
|
||||
.arg(arg!(--ppa <ppa> "Upload to a PPA (format: user/ppa_name)"))
|
||||
.arg(arg!([changes] "Explicit .changes file to upload (default: the one built from this package, next to the source tree)").required(false))
|
||||
.arg(arg!(--force "Upload even if this exact .changes file was already uploaded to the target")),
|
||||
.arg(arg!(--force "Upload even if this exact .changes file was already uploaded to the target, skipping the pre-upload mistake checks")),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("deb")
|
||||
|
||||
+14
-1
@@ -57,6 +57,13 @@ pub struct ChangesFile {
|
||||
pub version: String,
|
||||
/// `Distribution` field.
|
||||
pub distribution: String,
|
||||
/// `Changed-By` field (the changelog maintainer), when present.
|
||||
pub changed_by: Option<String>,
|
||||
/// `Maintainer` field (the source stanza maintainer), when present.
|
||||
pub maintainer: Option<String>,
|
||||
/// `Launchpad-Bugs-Fixed` field (Launchpad bugs referenced in the
|
||||
/// changelog), when present.
|
||||
pub launchpad_bugs_fixed: Option<String>,
|
||||
/// Files to upload, in listing order. The `.changes` file itself is not
|
||||
/// part of this list: it is uploaded last, like dput does.
|
||||
pub files: Vec<FileEntry>,
|
||||
@@ -146,6 +153,9 @@ fn parse_body(content: &str, path: &Path) -> Result<ChangesFile, Box<dyn std::er
|
||||
source: source.to_string(),
|
||||
version: version.to_string(),
|
||||
distribution: distribution.to_string(),
|
||||
changed_by: fields.get("Changed-By").map(str::to_string),
|
||||
maintainer: fields.get("Maintainer").map(str::to_string),
|
||||
launchpad_bugs_fixed: fields.get("Launchpad-Bugs-Fixed").map(str::to_string),
|
||||
files,
|
||||
})
|
||||
}
|
||||
@@ -262,7 +272,7 @@ iQIzBAABCgAdFiEEfakefingerprintXfakecommentlength
|
||||
"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA512\n\n\
|
||||
Format: 1.8\nSource: hello\nBinary: hello\nArchitecture: source\n\
|
||||
Version: 1.0-1\nDistribution: {distribution}\nUrgency: medium\n\
|
||||
Maintainer: A B <a@b>\nChecksums-Sha256:{}\n",
|
||||
Maintainer: A B <a@b>\nChanged-By: C D <c@d>\nChecksums-Sha256:{}\n",
|
||||
// deb822 continuation lines are indented
|
||||
cs.field_sha256().replace('\n', "\n ")
|
||||
);
|
||||
@@ -282,6 +292,9 @@ iQIzBAABCgAdFiEEfakefingerprintXfakecommentlength
|
||||
assert_eq!(changes.source, "hello");
|
||||
assert_eq!(changes.version, "1.0-1");
|
||||
assert_eq!(changes.distribution, "resolute");
|
||||
assert_eq!(changes.changed_by.as_deref(), Some("C D <c@d>"));
|
||||
assert_eq!(changes.maintainer.as_deref(), Some("A B <a@b>"));
|
||||
assert_eq!(changes.launchpad_bugs_fixed, None);
|
||||
assert_eq!(changes.files.len(), 2);
|
||||
assert_eq!(changes.files[0].name, "hello_1.0-1.dsc");
|
||||
|
||||
|
||||
@@ -0,0 +1,633 @@
|
||||
//! Pre-upload mistake guards: refuse or question uploads carrying common
|
||||
//! mistakes the archive queue would accept silently, before anything
|
||||
//! leaves the machine. Adapted from Christian Ehrhardt's dput hooks
|
||||
//! (`ubuntu-helpers/cpaelzer/.dput.d/hooks`), which guard the same
|
||||
//! mistakes for plain `dput` uploads.
|
||||
//!
|
||||
//! Each guard is a pure [`Verdict`], so every decision is testable
|
||||
//! without a terminal; [`run`] applies them in order, asking the prompter
|
||||
//! for the questionable ones. `--force` skips the whole module (the
|
||||
//! caller decides): it is the explicit "upload anyway" answer.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::debian::version::DebianVersion;
|
||||
use crate::report::Prompter;
|
||||
|
||||
use super::changes::ChangesFile;
|
||||
|
||||
/// What one guard decided about the upload.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum Verdict {
|
||||
/// No mistake detected.
|
||||
Proceed,
|
||||
/// The upload may proceed only if the user confirms; the prompter's
|
||||
/// default answer is "no", so headless runs refuse.
|
||||
Ask {
|
||||
/// What looks wrong, logged before the question and reused as the
|
||||
/// refusal reason.
|
||||
reason: String,
|
||||
/// The yes/no question.
|
||||
question: String,
|
||||
},
|
||||
/// Refuse outright: the mistake is unambiguous.
|
||||
Refuse(String),
|
||||
}
|
||||
|
||||
/// Run every guard. `tree` is the source directory the tree-level checks
|
||||
/// validate, `None` when the upload does not carry one next to it
|
||||
/// (an explicit `--changes` collected away from the tree).
|
||||
pub(super) async fn run(
|
||||
changes: &ChangesFile,
|
||||
tree: Option<&Path>,
|
||||
prompter: &dyn Prompter,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let target = target_series_release(&changes.distribution).await;
|
||||
for verdict in [
|
||||
bad_author(changes),
|
||||
no_bug(changes),
|
||||
placeholder_bug(changes),
|
||||
release_mismatch(changes, target.as_ref()),
|
||||
update_maintainer(changes),
|
||||
patches_in_native(changes, tree),
|
||||
] {
|
||||
apply(verdict, prompter)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Apply one guard's verdict: questions go to the prompter (whose default
|
||||
/// answer refuses), refusals become upload errors. Both end in the same
|
||||
/// `--force` hint, the single way past the guards.
|
||||
fn apply(verdict: Verdict, prompter: &dyn Prompter) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match verdict {
|
||||
Verdict::Proceed => Ok(()),
|
||||
Verdict::Refuse(reason) => Err(refusal(reason)),
|
||||
Verdict::Ask { reason, question } => {
|
||||
log::warn!("{reason}");
|
||||
if prompter.confirm(&question, false)? {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(refusal(reason))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The error for a guard that said no: the reason plus the way out.
|
||||
fn refusal(reason: String) -> Box<dyn std::error::Error> {
|
||||
format!("{reason} (pass --force to upload anyway)").into()
|
||||
}
|
||||
|
||||
/// Stop uploads whose `Changed-By` is a `ubuntu@` or `root@` address:
|
||||
/// built in a container or VM, the changelog picked up the machine's
|
||||
/// default identity, and sponsoring or publishing would push that address
|
||||
/// into the archive.
|
||||
fn bad_author(changes: &ChangesFile) -> Verdict {
|
||||
let Some(author) = &changes.changed_by else {
|
||||
return Verdict::Proceed;
|
||||
};
|
||||
if author.contains("ubuntu@") || author.contains("root@") {
|
||||
Verdict::Refuse(format!(
|
||||
"Changed-By '{author}' carries an ubuntu@ or root@ address, \
|
||||
usually a container or VM default identity leaked into the \
|
||||
changelog: set your real identity (DEBEMAIL/DEBFULLNAME or \
|
||||
'git config user.email'), fix debian/changelog and rebuild \
|
||||
with `pkh build`"
|
||||
))
|
||||
} else {
|
||||
Verdict::Proceed
|
||||
}
|
||||
}
|
||||
|
||||
/// Question uploads that reference no Launchpad bug: an upload almost
|
||||
/// always fixes a bug, and the missing reference only shows up in the
|
||||
/// changelog later review.
|
||||
fn no_bug(changes: &ChangesFile) -> Verdict {
|
||||
let has_bugs = changes
|
||||
.launchpad_bugs_fixed
|
||||
.as_deref()
|
||||
.is_some_and(|bugs| !bugs.trim().is_empty());
|
||||
if has_bugs {
|
||||
return Verdict::Proceed;
|
||||
}
|
||||
Verdict::Ask {
|
||||
reason: "the upload references no Launchpad bug: add 'LP: #NNN' to \
|
||||
the changelog entry for the bug it fixes"
|
||||
.to_string(),
|
||||
question: "Upload without Launchpad bug references?".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Question uploads whose bug numbers are common placeholders (`1234`,
|
||||
/// `9999`): the entry was written before the real bug number was known
|
||||
/// and the placeholder would end up in the archive.
|
||||
fn placeholder_bug(changes: &ChangesFile) -> Verdict {
|
||||
let Some(bugs) = &changes.launchpad_bugs_fixed else {
|
||||
return Verdict::Proceed;
|
||||
};
|
||||
let placeholders = ["1234", "9999"];
|
||||
let flagged: Vec<String> = bug_numbers(bugs)
|
||||
.into_iter()
|
||||
.filter(|bug| placeholders.iter().any(|p| bug.starts_with(p)))
|
||||
.collect();
|
||||
if flagged.is_empty() {
|
||||
return Verdict::Proceed;
|
||||
}
|
||||
Verdict::Ask {
|
||||
reason: format!(
|
||||
"Launchpad bug reference(s) {} look like placeholder numbers",
|
||||
flagged.join(", ")
|
||||
),
|
||||
question: "Upload with placeholder bug references?".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The bug numbers of a `Launchpad-Bugs-Fixed` value, as strings so the
|
||||
/// placeholder prefixes keep working whatever separator the field carries
|
||||
/// (dpkg renders spaces, the changelog convention uses commas).
|
||||
fn bug_numbers(bugs: &str) -> Vec<String> {
|
||||
bugs.split(|c: char| !c.is_ascii_digit())
|
||||
.filter(|token| !token.is_empty())
|
||||
.map(str::to_string)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Question uploads whose backport suffix does not match the target
|
||||
/// series: a version like `1.0-0ubuntu1~20.10` uploaded to `focal`
|
||||
/// (release `20.04`) carries the wrong series' number.
|
||||
///
|
||||
/// `target` is the target series' `(codename, release number)`, `None`
|
||||
/// when it is not a versioned Ubuntu series (the check then skips).
|
||||
fn release_mismatch(changes: &ChangesFile, target: Option<&(String, String)>) -> Verdict {
|
||||
let Some((codename, number)) = target else {
|
||||
return Verdict::Proceed;
|
||||
};
|
||||
let Some(ubuntu_idx) = changes.version.find("ubuntu") else {
|
||||
return Verdict::Proceed;
|
||||
};
|
||||
// Only the part after `ubuntu` is scanned: upstream versions carry
|
||||
// their own numbers, and a date there (`24.09.1`) is not a series
|
||||
// marker. dpkg scans the same span (everything following `ubuntu`).
|
||||
let ubuntu_part = &changes.version[ubuntu_idx + "ubuntu".len()..];
|
||||
let mismatched: Vec<&str> = release_numbers(ubuntu_part)
|
||||
.into_iter()
|
||||
.filter(|found| found != number)
|
||||
.collect();
|
||||
if mismatched.is_empty() {
|
||||
return Verdict::Proceed;
|
||||
}
|
||||
Verdict::Ask {
|
||||
reason: format!(
|
||||
"the version {} carries {} but the target series {} is {}: a \
|
||||
backport suffix does not match the series it uploads to",
|
||||
changes.version,
|
||||
mismatched.join(", "),
|
||||
codename,
|
||||
number
|
||||
),
|
||||
question: "Upload with a backport suffix not matching the target series?".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Every `\d\d.\d\d` release-looking number in `text`, unique and in
|
||||
/// order. A byte scan instead of a regex: the pattern can overlap itself
|
||||
/// (`23.45.67` holds two), which the regex crate cannot express.
|
||||
fn release_numbers(text: &str) -> Vec<&str> {
|
||||
let bytes = text.as_bytes();
|
||||
let mut found = Vec::new();
|
||||
for (i, window) in bytes.windows(5).enumerate() {
|
||||
let is_release = window[0].is_ascii_digit()
|
||||
&& window[1].is_ascii_digit()
|
||||
&& window[2] == b'.'
|
||||
&& window[3].is_ascii_digit()
|
||||
&& window[4].is_ascii_digit();
|
||||
// A match starts on an ASCII digit, so the byte offset is a char
|
||||
// boundary and the slice is always valid.
|
||||
if is_release && !found.contains(&&text[i..i + 5]) {
|
||||
found.push(&text[i..i + 5]);
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
/// The `(codename, release number)` of the changes' target series, when it
|
||||
/// is a versioned Ubuntu series; `None` otherwise (pocket suffixes like
|
||||
/// `focal-proposed` resolve through the codename, non-Ubuntu series and
|
||||
/// lookup failures skip the release check).
|
||||
async fn target_series_release(distribution: &str) -> Option<(String, String)> {
|
||||
let codename = distribution.split('-').next().unwrap_or(distribution);
|
||||
match crate::distro_info::get_series_release_number(codename).await {
|
||||
Ok(Some((dist, number))) if dist == "ubuntu" => Some((codename.to_string(), number)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Question Ubuntu-marked versions (`1.0-1ubuntuN`) whose `Maintainer` is
|
||||
/// not an ubuntu.com address: carrying Ubuntu changes without running
|
||||
/// `update-maintainer` leaves them owned by the original (usually Debian)
|
||||
/// maintainer.
|
||||
fn update_maintainer(changes: &ChangesFile) -> Verdict {
|
||||
if !ubuntu_marked_version(&changes.version) {
|
||||
return Verdict::Proceed;
|
||||
}
|
||||
let Some(maintainer) = &changes.maintainer else {
|
||||
return Verdict::Proceed;
|
||||
};
|
||||
if has_ubuntu_maintainer(maintainer) {
|
||||
return Verdict::Proceed;
|
||||
}
|
||||
Verdict::Ask {
|
||||
reason: format!(
|
||||
"the version {} carries Ubuntu changes but the Maintainer \
|
||||
'{maintainer}' is not an ubuntu.com address: run \
|
||||
'update-maintainer' (ubuntu-dev-tools) and rebuild, so Ubuntu \
|
||||
modifications are owned by an Ubuntu maintainer",
|
||||
changes.version
|
||||
),
|
||||
question: "Upload without an ubuntu.com maintainer?".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the version carries Ubuntu's own revision marker: an `ubuntu`
|
||||
/// word right after a digit, with only digits and dots between it and the
|
||||
/// end of the version (`1.0-1ubuntu1`, `1.0-1ubuntu2.3`). Anchoring at the
|
||||
/// end keeps upstream components that merely contain `ubuntu`
|
||||
/// (`1.0+gitubuntu-main`) out; the point-update digits extend dpkg's
|
||||
/// `\dubuntu\d*$` reading, which misses `1ubuntu2.3` SRU versions.
|
||||
fn ubuntu_marked_version(version: &str) -> bool {
|
||||
version.match_indices("ubuntu").any(|(idx, _)| {
|
||||
let before = version[..idx]
|
||||
.chars()
|
||||
.last()
|
||||
.is_some_and(|c| c.is_ascii_digit());
|
||||
let after = &version[idx + "ubuntu".len()..];
|
||||
before && after.chars().all(|c| c.is_ascii_digit() || c == '.')
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the maintainer address is an ubuntu.com one: the address
|
||||
/// `update-maintainer` sets (`ubuntu-devel-discuss@lists.ubuntu.com`) or
|
||||
/// an Ubuntu developer's. The boundary check (an `@` or `.` before
|
||||
/// `ubuntu.com`) keeps look-alike domains like `notubuntu.com` in.
|
||||
fn has_ubuntu_maintainer(maintainer: &str) -> bool {
|
||||
let Some(lt) = maintainer.rfind('<') else {
|
||||
return false;
|
||||
};
|
||||
let email = maintainer[lt + 1..].trim_end_matches('>');
|
||||
email.ends_with("@ubuntu.com") || email.ends_with(".ubuntu.com")
|
||||
}
|
||||
|
||||
/// Refuse native packages carrying `debian/patches/series`: quilt patches
|
||||
/// are never applied in a native package, so the fixes they carry would
|
||||
/// silently miss the build.
|
||||
fn patches_in_native(changes: &ChangesFile, tree: Option<&Path>) -> Verdict {
|
||||
let Some(tree) = tree else {
|
||||
return Verdict::Proceed;
|
||||
};
|
||||
if !is_native(tree, &changes.version) || !tree.join("debian/patches/series").is_file() {
|
||||
return Verdict::Proceed;
|
||||
}
|
||||
Verdict::Refuse(
|
||||
"the package is native but debian/patches/series exists: quilt \
|
||||
patches are never applied in a native package, so the fixes they \
|
||||
carry would silently miss the build. Fold the patches into the \
|
||||
source or switch debian/source/format to '3.0 (quilt)'"
|
||||
.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether the package in `tree` is native: `debian/source/format` says so
|
||||
/// when present, otherwise the version decides (an upload without a
|
||||
/// Debian revision is native by construction).
|
||||
fn is_native(tree: &Path, version: &str) -> bool {
|
||||
match std::fs::read_to_string(tree.join("debian/source/format")) {
|
||||
Ok(format) => format.trim().ends_with("(native)"),
|
||||
Err(_) => {
|
||||
DebianVersion::parse(version).is_ok_and(|parsed| parsed.debian_revision.is_none())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A changes file with these fields, everything else minimal.
|
||||
fn changes(version: &str, changed_by: Option<&str>, maintainer: Option<&str>) -> ChangesFile {
|
||||
changes_with_bugs(version, changed_by, maintainer, None)
|
||||
}
|
||||
|
||||
/// A changes file that also carries a `Launchpad-Bugs-Fixed` value.
|
||||
fn changes_with_bugs(
|
||||
version: &str,
|
||||
changed_by: Option<&str>,
|
||||
maintainer: Option<&str>,
|
||||
bugs: Option<&str>,
|
||||
) -> ChangesFile {
|
||||
ChangesFile {
|
||||
path: PathBuf::from("hello_1.0-1_source.changes"),
|
||||
source: "hello".to_string(),
|
||||
version: version.to_string(),
|
||||
distribution: "resolute".to_string(),
|
||||
changed_by: changed_by.map(str::to_string),
|
||||
maintainer: maintainer.map(str::to_string),
|
||||
launchpad_bugs_fixed: bugs.map(str::to_string),
|
||||
files: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_author_stops_machine_identities() {
|
||||
assert_eq!(
|
||||
bad_author(&changes("1.0-1", Some("root <root@localhost>"), None)),
|
||||
Verdict::Refuse(
|
||||
"Changed-By 'root <root@localhost>' carries an ubuntu@ or \
|
||||
root@ address, usually a container or VM default identity \
|
||||
leaked into the changelog: set your real identity \
|
||||
(DEBEMAIL/DEBFULLNAME or 'git config user.email'), fix \
|
||||
debian/changelog and rebuild with `pkh build`"
|
||||
.to_string()
|
||||
)
|
||||
);
|
||||
assert!(matches!(
|
||||
bad_author(&changes("1.0-1", Some("Ubuntu <ubuntu@ip-10-0-0-1>"), None)),
|
||||
Verdict::Refuse(_)
|
||||
));
|
||||
assert_eq!(
|
||||
bad_author(&changes("1.0-1", Some("A B <a@b.c>"), None)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// No Changed-By field: nothing to judge
|
||||
assert_eq!(bad_author(&changes("1.0-1", None, None)), Verdict::Proceed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_bug_questions_missing_references() {
|
||||
assert!(matches!(
|
||||
no_bug(&changes("1.0-1", Some("A <a@b.c>"), None)),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
// An empty field is as good as absent
|
||||
assert!(matches!(
|
||||
no_bug(&changes_with_bugs("1.0-1", None, None, Some(" "))),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
assert_eq!(
|
||||
no_bug(&changes_with_bugs("1.0-1", None, None, Some("123456"))),
|
||||
Verdict::Proceed
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placeholder_bug_flags_placeholder_prefixes() {
|
||||
assert!(matches!(
|
||||
placeholder_bug(&changes_with_bugs("1.0-1", None, None, Some("123456"))),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
assert!(matches!(
|
||||
placeholder_bug(&changes_with_bugs("1.0-1", None, None, Some("9999"))),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
// Both placeholders in one comma-separated field: both reported
|
||||
match placeholder_bug(&changes_with_bugs(
|
||||
"1.0-1",
|
||||
None,
|
||||
None,
|
||||
Some("1234, 99990, 4567"),
|
||||
)) {
|
||||
Verdict::Ask { reason, .. } => {
|
||||
assert!(reason.contains("1234, 99990"), "unexpected: {reason}");
|
||||
assert!(!reason.contains("4567"), "unexpected: {reason}");
|
||||
}
|
||||
other => panic!("unexpected verdict: {other:?}"),
|
||||
}
|
||||
assert_eq!(
|
||||
placeholder_bug(&changes_with_bugs("1.0-1", None, None, Some("456789"))),
|
||||
Verdict::Proceed
|
||||
);
|
||||
assert_eq!(
|
||||
placeholder_bug(&changes("1.0-1", None, None)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn release_mismatch_checks_backport_suffixes() {
|
||||
let target = ("focal".to_string(), "20.04".to_string());
|
||||
|
||||
// Matching suffix
|
||||
assert_eq!(
|
||||
release_mismatch(&changes("1.0-0ubuntu1~20.04", None, None), Some(&target)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// Suffix for another series
|
||||
assert!(matches!(
|
||||
release_mismatch(&changes("1.0-0ubuntu1~20.10", None, None), Some(&target)),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
// No ubuntu marker, no suffix: nothing to compare
|
||||
assert_eq!(
|
||||
release_mismatch(&changes("1.0-1", None, None), Some(&target)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// Numbers in the upstream part do not decide (the scan starts
|
||||
// after `ubuntu`)
|
||||
assert_eq!(
|
||||
release_mismatch(&changes("24.09.1-1ubuntu1", None, None), Some(&target)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// Unversioned target (not a versioned Ubuntu series): skipped
|
||||
assert_eq!(
|
||||
release_mismatch(&changes("1.0-0ubuntu1~20.10", None, None), None),
|
||||
Verdict::Proceed
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn release_numbers_scans_overlapping_patterns() {
|
||||
assert_eq!(release_numbers("1~20.04"), vec!["20.04"]);
|
||||
// `23.45.67` holds two overlapping matches
|
||||
assert_eq!(release_numbers("23.45.67"), vec!["23.45", "45.67"]);
|
||||
// Duplicates collapse
|
||||
assert_eq!(release_numbers("20.04-20.04"), vec!["20.04"]);
|
||||
assert!(release_numbers("1.2-1").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_maintainer_questions_non_ubuntu_maintainers() {
|
||||
// Ubuntu-marked version, Debian maintainer
|
||||
assert!(matches!(
|
||||
update_maintainer(&changes("1.0-1ubuntu1", None, Some("D M <d@debian.org>"))),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
// Point-update SRU version (`1ubuntu2.3`), the shape dpkg's own
|
||||
// `\dubuntu\d*$` misses
|
||||
assert!(matches!(
|
||||
update_maintainer(&changes(
|
||||
"1.0-1ubuntu2.22",
|
||||
None,
|
||||
Some("D M <d@debian.org>")
|
||||
)),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
// The address update-maintainer sets
|
||||
assert_eq!(
|
||||
update_maintainer(&changes(
|
||||
"1.0-1ubuntu1",
|
||||
None,
|
||||
Some("Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>")
|
||||
)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// An Ubuntu developer's address
|
||||
assert_eq!(
|
||||
update_maintainer(&changes("1.0-1ubuntu1", None, Some("U D <u@ubuntu.com>"))),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// Look-alike domain: not an ubuntu.com address
|
||||
assert!(matches!(
|
||||
update_maintainer(&changes(
|
||||
"1.0-1ubuntu1",
|
||||
None,
|
||||
Some("N U <n@notubuntu.com>")
|
||||
)),
|
||||
Verdict::Ask { .. }
|
||||
));
|
||||
// Plain revision upload: the check does not apply
|
||||
assert_eq!(
|
||||
update_maintainer(&changes("1.0-1", None, Some("D M <d@debian.org>"))),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// Upstream component merely containing `ubuntu`: not Ubuntu-marked
|
||||
assert_eq!(
|
||||
update_maintainer(&changes(
|
||||
"1.0+gitubuntu-main-1",
|
||||
None,
|
||||
Some("D M <d@debian.org>")
|
||||
)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// A `~ppa` tail keeps the marker out of the anchored position
|
||||
assert_eq!(
|
||||
update_maintainer(&changes(
|
||||
"1.0-1ubuntu2~ppa1",
|
||||
None,
|
||||
Some("D M <d@debian.org>")
|
||||
)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
// No Maintainer field: nothing to judge
|
||||
assert_eq!(
|
||||
update_maintainer(&changes("1.0-1ubuntu1", None, None)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn patches_in_native_refuses_quilt_series() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
// Native format + series: refused
|
||||
let native = dir.path().join("native");
|
||||
std::fs::create_dir_all(native.join("debian/patches")).unwrap();
|
||||
std::fs::create_dir_all(native.join("debian/source")).unwrap();
|
||||
std::fs::write(native.join("debian/source/format"), "3.0 (native)\n").unwrap();
|
||||
std::fs::write(native.join("debian/patches/series"), "").unwrap();
|
||||
assert!(matches!(
|
||||
patches_in_native(&changes("1.0-1", None, None), Some(&native)),
|
||||
Verdict::Refuse(_)
|
||||
));
|
||||
|
||||
// Quilt format + series: fine
|
||||
let quilt = dir.path().join("quilt");
|
||||
std::fs::create_dir_all(quilt.join("debian/patches")).unwrap();
|
||||
std::fs::create_dir_all(quilt.join("debian/source")).unwrap();
|
||||
std::fs::write(quilt.join("debian/source/format"), "3.0 (quilt)\n").unwrap();
|
||||
std::fs::write(quilt.join("debian/patches/series"), "").unwrap();
|
||||
assert_eq!(
|
||||
patches_in_native(&changes("1.0-1", None, None), Some(&quilt)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
|
||||
// Native format, no series file: fine
|
||||
let native_clean = dir.path().join("native-clean");
|
||||
std::fs::create_dir_all(native_clean.join("debian/source")).unwrap();
|
||||
std::fs::write(native_clean.join("debian/source/format"), "3.0 (native)\n").unwrap();
|
||||
assert_eq!(
|
||||
patches_in_native(&changes("1.0-1", None, None), Some(&native_clean)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
|
||||
// No format file: the version decides (no revision = native)
|
||||
let unversioned = dir.path().join("unversioned");
|
||||
std::fs::create_dir_all(unversioned.join("debian/patches")).unwrap();
|
||||
std::fs::write(unversioned.join("debian/patches/series"), "").unwrap();
|
||||
assert!(matches!(
|
||||
patches_in_native(&changes("1.0", None, None), Some(&unversioned)),
|
||||
Verdict::Refuse(_)
|
||||
));
|
||||
assert_eq!(
|
||||
patches_in_native(&changes("1.0-1", None, None), Some(&unversioned)),
|
||||
Verdict::Proceed
|
||||
);
|
||||
|
||||
// No tree next to the upload: skipped
|
||||
assert_eq!(
|
||||
patches_in_native(&changes("1.0", None, None), None),
|
||||
Verdict::Proceed
|
||||
);
|
||||
}
|
||||
|
||||
/// A prompter answering yes to every question, recording what it was
|
||||
/// asked.
|
||||
struct ConfirmYes;
|
||||
|
||||
impl Prompter for ConfirmYes {
|
||||
fn confirm(
|
||||
&self,
|
||||
question: &str,
|
||||
_default: bool,
|
||||
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
assert!(question.ends_with('?'), "unexpected question: {question}");
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn run_asks_then_proceeds_on_confirmation() {
|
||||
// No bugs, placeholder-free upload: the only Ask is no_bug
|
||||
let changes = changes("1.0-1", Some("A B <a@b.c>"), Some("A B <a@b.c>"));
|
||||
assert!(
|
||||
run(&changes, None, &ConfirmYes).await.is_ok(),
|
||||
"a yes answer lets the upload through"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn run_refuses_without_confirmation() {
|
||||
let changes = changes("1.0-1", Some("A B <a@b.c>"), Some("A B <a@b.c>"));
|
||||
let error = run(&changes, None, &crate::report::Quiet)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
assert!(
|
||||
error.contains("references no Launchpad bug"),
|
||||
"unexpected: {error}"
|
||||
);
|
||||
assert!(error.contains("--force"), "unexpected: {error}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn run_stops_machine_identities_before_asking() {
|
||||
// A bad author is refused outright, with no question in between
|
||||
let changes = changes("1.0-1", Some("root <root@localhost>"), None);
|
||||
let error = run(&changes, None, &ConfirmYes)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
assert!(error.contains("root@"), "unexpected: {error}");
|
||||
}
|
||||
}
|
||||
+22
-3
@@ -6,6 +6,7 @@
|
||||
//! transport dput's plain `ppa:` profiles use — through [`ftp`].
|
||||
|
||||
pub mod changes;
|
||||
pub mod checks;
|
||||
// The plain-FTP fallback transport: feature-gated (the `ftp` feature) so
|
||||
// the Debian build can drop its one unpackaged dependency; with the
|
||||
// feature off, the SFTP failure path reports the transport as
|
||||
@@ -36,8 +37,8 @@ pub struct PutOptions<'a> {
|
||||
/// current package (from `debian/changelog`) is discovered next to the
|
||||
/// source tree.
|
||||
pub changes: Option<PathBuf>,
|
||||
/// Upload even if this exact `.changes` file was already uploaded to the
|
||||
/// target.
|
||||
/// Upload even if this exact `.changes` file was already uploaded to
|
||||
/// the target, skipping the mistake pre-flight checks.
|
||||
pub force: bool,
|
||||
/// Source package directory (the one containing `debian/`).
|
||||
pub cwd: PathBuf,
|
||||
@@ -105,10 +106,25 @@ async fn put_impl(opts: &PutOptions<'_>) -> Result<(), Box<dyn std::error::Error
|
||||
});
|
||||
changes::validate(&changes)?;
|
||||
|
||||
// The tree the tree-level pre-flights validate (see
|
||||
// [`section_check_target`])
|
||||
let tree = section_check_target(opts.changes.as_deref(), &opts.cwd);
|
||||
|
||||
// Mistake guards before anything touches the network: common upload
|
||||
// mistakes the archive queue accepts silently (adapted from
|
||||
// cpaelzer's dput hooks). --force is the explicit way past them.
|
||||
if !opts.force {
|
||||
let tree_dir = match &tree {
|
||||
SectionCheckTarget::Dir(dir) => Some(dir.as_path()),
|
||||
SectionCheckTarget::Skip => None,
|
||||
};
|
||||
checks::run(&changes, tree_dir, opts.prompter).await?;
|
||||
}
|
||||
|
||||
// Pre-flight checks for everything the upload queue only rejects after
|
||||
// processing: a valid Section, a known target series, and the target
|
||||
// PPA actually existing (the SFTP queue itself is a blind write)
|
||||
match section_check_target(opts.changes.as_deref(), &opts.cwd) {
|
||||
match tree {
|
||||
SectionCheckTarget::Dir(dir) => check_control_section(&dir, "ubuntu")?,
|
||||
SectionCheckTarget::Skip => log::warn!(
|
||||
"cannot check the Section: '{}' has no debian/control next to \
|
||||
@@ -945,6 +961,9 @@ mod tests {
|
||||
source: "hello".to_string(),
|
||||
version: version.to_string(),
|
||||
distribution: "resolute".to_string(),
|
||||
changed_by: None,
|
||||
maintainer: None,
|
||||
launchpad_bugs_fixed: None,
|
||||
files: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user