From 9f56de09974df969faf157ab9d9dd64d5a48f5c8 Mon Sep 17 00:00:00 2001 From: Krzysztof Piotrowski Date: Mon, 5 Feb 2024 17:55:39 +0000 Subject: [PATCH 1/3] Convert special characters to hex values in package version Signed-off-by: Krzysztof Piotrowski --- crates/core/plugin_sm/src/plugin.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/core/plugin_sm/src/plugin.rs b/crates/core/plugin_sm/src/plugin.rs index 851903c8432..ed3e1fc989d 100644 --- a/crates/core/plugin_sm/src/plugin.rs +++ b/crates/core/plugin_sm/src/plugin.rs @@ -554,5 +554,17 @@ fn sm_path(name: &str, version: &Option, target_dir_path: impl AsRef String { + let mut result = String::new(); + filename.chars().for_each(|c| { + if matches!(c as u8, b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z' | b'-' | b'.' | b'_' | b'~') { + result.push(c) + } else { + result.push_str(&format!("%{:x?}", c as u8)) + } + }); + result } From ae817d01ec27f2ddc4bbbcdabf5439edb28864e9 Mon Sep 17 00:00:00 2001 From: Krzysztof Piotrowski Date: Tue, 6 Feb 2024 11:18:04 +0000 Subject: [PATCH 2/3] Add test for handling special characters in module version Signed-off-by: Krzysztof Piotrowski --- crates/core/plugin_sm/src/plugin.rs | 2 +- crates/core/plugin_sm/tests/plugin.rs | 14 +++++++++++ .../RobotFramework/tests/plugin_apt/build.sh | 8 +++++-- .../install_overwrite_config_files.robot | 1 - .../install_package_with_epoch.robot | 22 ++++++++++++++++++ .../plugin_apt/nfpm-package-with-epoch.yaml | 19 +++++++++++++++ .../tests/plugin_apt/nfpm-version1.yaml | 2 +- .../tests/plugin_apt/nfpm-version2.yaml | 2 +- .../package-with-epoch_1.2.3_all.deb | Bin 0 -> 762 bytes .../tests/plugin_apt/sampledeb_1.0.0_all.deb | Bin 722 -> 714 bytes .../tests/plugin_apt/sampledeb_2.0.0_all.deb | Bin 720 -> 714 bytes tests/images/debian-systemd/files/tedge.toml | 1 + 12 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 tests/RobotFramework/tests/plugin_apt/install_package_with_epoch.robot create mode 100644 tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml create mode 100644 tests/RobotFramework/tests/plugin_apt/package-with-epoch_1.2.3_all.deb diff --git a/crates/core/plugin_sm/src/plugin.rs b/crates/core/plugin_sm/src/plugin.rs index ed3e1fc989d..44a7af66fad 100644 --- a/crates/core/plugin_sm/src/plugin.rs +++ b/crates/core/plugin_sm/src/plugin.rs @@ -547,7 +547,7 @@ pub fn deserialize_module_info( Ok(software_list) } -fn sm_path(name: &str, version: &Option, target_dir_path: impl AsRef) -> PathBuf { +pub fn sm_path(name: &str, version: &Option, target_dir_path: impl AsRef) -> PathBuf { let mut filename = name.to_string(); if let Some(version) = version { filename.push('_'); diff --git a/crates/core/plugin_sm/tests/plugin.rs b/crates/core/plugin_sm/tests/plugin.rs index 2125437ec28..90a1c3e7753 100644 --- a/crates/core/plugin_sm/tests/plugin.rs +++ b/crates/core/plugin_sm/tests/plugin.rs @@ -2,9 +2,11 @@ mod tests { use plugin_sm::plugin::deserialize_module_info; + use plugin_sm::plugin::sm_path; use plugin_sm::plugin::ExternalPluginCommand; use serial_test::serial; use std::io::Write; + use std::path::Path; use std::path::PathBuf; use std::str::FromStr; use tedge_api::SoftwareError; @@ -147,6 +149,18 @@ mod tests { assert_eq!(res, Ok(())); } + #[test_case("abc", &Some("1:2.3.4567-8~1234".to_string()), "/tmp", PathBuf::from("/tmp/abc_1%3a2.3.4567-8~1234") ; "with special character")] + fn handle_special_characters_in_module_version( + name: &str, + version: &Option, + target_dir_path: impl AsRef, + expected_path: PathBuf, + ) { + let res = sm_path(name, version, target_dir_path); + + assert_eq!(res, expected_path); + } + fn get_dummy_plugin_path() -> PathBuf { // Return a path to a dummy plugin in target directory. let package_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); diff --git a/tests/RobotFramework/tests/plugin_apt/build.sh b/tests/RobotFramework/tests/plugin_apt/build.sh index 53e9fe57ac1..5a56b57477e 100755 --- a/tests/RobotFramework/tests/plugin_apt/build.sh +++ b/tests/RobotFramework/tests/plugin_apt/build.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +set -e SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -nfpm package -f "$SCRIPT_DIR/nfpm-version1.yaml" --target "$SCRIPT_DIR/" --packager deb -nfpm package -f "$SCRIPT_DIR/nfpm-version2.yaml" --target "$SCRIPT_DIR/" --packager deb +pushd "$SCRIPT_DIR" 2>/dev/null ||: +nfpm package -f "nfpm-version1.yaml" --target "./" --packager deb +nfpm package -f "nfpm-version2.yaml" --target "./" --packager deb +nfpm package -f "nfpm-package-with-epoch.yaml" --target "./" --packager deb +popd 2>/dev/null ||: diff --git a/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot b/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot index ca01dbc1988..f1e5b3c346c 100644 --- a/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot +++ b/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot @@ -45,7 +45,6 @@ Install packages overwrite config files ${output}= Execute Command cat /etc/sampledeb.cfg Should Contain ${output} conf 2.0 - *** Keywords *** Custom Setup ${DEVICE_SN}= Setup diff --git a/tests/RobotFramework/tests/plugin_apt/install_package_with_epoch.robot b/tests/RobotFramework/tests/plugin_apt/install_package_with_epoch.robot new file mode 100644 index 00000000000..98f9f8ab71a --- /dev/null +++ b/tests/RobotFramework/tests/plugin_apt/install_package_with_epoch.robot @@ -0,0 +1,22 @@ +*** Settings *** +Resource ../../resources/common.resource +Library ThinEdgeIO +Library Cumulocity + +Test Setup Custom Setup +Test Teardown Get Logs + +Test Tags theme:software theme:plugins + +*** Test Cases *** +Install package with Epoch in version #2666 + ${FILE_URL}= Cumulocity.Create Inventory Binary package-with-epoch package file=${CURDIR}/package-with-epoch_1.2.3_all.deb + ${OPERATION}= Install Software {"name": "package-with-epoch", "version": "2:1.2.3", "softwareType": "apt", "url": "${FILE_URL}"} + ${OPERATION}= Operation Should Be SUCCESSFUL ${OPERATION} timeout=60 + Device Should Have Installed Software {"name": "package-with-epoch", "version": "2:1.2.3", "softwareType": "apt"} + +*** Keywords *** +Custom Setup + ${DEVICE_SN}= Setup + Device Should Exist ${DEVICE_SN} + \ No newline at end of file diff --git a/tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml b/tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml new file mode 100644 index 00000000000..8936072e5aa --- /dev/null +++ b/tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml @@ -0,0 +1,19 @@ +# yaml-language-server: $schema=https://nfpm.goreleaser.com/static/schema.json +--- +name: package-with-epoch +arch: all +platform: linux +version: 1.2.3 +section: default +priority: optional +maintainer: thin-edge.io +description: Example package which uses the epoch field +homepage: https://thin-edge.io/ +license: MIT +epoch: "2" + +contents: + # reuse an existing file for convenience + - src: ./sampledeb_1.cfg + dst: /etc/package-with-epoch/ + type: config diff --git a/tests/RobotFramework/tests/plugin_apt/nfpm-version1.yaml b/tests/RobotFramework/tests/plugin_apt/nfpm-version1.yaml index d825e43485d..6e85839382e 100644 --- a/tests/RobotFramework/tests/plugin_apt/nfpm-version1.yaml +++ b/tests/RobotFramework/tests/plugin_apt/nfpm-version1.yaml @@ -4,7 +4,7 @@ platform: linux version: 1.0.0 section: default priority: optional -maintainer: Your Name +maintainer: thin-edge.io description: My Sample App Debian Package homepage: https://example.com/myapp license: MIT diff --git a/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml b/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml index a3f228756da..ca7128b3147 100644 --- a/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml +++ b/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml @@ -4,7 +4,7 @@ platform: linux version: 2.0.0 section: default priority: optional -maintainer: Your Name +maintainer: thin-edge.io description: My Sample App Debian Package homepage: https://example.com/myapp license: MIT diff --git a/tests/RobotFramework/tests/plugin_apt/package-with-epoch_1.2.3_all.deb b/tests/RobotFramework/tests/plugin_apt/package-with-epoch_1.2.3_all.deb new file mode 100644 index 0000000000000000000000000000000000000000..c6584fc0ae28b8c0fa28669b106444839cbacb82 GIT binary patch literal 762 zcmY$iNi0gvu;WTeP0CEn(@o0EODw8XP*5;5H!wFcGBGzbQ&2Df@?oT*fq|KciGl(U zK|unSk)8opa(-S(QGSkINn(*+dKF>)#^x4q{qo%$3}Ep8&D6l|D+U4$-!1ni{X4L2 za^B=QjxLUl@-5BG@v5`^%n#-SPnr^3zxT%B#}V@H9IK8e?wg*u++-$a&E#cU3$--c z?v^Pio!S?#tQ6;Fqp|hz-U&C#S55xQXQ`!G)*yYYppDCO< z|B?QddFp73!{L9&{;Tkwusdda zHhb>6DVDFd)&6ileJ^<1$@Aq`Yk%aOD_&r)dvNXNYX>K3Iv28J7aLS@F;~BPTwgZp zn@z`_IiK6AZJyabZ}Hj zTe(|%qRcLQ)XslXu}W{R%eCM2GPMidsvSuFxA*|}|H|v1U;Pgbc)Bh`YwG{W@r(=% z|Noy@%(b6EfPo<;u_O^5Wx)6#6zhhThS*|lQtY~B1%cK`F6n^u35`$h6li8$mhZV# z^4s_8*&}AYSC5qJo37Z{a`@+o?g=%DVXO=Xgm{G+mK8@VR%4EeOx?oZ5-p{ec{f6N zyWLJduZu@##LcbVZeM%HPvYmQnUB$P=E%UzjH`g1vWL)41STIGjXtGfKo&EjSy^{9L-ota);Ea(C6Ugf) M#VVBd{N&o-= literal 0 HcmV?d00001 diff --git a/tests/RobotFramework/tests/plugin_apt/sampledeb_1.0.0_all.deb b/tests/RobotFramework/tests/plugin_apt/sampledeb_1.0.0_all.deb index 656be4302d2ed6141d2c446c74de4c6e7fa1f709..332b865212e610df88557cc5c70ad8ec9686ba38 100644 GIT binary patch delta 614 zcmcb_dWv;|G`qQxk%_sf*PLD9ZWn+5cm4JI8^=|}AKUhpTYsNgo*AeX8xp}Xa7WdUFO70DUj&HK!S zzOwpo{Egd{;(hJgcVDfIjlPOXY!jmd3nO38j1bw$yVgh{@P){noZHvlSWc}g;X5|x z^!D=o@1`Gqdt}c4EBEEDm-wm6x1WAhzvuhHGxI;|ET6T11&1c9!=pat9s6}YKKOaO eMqcLU-7ncahH0|vfvM#Ge^J3aNd_(k1}*?y&k~OS delta 622 zcmX@bdWm&{G`o?BnW=@5(L^On1t?QN!9W27Af%yzftiVkf`YM``D8^Vk@~4;v+fuO zG<;vPe1`Z6+o;={lD#q&+P_T@iqQCCajj1{@TAZrp1XFnE2Eumdh?}Tp8sMu&#_5q zZXbGAMg3NF&o7_OEEu@;t(f3Po21L%tZ$a}W~prJy|wVjzSm_9;%i<`G)?Vd*k60D zviLto`4aofw*3=Mu%33Gcf`H#&fxSNBeqePseZTnfmQrZ^iy4KG!~d zyn3+asbIjK&wYo(ZaSY+>@EF!y6x6n4VJ>gp6JKlWJl%TB8?_mG5_B6OKZ~^@T04v`k&Hw-a diff --git a/tests/RobotFramework/tests/plugin_apt/sampledeb_2.0.0_all.deb b/tests/RobotFramework/tests/plugin_apt/sampledeb_2.0.0_all.deb index eec5c1ecbdd68b2361e6df6f31ab622f2da579f7..032a52dd7492ac2608a94dd278b79f946c9b6f79 100644 GIT binary patch delta 626 zcmcb>dWv;|G`qQxk%_sf*+eDFdMHyt!9W27Af%yzftiVkf`YM`Ay`yFA%RQ2n}Y!i z{=b=ezH6?5NPFya&2!v7Hfbi`yfkHJxbBva*m0q@=XkaAVouMNdv>)eb*Dc{6FYj_ zesX@Xh1M_YL*<9O-#!zWqx+3nF!0*fD8a($kM;WmT|>=H;OMddoH;ww1PQRw>l`z@6;I)E01*J`xgt8@?`exEqhF z;#V@K$ls}VspBp8J9&Ja&dbxYCS{vXz3f_fUQY8>!k_*Ye{qX-{0Ex9fAH8FX#8i+ zgugHC|CS#*otg2-=&0=ekCXmuJiS(b)9mK|Xal}S1rx5APpT4n6|h&ZIV03`n@h5O z7DHUnrKhE~1-A1xdH?5q{nNhh*rht@2d@8*{yp~J>q_Xi|6&FyJB?@hJS+XA%fRse ze@)S^SquUU3|uLRC5d_^iA8$pRp1CPG&g`o)MOqeiF!yZp~cF@z;lNbc-TM4wF+;T zw)Lsa?;kVtwbBm%mcDsg=xeHRs@~Kf5kiJneorH{dMaD q1%tX8j@Y^v#792re?I?IX~{wPW%0>9hPNwNz+TCo@tJ{(fdK#`G!h8_ delta 620 zcmX@bdVzIRo zw^2<|Xtw?H7jN^d1q4HHuM-s1S3b4vzG<%d)SL}dv)XyT#cpT5vtgO~v?-cQe?D1G zKl@kp&g6eC{5B3s;yV2`Lh=@BkDoJss}~K^=v(vom*ppy?z4~Vq~v|=_#YhJZl7}0 z_e#Io=5yXp7*9kMx~H8>N$X>-`QqL3{fR`}+`mHFWhrl@|LsXzv!#6f(cPA*o2DHX zcmLeV?(p%NHD7jWzh%40m9PHNS>?+Fj_9h(`u>Q!cUQ9SHPa4G#=M^?8Ex`!JMY(? zt=Fj!eS1t#S1)(QW6S@6E4}}R_8rLUqSRP+7qdfX z@wKm)D^`5@5>WChJ>vfVOrvSrXEU7twST(!KlAFFV*l4WPTU=!A@a|E9~%S1|NrSf zeitzaFfgPfmL%$xBo^tVSAnC#(A)qTIg+q=L5&?lGb3Q^h}JuWw-wp_0OvR soilFS+o8Pqq)@%h{}8{uh2moM^YdIZmtI-6juGS^DJhd93|tHh0M7mvx&QzG diff --git a/tests/images/debian-systemd/files/tedge.toml b/tests/images/debian-systemd/files/tedge.toml index c71266b77d7..309c98d7a46 100644 --- a/tests/images/debian-systemd/files/tedge.toml +++ b/tests/images/debian-systemd/files/tedge.toml @@ -1,3 +1,4 @@ [apt] name = "(tedge|c8y|python|wget|vim|curl|apt|mosquitto|ssh|sudo|rolldice).*" +maintainer = ".*(thin-edge.io).*" From 153b90f1e54ce259c842ff0330e9f955c6a8a824 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Tue, 6 Feb 2024 18:21:06 +0100 Subject: [PATCH 3/3] ignore default maintainer filter Signed-off-by: Reuben Miller --- .../tests/plugin_apt/filter_packages_list_output.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/RobotFramework/tests/plugin_apt/filter_packages_list_output.robot b/tests/RobotFramework/tests/plugin_apt/filter_packages_list_output.robot index b921944f5e4..12e74768cee 100644 --- a/tests/RobotFramework/tests/plugin_apt/filter_packages_list_output.robot +++ b/tests/RobotFramework/tests/plugin_apt/filter_packages_list_output.robot @@ -11,7 +11,7 @@ Test Tags theme:software theme:plugins *** Test Cases *** Apply name filter ${packages_list}= Execute Command - ... sudo /etc/tedge/sm-plugins/apt list --name tedge + ... sudo /etc/tedge/sm-plugins/apt list --name tedge --maintainer "" ... exp_exit_code=0 Should Match Regexp ${packages_list} ^tedge\\s+${VERSION}