From b59b672937fddbdaa884537626fbd1293c729755 Mon Sep 17 00:00:00 2001 From: exin Date: Sat, 9 Jul 2022 19:49:09 -0500 Subject: [PATCH 1/7] Remove Matcher::KeyValue match laziness Closes #316 --- os_info/src/matcher.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/os_info/src/matcher.rs b/os_info/src/matcher.rs index f8acba37..fcc31bc5 100644 --- a/os_info/src/matcher.rs +++ b/os_info/src/matcher.rs @@ -33,10 +33,8 @@ impl Matcher { fn find_by_key<'a>(string: &'a str, key: &str) -> Option<&'a str> { let key = [key, "="].concat(); for line in string.lines() { - if let Some(key_start) = line.find(&key) { - return Some( - line[key_start + key.len()..].trim_matches(|c: char| c == '"' || c.is_whitespace()), - ); + if line.starts_with(&key) { + return Some(line[key.len()..].trim_matches(|c: char| c == '"' || c.is_whitespace())); } } From 18e4e69783bbb0e6cd5e6d931691ad2a85dc48e2 Mon Sep 17 00:00:00 2001 From: exin Date: Sun, 10 Jul 2022 15:34:05 -0600 Subject: [PATCH 2/7] Fix linux file_release detection * Fix retrieve function fails to fail * Fix Oracle Linux false positive condition * Refactor ReleaseInfo Matcher to function pointers * Refactor DISTRIBUTIONS to static * Add os-release match closure * Add ReleaseInfo fmt::Debug implementation and tests * Remove get_type function Closes #315 --- os_info/src/linux/file_release.rs | 183 ++++++++++++++++++++---------- 1 file changed, 123 insertions(+), 60 deletions(-) diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index 8ca40ace..3a045b89 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -1,6 +1,6 @@ // spell-checker:ignore sles -use std::{fs::File, io::Read, path::Path}; +use std::{fmt, fs::File, io::Read, path::Path}; use log::{trace, warn}; @@ -31,100 +31,158 @@ fn retrieve(distributions: &[ReleaseInfo]) -> Option { continue; } - let os_type = Matcher::KeyValue { key: "NAME" } - .find(&file_content) - .and_then(|name| get_type(&name)) - .unwrap_or(release_info.os_type); + let os_type = (release_info.os_type)(&file_content); - let version = release_info - .version_matcher - .find(&file_content) - .map(Version::from_string) - .unwrap_or_else(|| Version::Unknown); + // If os_type is indeterminate, try the next release_info + if let None = os_type { + continue; + } + + let version = (release_info.version)(&file_content); return Some(Info { - os_type, - version, + os_type: os_type.unwrap(), + version: version.unwrap_or_else(|| Version::Unknown), bitness: Bitness::Unknown, ..Default::default() }); } + // Failed to determine os info None } -fn get_type(name: &str) -> Option { - let name = name.to_lowercase(); - - // RHEL sometimes has a suffix, like Server or Workstation - if name.starts_with("red hat enterprise linux") { - return Some(Type::RedHatEnterprise); - } - - match name.as_str() { - "alpine linux" => Some(Type::Alpine), - "amazon linux" => Some(Type::Amazon), - "amazon linux ami" => Some(Type::Amazon), - "arch linux" => Some(Type::Arch), - "centos linux" => Some(Type::CentOS), - "centos stream" => Some(Type::CentOS), - "fedora" => Some(Type::Fedora), - "fedora linux" => Some(Type::Fedora), - "linux mint" => Some(Type::Mint), - "mariner" => Some(Type::Mariner), - "nixos" => Some(Type::NixOS), - "sles" => Some(Type::SUSE), - "ubuntu" => Some(Type::Ubuntu), - _ => None, - } -} - -#[derive(Debug, Clone)] +#[derive(Clone)] struct ReleaseInfo<'a> { - os_type: Type, + // The release file the struct corresponds to path: &'a str, - version_matcher: Matcher, + // Outputs the os type given the release file + os_type: for<'b> fn(&'b str) -> Option, + // Outputs the os version given the release file + version: for<'b> fn(&'b str) -> Option, +} + +impl fmt::Debug for ReleaseInfo<'_> { + fn fmt<'a>(&'a self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ReleaseInfo") + .field("path", &self.path) + .field("os_type", &(self.os_type as fn(&'a str) -> Option)) + .field("version", &(self.version as fn(&'a str) -> Option)) + .finish() + } } /// List of all supported distributions and the information on how to parse their version from the /// release file. -const DISTRIBUTIONS: [ReleaseInfo; 6] = [ - // Due to shenanigans with Oracle Linux including an /etc/redhat-release file that states - // that the OS is Red Hat Enterprise Linux, this /etc/os-release file MUST be checked - // before this code checks /etc/redhat-release. If it does not get run first, - // it will unintentionally report that the operating system is Red Hat Enterprise Linux - // instead of Oracle Linux. +static DISTRIBUTIONS: [ReleaseInfo; 6] = [ ReleaseInfo { - os_type: Type::Mariner, path: "/etc/mariner-release", - version_matcher: Matcher::PrefixedVersion { - prefix: "CBL-Mariner ", + os_type: |_| Some(Type::Mariner), + version: |release| { + Matcher::PrefixedVersion { + prefix: "CBL-Mariner", + } + .find(&release) + .map(Version::from_string) }, }, ReleaseInfo { - os_type: Type::CentOS, path: "/etc/centos-release", - version_matcher: Matcher::PrefixedVersion { prefix: "release" }, + os_type: |_| Some(Type::CentOS), + version: |release| { + Matcher::PrefixedVersion { prefix: "release" } + .find(&release) + .map(Version::from_string) + }, }, ReleaseInfo { - os_type: Type::Fedora, path: "/etc/fedora-release", - version_matcher: Matcher::PrefixedVersion { prefix: "release" }, + os_type: |_| Some(Type::Fedora), + version: |release| { + Matcher::PrefixedVersion { prefix: "release" } + .find(&release) + .map(Version::from_string) + }, }, ReleaseInfo { - os_type: Type::Alpine, path: "/etc/alpine-release", - version_matcher: Matcher::AllTrimmed, + os_type: |_| Some(Type::Alpine), + version: |release| Matcher::AllTrimmed.find(&release).map(Version::from_string), }, + // TODO: This should be placed first, as most modern distributions + // will have this file. ReleaseInfo { - os_type: Type::OracleLinux, path: "/etc/os-release", - version_matcher: Matcher::KeyValue { key: "VERSION_ID" }, + os_type: |release| { + Matcher::KeyValue { key: "ID" } + .find(&release) + .map(|id| match id.as_str() { + // os-release information collected from + // https://github.com/chef/os_release + + //"almalinux" => Alma + "alpine" => Some(Type::Alpine), + "amzn" => Some(Type::Amazon), + //"antergos" => Antergos + //"aosc" => AOSC + "arch" => Some(Type::Arch), + //"artix" => Artix + "centos" => Some(Type::CentOS), + //"clear-linux-os" => ClearLinuxOS + //"clearos" => ClearOS + //"coreos" + //"cumulus-linux" => Cumulus + //"debian" => Debian + //"devuan" => Devuan + //"elementary" => Elementary + "fedora" => Some(Type::Fedora), + //"gentoo" => Gentoo + //"ios_xr" => ios_xr + //"kali" => Kali + //"mageia" => Mageia + //"manjaro" => Manjaro + "linuxmint" => Some(Type::Mint), + "mariner" => Some(Type::Mariner), + //"nexus" => Nexus + "nixos" => Some(Type::NixOS), + "ol" => Some(Type::OracleLinux), + "opensuse" => Some(Type::openSUSE), + "opensuse-leap" => Some(Type::openSUSE), + //"rancheros" => RancherOS + //"raspbian" => Raspbian + // note XBian also uses "raspbian" + "rhel" => Some(Type::RedHatEnterprise), + //"rocky" => Rocky + //"sabayon" => Sabayon + //"scientific" => Scientific + //"slackware" => Slackware + "sled" => Some(Type::SUSE), // SUSE desktop + "sles" => Some(Type::SUSE), + "sles_sap" => Some(Type::SUSE), // SUSE SAP + "ubuntu" => Some(Type::Ubuntu), + //"virtuozzo" => Virtuozzo + //"void" => Void + //"XCP-ng" => xcp-ng + //"xenenterprise" => xcp-ng + //"xenserver" => xcp-ng + _ => None, + }) + .flatten() + }, + version: |release| { + Matcher::KeyValue { key: "VERSION_ID" } + .find(&release) + .map(Version::from_string) + }, }, ReleaseInfo { - os_type: Type::RedHatEnterprise, path: "/etc/redhat-release", - version_matcher: Matcher::PrefixedVersion { prefix: "release" }, + os_type: |_| Some(Type::RedHatEnterprise), + version: |release| { + Matcher::PrefixedVersion { prefix: "release" } + .find(&release) + .map(Version::from_string) + }, }, ]; @@ -375,4 +433,9 @@ mod tests { assert_eq!(info.edition, None); assert_eq!(info.codename, None); } + + #[test] + fn release_info_debug() { + dbg!("{:?}", &DISTRIBUTIONS[0]); + } } From 7d86cae863c4b18087bd34dc7045d8a62bff6155 Mon Sep 17 00:00:00 2001 From: exin Date: Wed, 13 Jul 2022 20:31:52 -0600 Subject: [PATCH 3/7] Add ReleaseInfo documentation --- os_info/src/linux/file_release.rs | 55 ++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index 3a045b89..d34051ab 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -12,22 +12,24 @@ pub fn get() -> Option { fn retrieve(distributions: &[ReleaseInfo]) -> Option { for release_info in distributions { - if !Path::new(release_info.path).exists() { + let path = Path::new(release_info.path); + + if !path.exists() { trace!("Path '{}' doesn't exist", release_info.path); continue; } - let mut file = match File::open(&release_info.path) { + let mut file = match File::open(&path) { Ok(val) => val, Err(e) => { - warn!("Unable to open {:?} file: {:?}", release_info.path, e); + warn!("Unable to open {:?} file: {:?}", &path, e); continue; } }; let mut file_content = String::new(); if let Err(e) = file.read_to_string(&mut file_content) { - warn!("Unable to read {:?} file: {:?}", release_info.path, e); + warn!("Unable to read {:?} file: {:?}", &path, e); continue; } @@ -52,13 +54,50 @@ fn retrieve(distributions: &[ReleaseInfo]) -> Option { None } +/// Struct containing information on how to parse distribution info from a +/// release file. +/// +/// # Example +/// ```rust,ignore +/// ReleaseInfo { +/// path: "/etc/fedora-release", +/// os_type: |_| Some(Type::Fedora), +/// version: |release| { +/// Matcher::PrefixedVersion { prefix: "release" } +/// .find(&release) +/// .map(Version::from_string) +/// }, +/// }, +/// ``` #[derive(Clone)] struct ReleaseInfo<'a> { - // The release file the struct corresponds to + /// The release file the struct corresponds to. + /// + /// # Example + /// ```rust,ignore + /// path: "/etc/os-release" + /// ``` path: &'a str, - // Outputs the os type given the release file + + /// A closure that determines the os type from the release file contents. + /// + /// # Example + /// ```rust,ignore + /// //path: "/etc/mariner-release", + /// os_type: |_| Some(Type::Mariner), + /// ``` os_type: for<'b> fn(&'b str) -> Option, - // Outputs the os version given the release file + + /// A closure that determines the os version from the release file contents. + /// + /// # Example + /// ```rust,ignore + /// version: |release| { + /// Matcher::KeyValue { key: "VERSION_ID" } + /// .find(&release) + /// .map(Version::from_string) + /// }, + /// ``` version: for<'b> fn(&'b str) -> Option, } @@ -164,7 +203,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ //"void" => Void //"XCP-ng" => xcp-ng //"xenenterprise" => xcp-ng - //"xenserver" => xcp-ng + //"xenserver" => xcp-ng _ => None, }) .flatten() From b9cf38daed3beb4a686d7b7049161cccd3e5f549 Mon Sep 17 00:00:00 2001 From: exin Date: Sat, 16 Jul 2022 21:37:08 -0600 Subject: [PATCH 4/7] Fix file_release clippy warnings --- os_info/src/linux/file_release.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index d34051ab..a724fc91 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -36,7 +36,7 @@ fn retrieve(distributions: &[ReleaseInfo]) -> Option { let os_type = (release_info.os_type)(&file_content); // If os_type is indeterminate, try the next release_info - if let None = os_type { + if os_type.is_none() { continue; } @@ -44,7 +44,7 @@ fn retrieve(distributions: &[ReleaseInfo]) -> Option { return Some(Info { os_type: os_type.unwrap(), - version: version.unwrap_or_else(|| Version::Unknown), + version: version.unwrap_or(Version::Unknown), bitness: Bitness::Unknown, ..Default::default() }); @@ -121,7 +121,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ Matcher::PrefixedVersion { prefix: "CBL-Mariner", } - .find(&release) + .find(release) .map(Version::from_string) }, }, @@ -130,7 +130,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ os_type: |_| Some(Type::CentOS), version: |release| { Matcher::PrefixedVersion { prefix: "release" } - .find(&release) + .find(release) .map(Version::from_string) }, }, @@ -139,14 +139,14 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ os_type: |_| Some(Type::Fedora), version: |release| { Matcher::PrefixedVersion { prefix: "release" } - .find(&release) + .find(release) .map(Version::from_string) }, }, ReleaseInfo { path: "/etc/alpine-release", os_type: |_| Some(Type::Alpine), - version: |release| Matcher::AllTrimmed.find(&release).map(Version::from_string), + version: |release| Matcher::AllTrimmed.find(release).map(Version::from_string), }, // TODO: This should be placed first, as most modern distributions // will have this file. @@ -154,8 +154,8 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ path: "/etc/os-release", os_type: |release| { Matcher::KeyValue { key: "ID" } - .find(&release) - .map(|id| match id.as_str() { + .find(release) + .and_then(|id| match id.as_str() { // os-release information collected from // https://github.com/chef/os_release @@ -206,11 +206,10 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ //"xenserver" => xcp-ng _ => None, }) - .flatten() }, version: |release| { Matcher::KeyValue { key: "VERSION_ID" } - .find(&release) + .find(release) .map(Version::from_string) }, }, @@ -219,7 +218,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ os_type: |_| Some(Type::RedHatEnterprise), version: |release| { Matcher::PrefixedVersion { prefix: "release" } - .find(&release) + .find(release) .map(Version::from_string) }, }, From b780ea4c0dab7f67cb819f574f9714989c98fd76 Mon Sep 17 00:00:00 2001 From: exin Date: Sat, 16 Jul 2022 21:55:21 -0600 Subject: [PATCH 5/7] Fix cspell-dictionary --- cspell-dictionary.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index bba5692e..d1201a97 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -1,12 +1,20 @@ aarch64 +almalinux +antergos +aosc +artix bitness centos clippy +clearos concat +coreos +devuan earmv emscripten endeavouros freebsd +garuda hardenedbsd hbsd illumos @@ -14,12 +22,14 @@ isainfo libntdll linuxmint macos +mageia manjaro midnightbsd msvc netbsd nixos openbsd +opensuse println raspberry raspbian @@ -30,5 +40,9 @@ serde structopt toml ulyana +virtuozzo winapi +xbian +xenenterprise xenial +xenserver From 517e13e043d3a6c6e464e8c334a1d946d8445c8a Mon Sep 17 00:00:00 2001 From: exin Date: Sat, 16 Jul 2022 22:26:09 -0600 Subject: [PATCH 6/7] Refactor DISTRIBUTIONS order --- os_info/src/linux/file_release.rs | 110 +++++++++++++++--------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index a724fc91..4374a438 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -114,42 +114,7 @@ impl fmt::Debug for ReleaseInfo<'_> { /// List of all supported distributions and the information on how to parse their version from the /// release file. static DISTRIBUTIONS: [ReleaseInfo; 6] = [ - ReleaseInfo { - path: "/etc/mariner-release", - os_type: |_| Some(Type::Mariner), - version: |release| { - Matcher::PrefixedVersion { - prefix: "CBL-Mariner", - } - .find(release) - .map(Version::from_string) - }, - }, - ReleaseInfo { - path: "/etc/centos-release", - os_type: |_| Some(Type::CentOS), - version: |release| { - Matcher::PrefixedVersion { prefix: "release" } - .find(release) - .map(Version::from_string) - }, - }, - ReleaseInfo { - path: "/etc/fedora-release", - os_type: |_| Some(Type::Fedora), - version: |release| { - Matcher::PrefixedVersion { prefix: "release" } - .find(release) - .map(Version::from_string) - }, - }, - ReleaseInfo { - path: "/etc/alpine-release", - os_type: |_| Some(Type::Alpine), - version: |release| Matcher::AllTrimmed.find(release).map(Version::from_string), - }, - // TODO: This should be placed first, as most modern distributions - // will have this file. + // Keep this first; most modern distributions have this file. ReleaseInfo { path: "/etc/os-release", os_type: |release| { @@ -213,6 +178,41 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ .map(Version::from_string) }, }, + // Older distributions must have their specific release file parsed. + ReleaseInfo { + path: "/etc/mariner-release", + os_type: |_| Some(Type::Mariner), + version: |release| { + Matcher::PrefixedVersion { + prefix: "CBL-Mariner", + } + .find(release) + .map(Version::from_string) + }, + }, + ReleaseInfo { + path: "/etc/centos-release", + os_type: |_| Some(Type::CentOS), + version: |release| { + Matcher::PrefixedVersion { prefix: "release" } + .find(release) + .map(Version::from_string) + }, + }, + ReleaseInfo { + path: "/etc/fedora-release", + os_type: |_| Some(Type::Fedora), + version: |release| { + Matcher::PrefixedVersion { prefix: "release" } + .find(release) + .map(Version::from_string) + }, + }, + ReleaseInfo { + path: "/etc/alpine-release", + os_type: |_| Some(Type::Alpine), + version: |release| Matcher::AllTrimmed.find(release).map(Version::from_string), + }, ReleaseInfo { path: "/etc/redhat-release", os_type: |_| Some(Type::RedHatEnterprise), @@ -231,7 +231,7 @@ mod tests { #[test] fn oracle_linux() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release"; let info = retrieve(&distributions).unwrap(); @@ -243,7 +243,7 @@ mod tests { #[test] fn os_release_alpine_3_12() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-alpine-3-12"; let info = retrieve(&distributions).unwrap(); @@ -255,7 +255,7 @@ mod tests { #[test] fn os_release_amazon_1() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-amazon-1"; let info = retrieve(&distributions).unwrap(); @@ -267,7 +267,7 @@ mod tests { #[test] fn os_release_amazon_2() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-amazon-2"; let info = retrieve(&distributions).unwrap(); @@ -279,7 +279,7 @@ mod tests { #[test] fn os_release_centos() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-centos"; let info = retrieve(&distributions).unwrap(); @@ -291,7 +291,7 @@ mod tests { #[test] fn os_release_centos_stream() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-centos-stream"; let info = retrieve(&distributions).unwrap(); @@ -303,7 +303,7 @@ mod tests { #[test] fn os_release_fedora() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-fedora-32"; let info = retrieve(&distributions).unwrap(); @@ -315,7 +315,7 @@ mod tests { #[test] fn os_release_fedora_35() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-fedora-35"; let info = retrieve(&distributions).unwrap(); @@ -327,7 +327,7 @@ mod tests { #[test] fn os_release_nixos() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-nixos"; let info = retrieve(&distributions).unwrap(); @@ -342,7 +342,7 @@ mod tests { #[test] fn os_release_rhel() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-rhel"; let info = retrieve(&distributions).unwrap(); @@ -354,7 +354,7 @@ mod tests { #[test] fn os_release_rhel_7() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-rhel-7"; let info = retrieve(&distributions).unwrap(); @@ -366,7 +366,7 @@ mod tests { #[test] fn os_release_suse_12() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-suse-12"; let info = retrieve(&distributions).unwrap(); @@ -378,7 +378,7 @@ mod tests { #[test] fn os_release_suse_15() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-suse-15"; let info = retrieve(&distributions).unwrap(); @@ -390,7 +390,7 @@ mod tests { #[test] fn os_release_ubuntu() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-ubuntu"; let info = retrieve(&distributions).unwrap(); @@ -402,7 +402,7 @@ mod tests { #[test] fn os_release_mint() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; + let mut distributions = [DISTRIBUTIONS[0].clone()]; distributions[0].path = "src/linux/tests/os-release-mint"; let info = retrieve(&distributions).unwrap(); @@ -414,7 +414,7 @@ mod tests { #[test] fn centos() { - let mut distributions = [DISTRIBUTIONS[1].clone()]; + let mut distributions = [DISTRIBUTIONS[2].clone()]; distributions[0].path = "src/linux/tests/centos-release"; let info = retrieve(&distributions).unwrap(); @@ -426,7 +426,7 @@ mod tests { #[test] fn fedora() { - let mut distributions = [DISTRIBUTIONS[2].clone()]; + let mut distributions = [DISTRIBUTIONS[3].clone()]; distributions[0].path = "src/linux/tests/fedora-release"; let info = retrieve(&distributions).unwrap(); @@ -450,7 +450,7 @@ mod tests { #[test] fn alpine() { - let mut distributions = [DISTRIBUTIONS[3].clone()]; + let mut distributions = [DISTRIBUTIONS[4].clone()]; distributions[0].path = "src/linux/tests/alpine-release"; let info = retrieve(&distributions).unwrap(); @@ -462,7 +462,7 @@ mod tests { #[test] fn mariner() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; + let mut distributions = [DISTRIBUTIONS[1].clone()]; distributions[0].path = "src/linux/tests/mariner-release"; let info = retrieve(&distributions).unwrap(); From e98db60d16c26776b5a86ea360ac3f9219c41e3d Mon Sep 17 00:00:00 2001 From: exin Date: Mon, 18 Jul 2022 15:01:49 -0600 Subject: [PATCH 7/7] Fix file_release inadequate testing * Refactor tests to have more operating system context * Add tests for more edge cases * Order tests alphabetically --- os_info/src/linux/file_release.rs | 286 ++++++++++-------- .../tests/{ => Alpine/etc}/alpine-release | 0 .../etc/os-release} | 0 .../etc/os-release} | 0 .../etc/os-release} | 0 .../tests/{ => CentOS/etc}/centos-release | 0 .../etc/os-release} | 0 .../etc/os-release} | 0 .../tests/CentOS_Unknown/etc/centos-release | 1 + .../tests/{ => Fedora/etc}/fedora-release | 0 .../etc/os-release} | 0 .../etc/os-release} | 0 .../tests/Fedora_Unknown/etc/fedora-release | 1 + .../tests/{ => Mariner/etc}/mariner-release | 0 .../tests/Mariner_Unknown/etc/mariner-release | 1 + .../{os-release-mint => Mint/etc/os-release} | 0 .../etc/os-release} | 0 .../tests/{ => OracleLinux/etc}/os-release | 0 .../tests/OracleLinux/etc/redhat-release | 1 + .../{ => RedHatEnterprise/etc}/redhat-release | 0 .../etc/os-release} | 0 .../etc/os-release} | 0 .../etc/redhat-release | 0 .../etc/os-release} | 0 .../etc/os-release} | 0 .../etc/os-release} | 0 .../none_invalid_os_release/etc/os-release | 2 + 27 files changed, 173 insertions(+), 119 deletions(-) rename os_info/src/linux/tests/{ => Alpine/etc}/alpine-release (100%) rename os_info/src/linux/tests/{os-release-alpine-3-12 => Alpine_3_12/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-amazon-1 => Amazon_1/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-amazon-2 => Amazon_2/etc/os-release} (100%) rename os_info/src/linux/tests/{ => CentOS/etc}/centos-release (100%) rename os_info/src/linux/tests/{os-release-centos => CentOS_7/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-centos-stream => CentOS_Stream/etc/os-release} (100%) create mode 100644 os_info/src/linux/tests/CentOS_Unknown/etc/centos-release rename os_info/src/linux/tests/{ => Fedora/etc}/fedora-release (100%) rename os_info/src/linux/tests/{os-release-fedora-32 => Fedora_32/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-fedora-35 => Fedora_35/etc/os-release} (100%) create mode 100644 os_info/src/linux/tests/Fedora_Unknown/etc/fedora-release rename os_info/src/linux/tests/{ => Mariner/etc}/mariner-release (100%) create mode 100644 os_info/src/linux/tests/Mariner_Unknown/etc/mariner-release rename os_info/src/linux/tests/{os-release-mint => Mint/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-nixos => NixOS/etc/os-release} (100%) rename os_info/src/linux/tests/{ => OracleLinux/etc}/os-release (100%) create mode 100644 os_info/src/linux/tests/OracleLinux/etc/redhat-release rename os_info/src/linux/tests/{ => RedHatEnterprise/etc}/redhat-release (100%) rename os_info/src/linux/tests/{os-release-rhel-7 => RedHatEnterprise_7/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-rhel => RedHatEnterprise_8/etc/os-release} (100%) create mode 100644 os_info/src/linux/tests/RedHatEnterprise_Unknown/etc/redhat-release rename os_info/src/linux/tests/{os-release-suse-12 => SUSE_12/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-suse-15 => SUSE_15/etc/os-release} (100%) rename os_info/src/linux/tests/{os-release-ubuntu => Ubuntu/etc/os-release} (100%) create mode 100644 os_info/src/linux/tests/none_invalid_os_release/etc/os-release diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index 4374a438..0cebba1d 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -7,12 +7,12 @@ use log::{trace, warn}; use crate::{matcher::Matcher, Bitness, Info, Type, Version}; pub fn get() -> Option { - retrieve(&DISTRIBUTIONS) + retrieve(&DISTRIBUTIONS, "/") } -fn retrieve(distributions: &[ReleaseInfo]) -> Option { +fn retrieve(distributions: &[ReleaseInfo], root: &str) -> Option { for release_info in distributions { - let path = Path::new(release_info.path); + let path = Path::new(root).join(release_info.path); if !path.exists() { trace!("Path '{}' doesn't exist", release_info.path); @@ -71,11 +71,11 @@ fn retrieve(distributions: &[ReleaseInfo]) -> Option { /// ``` #[derive(Clone)] struct ReleaseInfo<'a> { - /// The release file the struct corresponds to. + /// Relative path to the release file this struct corresponds to from root. /// /// # Example /// ```rust,ignore - /// path: "/etc/os-release" + /// path: "etc/os-release" /// ``` path: &'a str, @@ -116,7 +116,7 @@ impl fmt::Debug for ReleaseInfo<'_> { static DISTRIBUTIONS: [ReleaseInfo; 6] = [ // Keep this first; most modern distributions have this file. ReleaseInfo { - path: "/etc/os-release", + path: "etc/os-release", os_type: |release| { Matcher::KeyValue { key: "ID" } .find(release) @@ -180,7 +180,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ }, // Older distributions must have their specific release file parsed. ReleaseInfo { - path: "/etc/mariner-release", + path: "etc/mariner-release", os_type: |_| Some(Type::Mariner), version: |release| { Matcher::PrefixedVersion { @@ -191,7 +191,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ }, }, ReleaseInfo { - path: "/etc/centos-release", + path: "etc/centos-release", os_type: |_| Some(Type::CentOS), version: |release| { Matcher::PrefixedVersion { prefix: "release" } @@ -200,7 +200,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ }, }, ReleaseInfo { - path: "/etc/fedora-release", + path: "etc/fedora-release", os_type: |_| Some(Type::Fedora), version: |release| { Matcher::PrefixedVersion { prefix: "release" } @@ -209,12 +209,12 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ }, }, ReleaseInfo { - path: "/etc/alpine-release", + path: "etc/alpine-release", os_type: |_| Some(Type::Alpine), version: |release| Matcher::AllTrimmed.find(release).map(Version::from_string), }, ReleaseInfo { - path: "/etc/redhat-release", + path: "etc/redhat-release", os_type: |_| Some(Type::RedHatEnterprise), version: |release| { Matcher::PrefixedVersion { prefix: "release" } @@ -230,35 +230,32 @@ mod tests { use pretty_assertions::assert_eq; #[test] - fn oracle_linux() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release"; + fn alpine_3_12_os_release() { + let root = "src/linux/tests/Alpine_3_12"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::OracleLinux); - assert_eq!(info.version, Version::Semantic(8, 1, 0)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Alpine); + assert_eq!(info.version, Version::Semantic(3, 12, 0)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_alpine_3_12() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-alpine-3-12"; + fn alpine_release() { + let root = "src/linux/tests/Alpine"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::Alpine); - assert_eq!(info.version, Version::Semantic(3, 12, 0)); + assert_eq!(info.version, Version::Custom("A.B.C".to_owned())); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_amazon_1() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-amazon-1"; + fn amazon_1_os_release() { + let root = "src/linux/tests/Amazon_1"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::Amazon); assert_eq!(info.version, Version::Semantic(2018, 3, 0)); assert_eq!(info.edition, None); @@ -266,11 +263,10 @@ mod tests { } #[test] - fn os_release_amazon_2() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-amazon-2"; + fn amazon_2_os_release() { + let root = "src/linux/tests/Amazon_2"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::Amazon); assert_eq!(info.version, Version::Semantic(2, 0, 0)); assert_eq!(info.edition, None); @@ -278,11 +274,10 @@ mod tests { } #[test] - fn os_release_centos() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-centos"; + fn centos_7_os_release() { + let root = "src/linux/tests/CentOS_7"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::CentOS); assert_eq!(info.version, Version::Semantic(7, 0, 0)); assert_eq!(info.edition, None); @@ -290,11 +285,10 @@ mod tests { } #[test] - fn os_release_centos_stream() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-centos-stream"; + fn centos_stream_os_release() { + let root = "src/linux/tests/CentOS_Stream"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::CentOS); assert_eq!(info.version, Version::Semantic(8, 0, 0)); assert_eq!(info.edition, None); @@ -302,11 +296,32 @@ mod tests { } #[test] - fn os_release_fedora() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-fedora-32"; + fn centos_release() { + let root = "src/linux/tests/CentOS"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::CentOS); + assert_eq!(info.version, Version::Custom("XX".to_owned())); + assert_eq!(info.edition, None); + assert_eq!(info.codename, None); + } + + #[test] + fn centos_release_unknown() { + let root = "src/linux/tests/CentOS_Unknown"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::CentOS); + assert_eq!(info.version, Version::Unknown); + assert_eq!(info.edition, None); + assert_eq!(info.codename, None); + } + + #[test] + fn fedora_32_os_release() { + let root = "src/linux/tests/Fedora_32"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::Fedora); assert_eq!(info.version, Version::Semantic(32, 0, 0)); assert_eq!(info.edition, None); @@ -314,11 +329,10 @@ mod tests { } #[test] - fn os_release_fedora_35() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-fedora-35"; + fn fedora_35_os_release() { + let root = "src/linux/tests/Fedora_35"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::Fedora); assert_eq!(info.version, Version::Semantic(35, 0, 0)); assert_eq!(info.edition, None); @@ -326,122 +340,136 @@ mod tests { } #[test] - fn os_release_nixos() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-nixos"; + fn fedora_release() { + let root = "src/linux/tests/Fedora"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::NixOS); - assert_eq!( - info.version, - Version::Custom("21.05pre275822.916ee862e87".to_string()) - ); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Fedora); + assert_eq!(info.version, Version::Semantic(26, 0, 0)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_rhel() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-rhel"; + fn fedora_release_unknown() { + let root = "src/linux/tests/Fedora_Unknown"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::RedHatEnterprise); - assert_eq!(info.version, Version::Semantic(8, 2, 0)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Fedora); + assert_eq!(info.version, Version::Unknown); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_rhel_7() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-rhel-7"; + fn mariner_release() { + let root = "src/linux/tests/Mariner"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::RedHatEnterprise); - assert_eq!(info.version, Version::Semantic(7, 9, 0)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Mariner); + assert_eq!(info.version, Version::Semantic(2, 0, 20220210)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_suse_12() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-suse-12"; + fn mariner_release_unknown() { + let root = "src/linux/tests/Mariner_Unknown"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::SUSE); - assert_eq!(info.version, Version::Semantic(12, 5, 0)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Mariner); + assert_eq!(info.version, Version::Unknown); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_suse_15() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-suse-15"; + fn mint_os_release() { + let root = "src/linux/tests/Mint"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::SUSE); - assert_eq!(info.version, Version::Semantic(15, 2, 0)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Mint); + assert_eq!(info.version, Version::Semantic(20, 0, 0)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_ubuntu() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-ubuntu"; + fn nixos_os_release() { + let root = "src/linux/tests/NixOS"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::Ubuntu); - assert_eq!(info.version, Version::Semantic(18, 10, 0)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::NixOS); + assert_eq!( + info.version, + Version::Custom("21.05pre275822.916ee862e87".to_string()) + ); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn os_release_mint() { - let mut distributions = [DISTRIBUTIONS[0].clone()]; - distributions[0].path = "src/linux/tests/os-release-mint"; + fn none_invalid_os_release() { + let root = "src/linux/tests/none_invalid_os_release"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::Mint); - assert_eq!(info.version, Version::Semantic(20, 0, 0)); + let info = retrieve(&DISTRIBUTIONS, root); + assert_eq!(info, None); + } + + #[test] + fn none_no_release() { + let root = "src/linux/tests/none_no_release"; + + let info = retrieve(&DISTRIBUTIONS, root); + assert_eq!(info, None); + } + + #[test] + fn none_no_path() { + let root = "src/linux/tests/none_no_path"; + + let info = retrieve(&DISTRIBUTIONS, root); + assert_eq!(info, None); + } + + #[test] + fn oracle_linux_os_release() { + let root = "src/linux/tests/OracleLinux"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::OracleLinux); + assert_eq!(info.version, Version::Semantic(8, 1, 0)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn centos() { - let mut distributions = [DISTRIBUTIONS[2].clone()]; - distributions[0].path = "src/linux/tests/centos-release"; + fn rhel_8_os_release() { + let root = "src/linux/tests/RedHatEnterprise_8"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::CentOS); - assert_eq!(info.version, Version::Custom("XX".to_owned())); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::RedHatEnterprise); + assert_eq!(info.version, Version::Semantic(8, 2, 0)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn fedora() { - let mut distributions = [DISTRIBUTIONS[3].clone()]; - distributions[0].path = "src/linux/tests/fedora-release"; + fn rhel_7_os_release() { + let root = "src/linux/tests/RedHatEnterprise_7"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::Fedora); - assert_eq!(info.version, Version::Semantic(26, 0, 0)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::RedHatEnterprise); + assert_eq!(info.version, Version::Semantic(7, 9, 0)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn redhat() { - let mut distributions = [DISTRIBUTIONS[5].clone()]; - distributions[0].path = "src/linux/tests/redhat-release"; + fn redhat_release() { + let root = "src/linux/tests/RedHatEnterprise"; - let info = retrieve(&distributions).unwrap(); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); assert_eq!(info.os_type(), Type::RedHatEnterprise); assert_eq!(info.version, Version::Custom("XX".to_owned())); assert_eq!(info.edition, None); @@ -449,25 +477,45 @@ mod tests { } #[test] - fn alpine() { - let mut distributions = [DISTRIBUTIONS[4].clone()]; - distributions[0].path = "src/linux/tests/alpine-release"; + fn redhat_release_unknown() { + let root = "src/linux/tests/RedHatEnterprise_Unknown"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::Alpine); - assert_eq!(info.version, Version::Custom("A.B.C".to_owned())); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::RedHatEnterprise); + assert_eq!(info.version, Version::Unknown); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } #[test] - fn mariner() { - let mut distributions = [DISTRIBUTIONS[1].clone()]; - distributions[0].path = "src/linux/tests/mariner-release"; + fn suse_12_os_release() { + let root = "src/linux/tests/SUSE_12"; - let info = retrieve(&distributions).unwrap(); - assert_eq!(info.os_type(), Type::Mariner); - assert_eq!(info.version, Version::Semantic(2, 0, 20220210)); + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::SUSE); + assert_eq!(info.version, Version::Semantic(12, 5, 0)); + assert_eq!(info.edition, None); + assert_eq!(info.codename, None); + } + + #[test] + fn suse_15_os_release() { + let root = "src/linux/tests/SUSE_15"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::SUSE); + assert_eq!(info.version, Version::Semantic(15, 2, 0)); + assert_eq!(info.edition, None); + assert_eq!(info.codename, None); + } + + #[test] + fn ubuntu_os_release() { + let root = "src/linux/tests/Ubuntu"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Ubuntu); + assert_eq!(info.version, Version::Semantic(18, 10, 0)); assert_eq!(info.edition, None); assert_eq!(info.codename, None); } diff --git a/os_info/src/linux/tests/alpine-release b/os_info/src/linux/tests/Alpine/etc/alpine-release similarity index 100% rename from os_info/src/linux/tests/alpine-release rename to os_info/src/linux/tests/Alpine/etc/alpine-release diff --git a/os_info/src/linux/tests/os-release-alpine-3-12 b/os_info/src/linux/tests/Alpine_3_12/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-alpine-3-12 rename to os_info/src/linux/tests/Alpine_3_12/etc/os-release diff --git a/os_info/src/linux/tests/os-release-amazon-1 b/os_info/src/linux/tests/Amazon_1/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-amazon-1 rename to os_info/src/linux/tests/Amazon_1/etc/os-release diff --git a/os_info/src/linux/tests/os-release-amazon-2 b/os_info/src/linux/tests/Amazon_2/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-amazon-2 rename to os_info/src/linux/tests/Amazon_2/etc/os-release diff --git a/os_info/src/linux/tests/centos-release b/os_info/src/linux/tests/CentOS/etc/centos-release similarity index 100% rename from os_info/src/linux/tests/centos-release rename to os_info/src/linux/tests/CentOS/etc/centos-release diff --git a/os_info/src/linux/tests/os-release-centos b/os_info/src/linux/tests/CentOS_7/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-centos rename to os_info/src/linux/tests/CentOS_7/etc/os-release diff --git a/os_info/src/linux/tests/os-release-centos-stream b/os_info/src/linux/tests/CentOS_Stream/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-centos-stream rename to os_info/src/linux/tests/CentOS_Stream/etc/os-release diff --git a/os_info/src/linux/tests/CentOS_Unknown/etc/centos-release b/os_info/src/linux/tests/CentOS_Unknown/etc/centos-release new file mode 100644 index 00000000..e6b865bc --- /dev/null +++ b/os_info/src/linux/tests/CentOS_Unknown/etc/centos-release @@ -0,0 +1 @@ +Centos Linux diff --git a/os_info/src/linux/tests/fedora-release b/os_info/src/linux/tests/Fedora/etc/fedora-release similarity index 100% rename from os_info/src/linux/tests/fedora-release rename to os_info/src/linux/tests/Fedora/etc/fedora-release diff --git a/os_info/src/linux/tests/os-release-fedora-32 b/os_info/src/linux/tests/Fedora_32/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-fedora-32 rename to os_info/src/linux/tests/Fedora_32/etc/os-release diff --git a/os_info/src/linux/tests/os-release-fedora-35 b/os_info/src/linux/tests/Fedora_35/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-fedora-35 rename to os_info/src/linux/tests/Fedora_35/etc/os-release diff --git a/os_info/src/linux/tests/Fedora_Unknown/etc/fedora-release b/os_info/src/linux/tests/Fedora_Unknown/etc/fedora-release new file mode 100644 index 00000000..adc01153 --- /dev/null +++ b/os_info/src/linux/tests/Fedora_Unknown/etc/fedora-release @@ -0,0 +1 @@ +Fedora (Foo Bar) diff --git a/os_info/src/linux/tests/mariner-release b/os_info/src/linux/tests/Mariner/etc/mariner-release similarity index 100% rename from os_info/src/linux/tests/mariner-release rename to os_info/src/linux/tests/Mariner/etc/mariner-release diff --git a/os_info/src/linux/tests/Mariner_Unknown/etc/mariner-release b/os_info/src/linux/tests/Mariner_Unknown/etc/mariner-release new file mode 100644 index 00000000..d64fd530 --- /dev/null +++ b/os_info/src/linux/tests/Mariner_Unknown/etc/mariner-release @@ -0,0 +1 @@ +CBL-Mariner \ No newline at end of file diff --git a/os_info/src/linux/tests/os-release-mint b/os_info/src/linux/tests/Mint/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-mint rename to os_info/src/linux/tests/Mint/etc/os-release diff --git a/os_info/src/linux/tests/os-release-nixos b/os_info/src/linux/tests/NixOS/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-nixos rename to os_info/src/linux/tests/NixOS/etc/os-release diff --git a/os_info/src/linux/tests/os-release b/os_info/src/linux/tests/OracleLinux/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release rename to os_info/src/linux/tests/OracleLinux/etc/os-release diff --git a/os_info/src/linux/tests/OracleLinux/etc/redhat-release b/os_info/src/linux/tests/OracleLinux/etc/redhat-release new file mode 100644 index 00000000..994041ed --- /dev/null +++ b/os_info/src/linux/tests/OracleLinux/etc/redhat-release @@ -0,0 +1 @@ +Redhat Linux release XX \ No newline at end of file diff --git a/os_info/src/linux/tests/redhat-release b/os_info/src/linux/tests/RedHatEnterprise/etc/redhat-release similarity index 100% rename from os_info/src/linux/tests/redhat-release rename to os_info/src/linux/tests/RedHatEnterprise/etc/redhat-release diff --git a/os_info/src/linux/tests/os-release-rhel-7 b/os_info/src/linux/tests/RedHatEnterprise_7/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-rhel-7 rename to os_info/src/linux/tests/RedHatEnterprise_7/etc/os-release diff --git a/os_info/src/linux/tests/os-release-rhel b/os_info/src/linux/tests/RedHatEnterprise_8/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-rhel rename to os_info/src/linux/tests/RedHatEnterprise_8/etc/os-release diff --git a/os_info/src/linux/tests/RedHatEnterprise_Unknown/etc/redhat-release b/os_info/src/linux/tests/RedHatEnterprise_Unknown/etc/redhat-release new file mode 100644 index 00000000..e69de29b diff --git a/os_info/src/linux/tests/os-release-suse-12 b/os_info/src/linux/tests/SUSE_12/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-suse-12 rename to os_info/src/linux/tests/SUSE_12/etc/os-release diff --git a/os_info/src/linux/tests/os-release-suse-15 b/os_info/src/linux/tests/SUSE_15/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-suse-15 rename to os_info/src/linux/tests/SUSE_15/etc/os-release diff --git a/os_info/src/linux/tests/os-release-ubuntu b/os_info/src/linux/tests/Ubuntu/etc/os-release similarity index 100% rename from os_info/src/linux/tests/os-release-ubuntu rename to os_info/src/linux/tests/Ubuntu/etc/os-release diff --git a/os_info/src/linux/tests/none_invalid_os_release/etc/os-release b/os_info/src/linux/tests/none_invalid_os_release/etc/os-release new file mode 100644 index 00000000..92258e65 --- /dev/null +++ b/os_info/src/linux/tests/none_invalid_os_release/etc/os-release @@ -0,0 +1,2 @@ +ID="Lorem ipsum dolor sit amet" +VERSION_ID="It's all greek to me"