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]>
This commit is contained in:
Henry Park
2026-03-09 22:16:36 -07:00
co-authored by Claude Opus 4.6
parent 3a2989d009
commit a268790b88
25 changed files with 314 additions and 177 deletions
+6 -2
View File
@@ -12,6 +12,10 @@ use tempfile::tempdir;
use ironclaw::bootstrap::{save_bootstrap_env_to, upsert_bootstrap_var_to};
/// Fake OpenAI API key for test use only. Mirrors `TEST_OPENAI_API_KEY_LONG`
/// from `crate::testing::credentials` (unavailable in integration tests).
const TEST_OPENAI_API_KEY_LONG: &str = "sk-test-key-1234567890";
/// Parse a .env file into a HashMap using dotenvy.
fn read_env_map(path: &std::path::Path) -> HashMap<String, String> {
dotenvy::from_path_iter(path)
@@ -77,7 +81,7 @@ fn bootstrap_env_round_trips_embedding_disabled() {
&[
("DATABASE_BACKEND", "libsql"),
("EMBEDDING_ENABLED", "false"),
("OPENAI_API_KEY", "sk-test-key-1234567890"),
("OPENAI_API_KEY", TEST_OPENAI_API_KEY_LONG),
("ONBOARD_COMPLETED", "true"),
],
)
@@ -92,7 +96,7 @@ fn bootstrap_env_round_trips_embedding_disabled() {
);
assert_eq!(
map.get("OPENAI_API_KEY").map(String::as_str),
Some("sk-test-key-1234567890"),
Some(TEST_OPENAI_API_KEY_LONG),
"OPENAI_API_KEY must be preserved alongside EMBEDDING_ENABLED"
);
}