Lines
100 %
Functions
Branches
use super::*;
use crate::form_render::fixture::{assert_autocomplete, assert_fixture};
use crate::form_render::{References, render_form};
use chrono::{TimeZone, Utc};
use forms::FormValues;
use server::command::ssh_key::SshKeyRecord;
use uuid::Uuid;
fn record(last_used_at: Option<chrono::DateTime<Utc>>) -> SshKeyRecord {
SshKeyRecord {
id: Uuid::from_u128(1),
user_id: Uuid::from_u128(2),
key_type: "ssh-ed25519".to_string(),
key_blob: vec![1, 2, 3],
fingerprint: "SHA256:abc".to_string(),
annotation: "laptop".to_string(),
created_at: Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap(),
last_used_at,
}
#[test]
fn key_row_formats_the_last_use() {
let used = Utc.with_ymd_and_hms(2024, 3, 5, 14, 7, 0).unwrap();
let row = key_row(record(Some(used)), Tz::UTC);
assert_eq!(row.fingerprint, "SHA256:abc");
assert_eq!(row.key_type, "ssh-ed25519");
assert_eq!(row.annotation, "laptop");
assert_eq!(row.last_used.as_deref(), Some("2024-03-05 14:07"));
fn password_change_fields_keep_their_credential_autocomplete() {
let html = SshKeyPage {
form: String::new(),
keys: Vec::new(),
config_snippet: None,
.render()
.unwrap();
assert_autocomplete(
&html,
&[
("name=\"current_password\"", "current-password"),
("name=\"new_password\"", "new-password"),
("name=\"confirm_password\"", "new-password"),
],
);
fn key_row_prints_the_last_use_in_the_user_zone() {
let used = Utc.with_ymd_and_hms(2024, 3, 5, 23, 30, 0).unwrap();
let row = key_row(record(Some(used)), Tz::Asia__Tokyo);
assert_eq!(row.last_used.as_deref(), Some("2024-03-06 08:30"));
fn key_row_without_use_has_no_timestamp() {
assert!(key_row(record(None), Tz::UTC).last_used.is_none());
fn the_browser_fixture_of_the_ssh_key_add_form_is_up_to_date() {
let html = render_form(
&SSH_KEY_ADD,
&FormValues::default(),
&[],
SUBMIT_PATH,
&References::default(),
)
.expect("renders");
assert_fixture("ssh_key_add.html", &html);
fn the_query_value_keeps_only_unreserved_characters() {
assert_eq!(encode_query("SHA256:a+b/c="), "SHA256%3Aa%2Bb%2Fc%3D");