2020-11-30 18:47:35 +01:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn base64_defaults_to_encoding_with_standard_character_type() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2022-06-25 23:35:23 +02:00
|
|
|
echo 'username:password' | encode base64
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2020-11-30 18:47:35 +01:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ=");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-10-08 05:01:43 +02:00
|
|
|
fn base64_defaults_to_encoding_with_nopad() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2024-10-08 05:01:43 +02:00
|
|
|
echo 'username:password' | encode base64 --nopad
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2020-11-30 18:47:35 +01:00
|
|
|
|
2024-10-08 05:01:43 +02:00
|
|
|
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ");
|
2020-11-30 18:47:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-10-08 05:01:43 +02:00
|
|
|
fn base64_decode_value() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2024-10-08 05:01:43 +02:00
|
|
|
echo 'YWJjeHl6' | decode base64 | decode
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2020-11-30 18:47:35 +01:00
|
|
|
|
2024-10-08 05:01:43 +02:00
|
|
|
assert_eq!(actual.out, "abcxyz");
|
2020-11-30 18:47:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-10-08 05:01:43 +02:00
|
|
|
fn base64_decode_with_nopad() {
|
|
|
|
let actual = nu!(r#"
|
|
|
|
echo 'R29vZCBsdWNrIHRvIHlvdQ' | decode base64 --nopad | decode
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "Good luck to you");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn base64_decode_with_url() {
|
|
|
|
let actual = nu!(r#"
|
|
|
|
echo 'vu7_' | decode base64 --url | decode
|
|
|
|
"#);
|
2020-11-30 18:47:35 +01:00
|
|
|
|
2024-10-08 05:01:43 +02:00
|
|
|
assert_eq!(actual.out, "¾îÿ");
|
2020-11-30 18:47:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn error_invalid_decode_value() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2024-10-08 05:01:43 +02:00
|
|
|
echo "this should not be a valid encoded value" | decode base64
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2020-11-30 18:47:35 +01:00
|
|
|
|
2024-10-08 05:01:43 +02:00
|
|
|
assert!(actual.err.contains("nu::shell::incorrect_value"));
|
2020-11-30 18:47:35 +01:00
|
|
|
}
|
|
|
|
|
2021-03-20 19:48:53 +01:00
|
|
|
#[test]
|
|
|
|
fn md5_works_with_file() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
2022-04-14 05:15:02 +02:00
|
|
|
open sample.db --raw | hash md5
|
2021-03-20 19:48:53 +01:00
|
|
|
"#
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "4de97601d232c427977ef11db396c951");
|
|
|
|
}
|
2021-07-29 17:22:16 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sha256_works_with_file() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
2022-04-14 05:15:02 +02:00
|
|
|
open sample.db --raw | hash sha256
|
2021-07-29 17:22:16 +02:00
|
|
|
"#
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
"2f5050e7eea415c1f3d80b5d93355efd15043ec9157a2bb167a9e73f2ae651f2"
|
|
|
|
);
|
|
|
|
}
|