81 lines
2.2 KiB
Rust
81 lines
2.2 KiB
Rust
//! Public approval text and template presets from v2, without vault migrations.
|
|
use sausage::cred::{
|
|
edits::Operation,
|
|
items::{Field, FieldInput},
|
|
summary::*,
|
|
types::FieldType,
|
|
};
|
|
#[test]
|
|
fn durations_use_plain_language() {
|
|
for (seconds, expected) in [
|
|
(0, "0 seconds"),
|
|
(1, "1 second"),
|
|
(60, "1 minute"),
|
|
(3600, "1 hour"),
|
|
(93604, "1 day 2 hours 4 seconds"),
|
|
] {
|
|
assert_eq!(human_duration(seconds), expected);
|
|
}
|
|
}
|
|
#[test]
|
|
fn summaries_never_include_field_values_or_script_sources() {
|
|
let value = "SECRET_SUMMARY_SENTINEL";
|
|
for operation in [
|
|
Operation::SetTransformJs {
|
|
value: value.into(),
|
|
},
|
|
Operation::AddField {
|
|
field: Field {
|
|
field_id: String::new(),
|
|
name: "token".into(),
|
|
public: false,
|
|
value: Some(value.into()),
|
|
needs_value: true,
|
|
field_type: FieldType::Text,
|
|
key_type: None,
|
|
},
|
|
},
|
|
] {
|
|
assert!(!operation_summary(&operation).contains(value));
|
|
}
|
|
let input = FieldInput {
|
|
value: sausage::cred::items::FieldValue::Plain(value),
|
|
field_type: None,
|
|
key_type: None,
|
|
};
|
|
assert!(!format!("{input:?}").contains(value));
|
|
}
|
|
#[test]
|
|
fn summary_names_are_inert_and_stay_on_one_line() {
|
|
let text = operation_summary(&Operation::SetName {
|
|
name: "<x>&*\nnext".into(),
|
|
});
|
|
assert!(!text.contains('<'));
|
|
assert!(!text.contains('\n'));
|
|
assert!(text.contains("<x>&\\* next"));
|
|
}
|
|
#[test]
|
|
fn presets_preserve_headers_and_utf8_basic_encoding() {
|
|
assert!(
|
|
script("bearer")
|
|
.unwrap()
|
|
.contains("'Bearer ' + get('token')")
|
|
);
|
|
assert!(
|
|
script("basic")
|
|
.unwrap()
|
|
.contains("unescape(encodeURIComponent")
|
|
);
|
|
assert!(
|
|
script("header:x-api-key")
|
|
.unwrap()
|
|
.contains("const name = \"x-api-key\"")
|
|
);
|
|
assert!(
|
|
script("query:access_token")
|
|
.unwrap()
|
|
.contains("url.query.filter")
|
|
);
|
|
assert_eq!(script("unknown").unwrap_err().0, "invalid_preset");
|
|
}
|