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:
Henry Park
2026-03-10 13:25:32 -07:00
committed by GitHub
co-authored by Claude Opus 4.6 Copilot
parent 24d4fbb8a7
commit 76375f2eaa
25 changed files with 314 additions and 201 deletions
+17 -10
View File
@@ -272,6 +272,7 @@ fn parse_oauth_access_token(json: &str) -> Option<String> {
#[cfg(test)]
mod tests {
use crate::config::sandbox::*;
use crate::testing::credentials::*;
// ── SandboxModeConfig defaults ──────────────────────────────────
@@ -405,9 +406,12 @@ mod tests {
#[test]
fn parse_oauth_token_valid() {
let json = r#"{"claudeAiOauth": {"accessToken": "sk-ant-oat01-fake"}}"#;
let token = parse_oauth_access_token(json);
assert_eq!(token, Some("sk-ant-oat01-fake".to_string()));
let json = format!(
r#"{{"claudeAiOauth": {{"accessToken": "{}"}}}}"#,
TEST_ANTHROPIC_OAUTH_BASIC
);
let token = parse_oauth_access_token(&json);
assert_eq!(token, Some(TEST_ANTHROPIC_OAUTH_BASIC.to_string()));
}
#[test]
@@ -434,16 +438,19 @@ mod tests {
#[test]
fn parse_oauth_token_nested_extra_fields() {
let json = r#"{
"claudeAiOauth": {
"accessToken": "sk-ant-oat01-real-token",
let json = format!(
r#"{{
"claudeAiOauth": {{
"accessToken": "{}",
"refreshToken": "rt-abc",
"expiresAt": 1700000000
}
}"#;
}}
}}"#,
TEST_ANTHROPIC_OAUTH_NESTED
);
assert_eq!(
parse_oauth_access_token(json),
Some("sk-ant-oat01-real-token".to_string())
parse_oauth_access_token(&json),
Some(TEST_ANTHROPIC_OAUTH_NESTED.to_string())
);
}