mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-09-01 00:59:33 +00:00
refactor: centralize test credential constants into testing::credentials (#829)
* refactor: centralize test credential constants into testing::credentials Scattered test credential strings (API keys, OAuth tokens, crypto keys, Telegram tokens, session tokens) across ~25 files made security auditing harder and created unnecessary duplication. Centralize all test-only fake credentials into a new `src/testing/credentials.rs` module with named constants and a shared `test_secrets_store()` helper. - Convert `src/testing.rs` to directory module (`src/testing/mod.rs`) - Add `src/testing/credentials.rs` with ~30 named constants - Replace hardcoded literals in 24 source files - Deduplicate `test_store()` helper (was copy-pasted in 3 files) - Leave leak_detector/shell/signature tests as-is (inline values aid readability for pattern detection tests) [skip-regression-check] Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * refactor: replace real Telegram bot token with obviously fake test stub Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Update src/testing/credentials.rs Co-authored-by: Copilot <[email protected]> * Update src/testing/credentials.rs Co-authored-by: Copilot <[email protected]> * refactor: address PR review feedback on test credentials - Fix TEST_CRYPTO_KEY doc comment ("32-byte hex" → "32-character key string") - Rename confusing "real"/"fake" Anthropic constant names and values - Change TEST_STRIPE_KEY from "sk-live" to "sk_test_fake123" to avoid scanners - Use test_secrets_store() helper in orchestrator and http tool tests - Clarify config_round_trip.rs doc comment about integration test visibility Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: Copilot <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.6
Copilot
parent
24d4fbb8a7
commit
76375f2eaa
+10
-7
@@ -627,6 +627,9 @@ pub async fn create_session_manager(config: SessionConfig) -> Arc<SessionManager
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::testing::credentials::{
|
||||
TEST_SESSION_NEARAI_ABC, TEST_SESSION_NEARAI_XYZ, TEST_SESSION_TOKEN,
|
||||
};
|
||||
use secrecy::ExposeSecret;
|
||||
use tempfile::tempdir;
|
||||
|
||||
@@ -647,28 +650,28 @@ mod tests {
|
||||
|
||||
// Save a token
|
||||
manager
|
||||
.save_session("test_token_123", Some("near"))
|
||||
.save_session(TEST_SESSION_TOKEN, Some("near"))
|
||||
.await
|
||||
.unwrap();
|
||||
manager
|
||||
.set_token(SecretString::from("test_token_123"))
|
||||
.set_token(SecretString::from(TEST_SESSION_TOKEN))
|
||||
.await;
|
||||
|
||||
// Verify it's set
|
||||
assert!(manager.has_token().await);
|
||||
let token = manager.get_token().await.unwrap();
|
||||
assert_eq!(token.expose_secret(), "test_token_123");
|
||||
assert_eq!(token.expose_secret(), TEST_SESSION_TOKEN);
|
||||
|
||||
// Create new manager and verify it loads the token
|
||||
let manager2 = SessionManager::new_async(config).await;
|
||||
assert!(manager2.has_token().await);
|
||||
let token2 = manager2.get_token().await.unwrap();
|
||||
assert_eq!(token2.expose_secret(), "test_token_123");
|
||||
assert_eq!(token2.expose_secret(), TEST_SESSION_TOKEN);
|
||||
|
||||
// Verify file contents
|
||||
let data: SessionData =
|
||||
serde_json::from_str(&std::fs::read_to_string(&session_path).unwrap()).unwrap();
|
||||
assert_eq!(data.session_token, "test_token_123");
|
||||
assert_eq!(data.session_token, TEST_SESSION_TOKEN);
|
||||
assert_eq!(data.auth_provider, Some("near".to_string()));
|
||||
}
|
||||
|
||||
@@ -689,7 +692,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_session_data_serde_roundtrip_with_auth_provider() {
|
||||
let original = SessionData {
|
||||
session_token: "sess_abc123".to_string(),
|
||||
session_token: TEST_SESSION_NEARAI_ABC.to_string(),
|
||||
created_at: Utc::now(),
|
||||
auth_provider: Some("github".to_string()),
|
||||
};
|
||||
@@ -703,7 +706,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_session_data_serde_roundtrip_without_auth_provider() {
|
||||
let original = SessionData {
|
||||
session_token: "sess_xyz789".to_string(),
|
||||
session_token: TEST_SESSION_NEARAI_XYZ.to_string(),
|
||||
created_at: Utc::now(),
|
||||
auth_provider: None,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user