[WIP] User Invites
This commit is contained in:
parent
0827882bb3
commit
7164f4671d
24 changed files with 2829 additions and 170 deletions
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use mtp::codec::{CommunicationValue, DataTypeId, DataValue, Version};
|
||||
use mtp::codec::{CommunicationValue, DataTypeId, DataValue, TypeMap, Version};
|
||||
use ratatui::style::Color;
|
||||
|
||||
use iota_state::{UNIQUE, UiLogEntry};
|
||||
|
|
@ -354,6 +354,10 @@ fn format_data_container(data: Vec<(DataTypeId, DataValue)>, version: Version) -
|
|||
.map(|(key, value)| {
|
||||
let key_str = key.to_string();
|
||||
|
||||
if is_secret_data_type(key) {
|
||||
return format!("{}=<redacted>", key_str);
|
||||
}
|
||||
|
||||
match value {
|
||||
DataValue::Str(s) => format!("{}=\"{}\"", key_str, abbreviate_string(&s)),
|
||||
|
||||
|
|
@ -382,6 +386,13 @@ fn format_data_container(data: Vec<(DataTypeId, DataValue)>, version: Version) -
|
|||
parts.join(", ")
|
||||
}
|
||||
|
||||
fn is_secret_data_type(key: DataTypeId) -> bool {
|
||||
matches!(
|
||||
TypeMap::latest().data_type_name(key.0),
|
||||
Some("InvitationToken" | "InvitationPassword" | "ResetToken" | "RegisterId" | "NewToken")
|
||||
)
|
||||
}
|
||||
|
||||
fn format_array(arr: Vec<DataValue>, version: Version) -> String {
|
||||
let parts: Vec<String> = arr
|
||||
.into_iter()
|
||||
|
|
@ -427,7 +438,8 @@ fn abbreviate_string(value: &str) -> String {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::abbreviate_string;
|
||||
use super::{abbreviate_string, format_cv};
|
||||
use mtp::codec::{CommunicationType, CommunicationValue, DataType, DataValue, TypeMap};
|
||||
|
||||
#[test]
|
||||
fn abbreviates_only_strings_longer_than_eight_characters() {
|
||||
|
|
@ -435,6 +447,24 @@ mod tests {
|
|||
assert_eq!(abbreviate_string("123456789"), "1234...6789");
|
||||
assert_eq!(abbreviate_string("YWJjZGVmZ2hpag=="), "YWJj...ag==");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn redacts_invitation_and_account_credentials() {
|
||||
let reset_token = DataType::ResetToken.try_to_id(&TypeMap::latest()).unwrap();
|
||||
let value = CommunicationValue::new(CommunicationType::RedeemUserInvitation)
|
||||
.add_typed_default(DataType::InvitationToken, DataValue::Str("short123".into()))
|
||||
.add_typed_default(
|
||||
DataType::Invitations,
|
||||
DataValue::Array(vec![DataValue::Container(vec![(
|
||||
reset_token,
|
||||
DataValue::Str("reset-secret".into()),
|
||||
)])]),
|
||||
);
|
||||
let formatted = format_cv(&value);
|
||||
assert!(!formatted.contains("short123"));
|
||||
assert!(!formatted.contains("reset-secret"));
|
||||
assert_eq!(formatted.matches("<redacted>").count(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
|
|||
Loading…
Reference in a new issue