use std::path::PathBuf;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use crate::keyring_store;
use crate::oauth;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AuthKind {
#[default]
ApiKey,
OAuth,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CredentialStorage {
#[default]
File,
OsStore,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, clap::ValueEnum)]
#[serde(rename_all = "lowercase")]
pub enum OutputFormat {
#[default]
Text,
Json,
Agents,
}
impl OutputFormat {
pub fn as_str(&self) -> &'static str {
match self {
OutputFormat::Text => "text",
OutputFormat::Json => "json",
OutputFormat::Agents => "agents",
}
}
}
impl std::fmt::Display for OutputFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Region {
Us1,
Us2,
Us3,
Eu1,
Eu2,
Ap1,
Ap2,
Ap3,
Stg1,
#[serde(untagged)]
Custom(String),
}
impl Region {
pub fn api_endpoint(&self) -> &str {
match self {
Region::Us1 => "https://api.us1.coralogix.com",
Region::Us2 => "https://api.us2.coralogix.com",
Region::Us3 => "https://api.us3.coralogix.com",
Region::Eu1 => "https://api.eu1.coralogix.com",
Region::Eu2 => "https://api.eu2.coralogix.com",
Region::Ap1 => "https://api.ap1.coralogix.com",
Region::Ap2 => "https://api.ap2.coralogix.com",
Region::Ap3 => "https://api.ap3.coralogix.com",
Region::Stg1 => "https://api.stg1.coralogix.net",
Region::Custom(url) => url.as_str(),
}
}
}
impl std::fmt::Display for Region {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Region::Us1 => write!(f, "us1"),
Region::Us2 => write!(f, "us2"),
Region::Us3 => write!(f, "us3"),
Region::Eu1 => write!(f, "eu1"),
Region::Eu2 => write!(f, "eu2"),
Region::Ap1 => write!(f, "ap1"),
Region::Ap2 => write!(f, "ap2"),
Region::Ap3 => write!(f, "ap3"),
Region::Stg1 => write!(f, "stg1"),
Region::Custom(s) => write!(f, "{s}"),
}
}
}
impl std::str::FromStr for Region {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self> {
Ok(match s.to_lowercase().as_str() {
"us1" => Region::Us1,
"us2" => Region::Us2,
"us3" => Region::Us3,
"eu1" => Region::Eu1,
"eu2" => Region::Eu2,
"ap1" => Region::Ap1,
"ap2" => Region::Ap2,
"ap3" => Region::Ap3,
"stg1" => Region::Stg1,
other => Region::Custom(other.to_string()),
})
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ManagedCompletion {
pub shell: String,
pub path: PathBuf,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
#[serde(default = "default_profile")]
pub default_profile: String,
#[serde(default)]
pub default_output_format: OutputFormat,
#[serde(
default = "default_max_dataprime_direct_output_size",
with = "max_size_serde"
)]
pub max_dataprime_direct_output_size: Option<usize>,
#[serde(default = "default_temp_dir")]
pub temp_dir: String,
#[serde(default = "default_true")]
pub allow_risky_commands: bool,
#[serde(default = "default_true")]
pub allow_costly_commands: bool,
#[serde(default)]
pub read_only: bool,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub managed_completions: Vec<ManagedCompletion>,
}
fn default_profile() -> String {
"default".to_string()
}
fn default_true() -> bool {
true
}
fn default_max_dataprime_direct_output_size() -> Option<usize> {
Some(100 * 1024) }
fn default_temp_dir() -> String {
"/tmp/".to_string()
}
impl Default for Config {
fn default() -> Self {
Self {
default_profile: default_profile(),
default_output_format: OutputFormat::default(),
max_dataprime_direct_output_size: default_max_dataprime_direct_output_size(),
temp_dir: default_temp_dir(),
allow_risky_commands: true,
allow_costly_commands: true,
read_only: false,
managed_completions: vec![],
}
}
}
mod max_size_serde {
use serde::{Deserialize, Deserializer, Serialize, Serializer};
pub fn serialize<S>(value: &Option<usize>, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match value {
Some(n) => (*n as i64).serialize(s),
None => (-1i64).serialize(s),
}
}
pub fn deserialize<'de, D>(de: D) -> Result<Option<usize>, D::Error>
where
D: Deserializer<'de>,
{
let n = i64::deserialize(de)?;
if n < 0 {
Ok(None)
} else {
Ok(Some(n as usize))
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct StoredOAuthTokens {
pub access_token: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub id_token: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub expiry: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Profile {
#[serde(default)]
pub auth: AuthKind,
#[serde(default)]
pub credential_storage: CredentialStorage,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub api_key: Option<String>,
pub region: Region,
pub label: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub oauth_client_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub oauth_base_url: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub oauth_tokens: Option<StoredOAuthTokens>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub default_output_format: Option<OutputFormat>,
}
#[derive(Debug, Clone)]
pub struct ResolvedConfig {
pub profile_name: String,
pub api_key: String,
pub endpoint: String,
}
pub fn config_dir() -> Result<PathBuf> {
if let Ok(cx_home) = std::env::var("CX_HOME") {
return Ok(PathBuf::from(cx_home).join(".cx"));
}
let home = dirs::home_dir().context("Could not determine home directory")?;
Ok(home.join(".cx"))
}
pub fn config_file() -> Result<PathBuf> {
Ok(config_dir()?.join("config.toml"))
}
pub fn profiles_dir() -> Result<PathBuf> {
Ok(config_dir()?.join("profiles"))
}
pub fn profile_file(name: &str) -> Result<PathBuf> {
Ok(profiles_dir()?.join(format!("{name}.toml")))
}
pub fn list_profile_names() -> Result<Vec<String>> {
list_profile_names_from(&profiles_dir()?)
}
fn list_profile_names_from(dir: &PathBuf) -> Result<Vec<String>> {
if !dir.exists() {
return Ok(vec![]);
}
let mut names: Vec<String> = std::fs::read_dir(dir)?
.filter_map(|entry| {
let entry = entry.ok()?;
let path = entry.path();
if path.extension()?.to_str()? != "toml" {
return None;
}
Some(path.file_stem()?.to_str()?.to_string())
})
.collect();
names.sort();
Ok(names)
}
pub fn load_config() -> Result<Config> {
let path = config_file()?;
if !path.exists() {
return Ok(Config::default());
}
let raw = std::fs::read_to_string(&path)
.with_context(|| format!("Failed to read {}", path.display()))?;
toml::from_str(&raw).context("Failed to parse config.toml")
}
pub fn save_config(config: &Config) -> Result<()> {
let dir = config_dir()?;
std::fs::create_dir_all(&dir)?;
let path = config_file()?;
let content = toml::to_string_pretty(config).context("Failed to serialize config")?;
std::fs::write(&path, content)
.with_context(|| format!("Failed to write {}", path.display()))?;
Ok(())
}
pub fn first_profile_output_format(profiles: &[String]) -> Option<OutputFormat> {
let name = if profiles.is_empty() {
load_config().ok().map(|c| c.default_profile)
} else {
Some(profiles[0].clone())
};
name.and_then(|n| load_profile(&n).ok())
.and_then(|p| p.default_output_format)
}
pub fn load_profile(name: &str) -> Result<Profile> {
let path = profile_file(name)?;
let raw = std::fs::read_to_string(&path).with_context(|| {
format!("Profile '{name}' not found. Run `cx profiles add` to set it up.")
})?;
toml::from_str(&raw).with_context(|| format!("Failed to parse profile '{name}'"))
}
async fn resolve_single(
profile_name: &str,
api_key_override: Option<&str>,
region_override: Option<&str>,
) -> Result<ResolvedConfig> {
if !profile_file(profile_name)?.exists() {
if let (Some(key), Some(region)) = (api_key_override, region_override) {
let region: Region = region.parse()?;
return Ok(ResolvedConfig {
profile_name: profile_name.to_string(),
endpoint: region.api_endpoint().to_string(),
api_key: key.to_string(),
});
}
}
let mut profile = load_profile(profile_name)?;
if let Some(region) = region_override {
profile.region = region.parse()?;
}
let bearer = if let Some(key) = api_key_override {
key.to_string()
} else {
match profile.auth {
AuthKind::ApiKey => match profile.credential_storage {
CredentialStorage::OsStore => keyring_store::get_secret(profile_name, "api_key")?,
CredentialStorage::File => profile.api_key.clone(),
}
.ok_or_else(|| {
anyhow::anyhow!(
"No API key found for profile '{profile_name}'.\n\
Run `cx profiles add {profile_name}` to set it up."
)
})?,
AuthKind::OAuth => {
let region_name = profile.region.to_string();
let base_url = profile
.oauth_base_url
.clone()
.unwrap_or_else(|| profile.region.api_endpoint().to_string());
let client_id = profile
.oauth_client_id
.clone()
.or_else(|| oauth::client_id_for_region(®ion_name).map(str::to_string))
.ok_or_else(|| {
anyhow::anyhow!(
"No OAuth client ID configured for profile '{profile_name}' \
(region: {region_name}).\n\
Run `cx profiles add {profile_name}` to reconfigure."
)
})?;
let storage = profile.credential_storage;
let (bearer, refreshed) = oauth::resolve_token(
profile_name,
&base_url,
&client_id,
storage,
profile.oauth_tokens.as_ref(),
)
.await?;
if let Some(new_tokens) = refreshed {
profile.oauth_tokens = Some(new_tokens);
save_profile(profile_name, &profile)?;
}
bearer
}
}
};
Ok(ResolvedConfig {
profile_name: profile_name.to_string(),
endpoint: profile.region.api_endpoint().to_string(),
api_key: bearer,
})
}
pub async fn resolve(
profile_override: Option<&str>,
api_key_override: Option<&str>,
region_override: Option<&str>,
) -> Result<ResolvedConfig> {
let config = load_config()?;
let name = profile_override.unwrap_or(&config.default_profile);
resolve_single(name, api_key_override, region_override).await
}
pub async fn resolve_all(
profiles: &[String],
api_key_override: Option<&str>,
region_override: Option<&str>,
) -> Result<Vec<ResolvedConfig>> {
if profiles.is_empty() {
let cfg = load_config()?;
return Ok(vec![
resolve_single(&cfg.default_profile, api_key_override, region_override).await?,
]);
}
let mut results = Vec::with_capacity(profiles.len());
for name in profiles {
results.push(resolve_single(name, api_key_override, region_override).await?);
}
Ok(results)
}
pub fn save_profile(name: &str, profile: &Profile) -> Result<()> {
let dir = profiles_dir()?;
std::fs::create_dir_all(&dir)?;
let path = dir.join(format!("{name}.toml"));
let content = toml::to_string_pretty(profile).context("Failed to serialize profile")?;
std::fs::write(&path, &content)
.with_context(|| format!("Failed to write {}", path.display()))?;
#[cfg(unix)]
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600))
.with_context(|| format!("Failed to set permissions on {}", path.display()))?;
Ok(())
}
pub fn has_managed_completions() -> bool {
load_config()
.map(|c| !c.managed_completions.is_empty())
.unwrap_or(false)
}
pub fn managed_completions() -> Result<Vec<ManagedCompletion>> {
Ok(load_config()?.managed_completions)
}
pub fn upsert_managed_completion(shell: &str, path: PathBuf) -> Result<()> {
let mut config = load_config().unwrap_or_default();
if let Some(existing) = config
.managed_completions
.iter_mut()
.find(|c| c.shell == shell)
{
existing.path = path;
} else {
config.managed_completions.push(ManagedCompletion {
shell: shell.to_string(),
path,
});
}
save_config(&config)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn list_profile_names_sorted_and_filters_non_toml() {
let dir =
std::env::temp_dir().join(format!("cx_test_list_profiles_{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("prod.toml"), "").unwrap();
std::fs::write(dir.join("staging.toml"), "").unwrap();
std::fs::write(dir.join("alpha.toml"), "").unwrap();
std::fs::write(dir.join("ignored.txt"), "").unwrap();
std::fs::write(dir.join("also-ignored.json"), "").unwrap();
let names = list_profile_names_from(&dir).unwrap();
assert_eq!(names, vec!["alpha", "prod", "staging"]);
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn list_profile_names_missing_dir_returns_empty() {
let dir = std::env::temp_dir().join("cx_test_nonexistent_profiles_dir_xyz_never_created");
let _ = std::fs::remove_dir_all(&dir);
let names = list_profile_names_from(&dir).unwrap();
assert!(names.is_empty());
}
#[test]
fn list_profile_names_empty_dir_returns_empty() {
let dir =
std::env::temp_dir().join(format!("cx_test_empty_profiles_{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let names = list_profile_names_from(&dir).unwrap();
assert!(names.is_empty());
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn managed_completion_roundtrips_through_toml() {
let mc = ManagedCompletion {
shell: "zsh".to_string(),
path: PathBuf::from("/home/user/.zfunc/_cx"),
};
let config = Config {
managed_completions: vec![mc.clone()],
..Config::default()
};
let toml = toml::to_string_pretty(&config).unwrap();
let restored: Config = toml::from_str(&toml).unwrap();
assert_eq!(restored.managed_completions.len(), 1);
assert_eq!(restored.managed_completions[0], mc);
}
#[test]
fn default_config_has_no_managed_completions() {
let config = Config::default();
assert!(config.managed_completions.is_empty());
}
#[test]
fn config_without_managed_completions_field_deserialises_ok() {
let toml = r#"
default_profile = "my-profile"
"#;
let config: Config = toml::from_str(toml).unwrap();
assert!(config.managed_completions.is_empty());
assert_eq!(config.default_profile, "my-profile");
}
#[test]
fn managed_completions_not_written_when_empty() {
let config = Config::default();
let toml = toml::to_string_pretty(&config).unwrap();
assert!(
!toml.contains("managed_completions"),
"empty managed_completions should be skipped in TOML output"
);
}
#[test]
fn resolved_config_carries_profile_name() {
let cfg = ResolvedConfig {
profile_name: "prod".to_string(),
api_key: "k".to_string(),
endpoint: "https://api.eu2.coralogix.com".to_string(),
};
assert_eq!(cfg.profile_name, "prod");
}
#[test]
fn region_api_endpoint_eu1() {
assert_eq!(Region::Eu1.api_endpoint(), "https://api.eu1.coralogix.com");
}
#[test]
fn region_api_endpoint_us1() {
assert_eq!(Region::Us1.api_endpoint(), "https://api.us1.coralogix.com");
}
#[test]
fn region_parses_from_str() {
let r: Region = "eu2".parse().unwrap();
assert_eq!(r.api_endpoint(), "https://api.eu2.coralogix.com");
}
#[test]
fn region_custom_roundtrip() {
let url = "https://custom.endpoint.io";
let r: Region = url.parse().unwrap();
assert_eq!(r.api_endpoint(), url);
}
#[test]
fn profile_without_auth_field_defaults_to_api_key() {
let toml = r#"
region = "eu1"
api_key = "mykey"
"#;
let p: Profile = toml::from_str(toml).unwrap();
assert_eq!(p.auth, AuthKind::ApiKey);
assert_eq!(p.api_key.as_deref(), Some("mykey"));
assert!(p.oauth_client_id.is_none());
assert!(p.oauth_base_url.is_none());
}
#[test]
fn oauth_profile_round_trips() {
let profile = Profile {
auth: AuthKind::OAuth,
credential_storage: CredentialStorage::OsStore,
api_key: None,
region: Region::Eu2,
label: Some("prod".to_string()),
oauth_client_id: None,
oauth_base_url: None,
oauth_tokens: None,
default_output_format: None,
};
let toml = toml::to_string_pretty(&profile).unwrap();
let restored: Profile = toml::from_str(&toml).unwrap();
assert_eq!(restored.auth, AuthKind::OAuth);
assert_eq!(restored.credential_storage, CredentialStorage::OsStore);
assert!(restored.api_key.is_none());
assert!(restored.oauth_client_id.is_none());
assert!(restored.oauth_tokens.is_none());
}
#[test]
fn oauth_profile_file_storage_round_trips() {
let profile = Profile {
auth: AuthKind::OAuth,
credential_storage: CredentialStorage::File,
api_key: None,
region: Region::Eu2,
label: Some("prod".to_string()),
oauth_client_id: None,
oauth_base_url: None,
oauth_tokens: Some(StoredOAuthTokens {
access_token: "access-abc".to_string(),
refresh_token: Some("refresh-xyz".to_string()),
id_token: None,
expiry: Some(1_700_000_000),
}),
default_output_format: None,
};
let toml = toml::to_string_pretty(&profile).unwrap();
let restored: Profile = toml::from_str(&toml).unwrap();
assert_eq!(restored.credential_storage, CredentialStorage::File);
let tokens = restored.oauth_tokens.expect("oauth_tokens persisted");
assert_eq!(tokens.access_token, "access-abc");
assert_eq!(tokens.refresh_token.as_deref(), Some("refresh-xyz"));
assert!(tokens.id_token.is_none());
assert_eq!(tokens.expiry, Some(1_700_000_000));
}
#[test]
fn custom_oauth_profile_preserves_client_id() {
let profile = Profile {
auth: AuthKind::OAuth,
credential_storage: CredentialStorage::OsStore,
api_key: None,
region: Region::Custom("https://api.myenv.coralogix.com".to_string()),
label: None,
oauth_client_id: Some("abc-123".to_string()),
oauth_base_url: None,
oauth_tokens: None,
default_output_format: None,
};
let toml = toml::to_string_pretty(&profile).unwrap();
let restored: Profile = toml::from_str(&toml).unwrap();
assert_eq!(restored.oauth_client_id.as_deref(), Some("abc-123"));
}
#[tokio::test]
async fn resolve_all_missing_profile_returns_error() {
let result = resolve_all(
&["cx_definitely_does_not_exist_xyz".to_string()],
None,
None,
)
.await;
assert!(result.is_err());
}
#[tokio::test]
async fn resolve_single_env_only_synthesises_when_profile_file_missing() {
let cfg = resolve_single(
"cx_envonly_missing_profile_xyz",
Some("env-key"),
Some("eu1"),
)
.await
.unwrap();
assert_eq!(cfg.profile_name, "cx_envonly_missing_profile_xyz");
assert_eq!(cfg.api_key, "env-key");
assert_eq!(cfg.endpoint, "https://api.eu1.coralogix.com");
}
#[tokio::test]
async fn resolve_single_env_only_requires_api_key_override() {
let result = resolve_single("cx_envonly_no_key_xyz", None, Some("eu1")).await;
assert!(result.is_err());
}
#[tokio::test]
async fn resolve_single_env_only_requires_region_override() {
let result = resolve_single("cx_envonly_no_region_xyz", Some("env-key"), None).await;
assert!(result.is_err());
}
#[tokio::test]
#[ignore = "requires write access to ~/.cx; run with `cargo test -- --ignored`"]
async fn resolve_all_integration_multiple_profiles() {
let names = ["cx_inttest_multi_a", "cx_inttest_multi_b"];
for (i, name) in names.iter().enumerate() {
let profile = Profile {
auth: AuthKind::ApiKey,
credential_storage: CredentialStorage::File,
api_key: Some(format!("key-{i}")),
region: Region::Eu1,
label: None,
oauth_client_id: None,
oauth_base_url: None,
oauth_tokens: None,
default_output_format: None,
};
save_profile(name, &profile).unwrap();
}
let configs = resolve_all(
&names.iter().map(|s| s.to_string()).collect::<Vec<_>>(),
None,
None,
)
.await
.unwrap();
assert_eq!(configs.len(), 2);
assert_eq!(configs[0].profile_name, "cx_inttest_multi_a");
assert_eq!(configs[0].api_key, "key-0");
assert_eq!(configs[1].profile_name, "cx_inttest_multi_b");
assert_eq!(configs[1].api_key, "key-1");
for name in &names {
let _ = std::fs::remove_file(profile_file(name).unwrap());
}
}
#[tokio::test]
#[ignore = "requires write access to ~/.cx; run with `cargo test -- --ignored`"]
async fn resolve_all_integration_empty_slice_falls_back_to_default() {
let profile = Profile {
auth: AuthKind::ApiKey,
credential_storage: CredentialStorage::File,
api_key: Some("default-key".to_string()),
region: Region::Eu1,
label: None,
oauth_client_id: None,
oauth_base_url: None,
oauth_tokens: None,
default_output_format: None,
};
save_profile("default", &profile).unwrap();
let configs = resolve_all(&[], None, None).await.unwrap();
assert_eq!(configs.len(), 1);
assert_eq!(configs[0].profile_name, "default");
}
#[tokio::test]
#[ignore = "requires write access to ~/.cx"]
async fn resolve_prefers_cli_override_over_file() {
let name = "cx_inttest_resolve_override";
let profile = Profile {
auth: AuthKind::ApiKey,
credential_storage: CredentialStorage::File,
api_key: Some("file-key".to_string()),
region: Region::Eu1,
label: None,
oauth_client_id: None,
oauth_base_url: None,
oauth_tokens: None,
default_output_format: None,
};
save_profile(name, &profile).unwrap();
let config = resolve_single(name, Some("cli-key"), None).await.unwrap();
assert_eq!(config.api_key, "cli-key");
let _ = std::fs::remove_file(profile_file(name).unwrap());
}
#[tokio::test]
#[ignore = "requires write access to ~/.cx"]
async fn resolve_reads_from_file_storage() {
let name = "cx_inttest_resolve_file";
let profile = Profile {
auth: AuthKind::ApiKey,
credential_storage: CredentialStorage::File,
api_key: Some("file-key".to_string()),
region: Region::Eu1,
label: None,
oauth_client_id: None,
oauth_base_url: None,
oauth_tokens: None,
default_output_format: None,
};
save_profile(name, &profile).unwrap();
let config = resolve_single(name, None, None).await.unwrap();
assert_eq!(config.api_key, "file-key");
let _ = std::fs::remove_file(profile_file(name).unwrap());
}
#[tokio::test]
#[ignore = "requires write access to ~/.cx"]
async fn resolve_errors_when_no_key_anywhere() {
let name = "cx_inttest_resolve_no_key";
let profile = Profile {
auth: AuthKind::ApiKey,
credential_storage: CredentialStorage::File,
api_key: None,
region: Region::Eu1,
label: None,
oauth_client_id: None,
oauth_base_url: None,
oauth_tokens: None,
default_output_format: None,
};
save_profile(name, &profile).unwrap();
let result = resolve_single(name, None, None).await;
assert!(result.is_err());
let _ = std::fs::remove_file(profile_file(name).unwrap());
}
}