use product_os_command_control::authentication::{
CommandControlAuthenticateError, CommandControlAuthenticateErrorState,
AuthExchangeKeyData,
};
#[test]
fn test_auth_error_display() {
let error = CommandControlAuthenticateError {
error: CommandControlAuthenticateErrorState::KeyError("Invalid key".to_string()),
};
let display = format!("{}", error);
assert_eq!(display, "Invalid key");
}
#[test]
fn test_auth_error_none() {
let error = CommandControlAuthenticateError {
error: CommandControlAuthenticateErrorState::None,
};
let display = format!("{}", error);
assert_eq!(display, "No error");
}
#[test]
fn test_auth_error_serialization() {
let error = CommandControlAuthenticateError {
error: CommandControlAuthenticateErrorState::KeyError("Test error".to_string()),
};
let json = serde_json::to_string(&error).unwrap();
assert!(json.contains("keyError"));
assert!(json.contains("Test error"));
}
#[test]
fn test_auth_error_deserialization() {
let json = r#"{"error":{"keyError":"Test error"}}"#;
let error: CommandControlAuthenticateError = serde_json::from_str(json).unwrap();
match error.error {
CommandControlAuthenticateErrorState::KeyError(msg) => {
assert_eq!(msg, "Test error");
}
_ => panic!("Expected KeyError variant"),
}
}
#[test]
fn test_auth_exchange_key_data_serialization() {
let data = AuthExchangeKeyData {
identifier: "test-id-123".to_string(),
session: "session-456".to_string(),
public_key: vec![1, 2, 3, 4, 5],
};
let json = serde_json::to_string(&data).unwrap();
assert!(json.contains("test-id-123"));
assert!(json.contains("session-456"));
}
#[test]
fn test_auth_exchange_key_data_deserialization() {
let json = r#"{"identifier":"node-1","session":"sess-1","publicKey":[10,20,30]}"#;
let data: AuthExchangeKeyData = serde_json::from_str(json).unwrap();
assert_eq!(data.identifier, "node-1");
assert_eq!(data.session, "sess-1");
assert_eq!(data.public_key, vec![10, 20, 30]);
}
#[test]
fn test_auth_exchange_key_data_roundtrip() {
let original = AuthExchangeKeyData {
identifier: "roundtrip-test".to_string(),
session: "session-data".to_string(),
public_key: vec![100, 200, 50, 75],
};
let json = serde_json::to_string(&original).unwrap();
let deserialized: AuthExchangeKeyData = serde_json::from_str(&json).unwrap();
assert_eq!(original.identifier, deserialized.identifier);
assert_eq!(original.session, deserialized.session);
assert_eq!(original.public_key, deserialized.public_key);
}
#[test]
fn test_auth_error_state_variants() {
let key_error = CommandControlAuthenticateErrorState::KeyError("error".to_string());
let none_error = CommandControlAuthenticateErrorState::None;
match key_error {
CommandControlAuthenticateErrorState::KeyError(_) => (),
_ => panic!("Expected KeyError"),
}
match none_error {
CommandControlAuthenticateErrorState::None => (),
_ => panic!("Expected None"),
}
}