chore: turn clippy on for test code (#4817)
This commit is contained in:
@@ -1024,7 +1024,7 @@ mod tests {
|
||||
let key = format!("key{}", i);
|
||||
let value = format!("value{}", i);
|
||||
assert!(
|
||||
final_values.get(&key).is_some(),
|
||||
final_values.contains_key(&key),
|
||||
"Missing key {} in final values",
|
||||
key
|
||||
);
|
||||
@@ -1075,7 +1075,7 @@ mod tests {
|
||||
|
||||
// Should have recovered the data
|
||||
assert!(
|
||||
recovered_values.len() >= 1,
|
||||
!recovered_values.is_empty(),
|
||||
"Should have recovered at least one key"
|
||||
);
|
||||
|
||||
@@ -1169,7 +1169,7 @@ mod tests {
|
||||
|
||||
// Should have recovered the data from backup
|
||||
assert!(
|
||||
recovered_values.len() >= 1,
|
||||
!recovered_values.is_empty(),
|
||||
"Should have recovered data from backup"
|
||||
);
|
||||
|
||||
@@ -1260,10 +1260,10 @@ mod tests {
|
||||
assert_eq!(value, Value::Number((-123).into()));
|
||||
|
||||
// Test floats
|
||||
let value = Config::parse_env_value("3.14")?;
|
||||
let value = Config::parse_env_value("3.41")?;
|
||||
assert!(matches!(value, Value::Number(_)));
|
||||
if let Value::Number(n) = value {
|
||||
assert_eq!(n.as_f64().unwrap(), 3.14);
|
||||
assert_eq!(n.as_f64().unwrap(), 3.41);
|
||||
}
|
||||
|
||||
let value = Config::parse_env_value("0.01")?;
|
||||
@@ -1421,7 +1421,7 @@ mod tests {
|
||||
// Test boolean environment variable
|
||||
std::env::set_var("ENABLED", "true");
|
||||
let value: bool = config.get_param("enabled")?;
|
||||
assert_eq!(value, true);
|
||||
assert!(value);
|
||||
|
||||
// Test JSON object environment variable
|
||||
std::env::set_var("CONFIG", "{\"debug\": true, \"level\": 5}");
|
||||
@@ -1431,7 +1431,7 @@ mod tests {
|
||||
level: i32,
|
||||
}
|
||||
let value: TestConfig = config.get_param("config")?;
|
||||
assert_eq!(value.debug, true);
|
||||
assert!(value.debug);
|
||||
assert_eq!(value.level, 5);
|
||||
|
||||
// Clean up
|
||||
|
||||
@@ -1,68 +1,65 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::config::signup_openrouter::PkceAuthFlow;
|
||||
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
|
||||
use sha2::{Digest, Sha256};
|
||||
use crate::config::signup_openrouter::PkceAuthFlow;
|
||||
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[test]
|
||||
fn test_pkce_flow_creation() {
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
#[test]
|
||||
fn test_pkce_flow_creation() {
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
|
||||
// Verify code_verifier is 128 characters
|
||||
assert_eq!(flow.code_verifier.len(), 128);
|
||||
// Verify code_verifier is 128 characters
|
||||
assert_eq!(flow.code_verifier.len(), 128);
|
||||
|
||||
// Verify code_challenge is base64url encoded (no padding)
|
||||
assert!(!flow.code_challenge.contains('='));
|
||||
assert!(!flow.code_challenge.contains('+'));
|
||||
assert!(!flow.code_challenge.contains('/'));
|
||||
// Verify code_challenge is base64url encoded (no padding)
|
||||
assert!(!flow.code_challenge.contains('='));
|
||||
assert!(!flow.code_challenge.contains('+'));
|
||||
assert!(!flow.code_challenge.contains('/'));
|
||||
|
||||
// Verify auth URL is properly formatted
|
||||
let auth_url = flow.get_auth_url();
|
||||
assert!(auth_url.starts_with("https://openrouter.ai/auth"));
|
||||
assert!(auth_url.contains("callback_url=http%3A%2F%2Flocalhost%3A3000"));
|
||||
assert!(auth_url.contains(&format!("code_challenge={}", flow.code_challenge)));
|
||||
assert!(auth_url.contains("code_challenge_method=S256"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_different_flows_have_different_verifiers() {
|
||||
let flow1 = PkceAuthFlow::new().expect("Failed to create PKCE flow 1");
|
||||
let flow2 = PkceAuthFlow::new().expect("Failed to create PKCE flow 2");
|
||||
|
||||
// Verify that different flows have different verifiers and challenges
|
||||
assert_ne!(flow1.code_verifier, flow2.code_verifier);
|
||||
assert_ne!(flow1.code_challenge, flow2.code_challenge);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_code_verifier_is_alphanumeric() {
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
|
||||
// Verify all characters in code_verifier are alphanumeric
|
||||
assert!(flow.code_verifier.chars().all(|c| c.is_alphanumeric()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_code_challenge_matches_verifier() {
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
|
||||
// Manually compute the expected challenge
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&flow.code_verifier);
|
||||
let hash = hasher.finalize();
|
||||
let expected_challenge = URL_SAFE_NO_PAD.encode(hash);
|
||||
|
||||
// Verify the challenge matches
|
||||
assert_eq!(flow.code_challenge, expected_challenge);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pkce_verifier_length_bounds() {
|
||||
// PKCE spec requires verifier to be 43-128 characters
|
||||
// Our implementation uses 128 characters
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
|
||||
assert!(flow.code_verifier.len() >= 43);
|
||||
assert!(flow.code_verifier.len() <= 128);
|
||||
}
|
||||
// Verify auth URL is properly formatted
|
||||
let auth_url = flow.get_auth_url();
|
||||
assert!(auth_url.starts_with("https://openrouter.ai/auth"));
|
||||
assert!(auth_url.contains("callback_url=http%3A%2F%2Flocalhost%3A3000"));
|
||||
assert!(auth_url.contains(&format!("code_challenge={}", flow.code_challenge)));
|
||||
assert!(auth_url.contains("code_challenge_method=S256"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_different_flows_have_different_verifiers() {
|
||||
let flow1 = PkceAuthFlow::new().expect("Failed to create PKCE flow 1");
|
||||
let flow2 = PkceAuthFlow::new().expect("Failed to create PKCE flow 2");
|
||||
|
||||
// Verify that different flows have different verifiers and challenges
|
||||
assert_ne!(flow1.code_verifier, flow2.code_verifier);
|
||||
assert_ne!(flow1.code_challenge, flow2.code_challenge);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_code_verifier_is_alphanumeric() {
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
|
||||
// Verify all characters in code_verifier are alphanumeric
|
||||
assert!(flow.code_verifier.chars().all(|c| c.is_alphanumeric()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_code_challenge_matches_verifier() {
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
|
||||
// Manually compute the expected challenge
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&flow.code_verifier);
|
||||
let hash = hasher.finalize();
|
||||
let expected_challenge = URL_SAFE_NO_PAD.encode(hash);
|
||||
|
||||
// Verify the challenge matches
|
||||
assert_eq!(flow.code_challenge, expected_challenge);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pkce_verifier_length_bounds() {
|
||||
// PKCE spec requires verifier to be 43-128 characters
|
||||
// Our implementation uses 128 characters
|
||||
let flow = PkceAuthFlow::new().expect("Failed to create PKCE flow");
|
||||
|
||||
assert!(flow.code_verifier.len() >= 43);
|
||||
assert!(flow.code_verifier.len() <= 128);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user