1 line
11 KiB
JSON
1 line
11 KiB
JSON
{"repo": "bobobo0o/nf1", "files": {"api/utils_test.go": {"03693a38b56ef5b7e4254794e4e02b055531e037": {"t": 1785746096.8204288, "n": 5030, "h": "86c9d721c665c725", "c": "package api\n\nimport (\n\t\"testing\"\n)\n\nfunc TestMaskSensitiveString(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\tinput string\n\t\texpected string\n\t}{\n\t\t{\n\t\t\tname: \"Empty string\",\n\t\t\tinput: \"\",\n\t\t\texpected: \"\",\n\t\t},\n\t\t{\n\t\t\tname: \"Short string (8 characters or less)\",\n\t\t\tinput: \"short\",\n\t\t\texpected: \"****\",\n\t\t},\n\t\t{\n\t\t\tname: \"Normal API key\",\n\t\t\tinput: \"sk-1234567890abcdefghijklmnopqrstuvwxyz\",\n\t\t\texpected: \"sk-1****wxyz\",\n\t\t},\n\t\t{\n\t\t\tname: \"Normal private key\",\n\t\t\tinput: \"0x1234567890abcdef1234567890abcdef12345678\",\n\t\t\texpected: \"0x12****5678\",\n\t\t},\n\t\t{\n\t\t\tname: \"Exactly 9 characters\",\n\t\t\tinput: \"123456789\",\n\t\t\texpected: \"1234****6789\",\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tresult := MaskSensitiveString(tt.input)\n\t\t\tif result != tt.expected {\n\t\t\t\tt.Errorf(\"MaskSensitiveString(%q) = %q, want %q\", tt.input, result, tt.expected)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestSanitizeModelConfigForLog(t *testing.T) {\n\tmodels := map[string]struct {\n\t\tEnabled bool `json:\"enabled\"`\n\t\tAPIKey string `json:\"api_key\"`\n\t\tCustomAPIURL string `json:\"custom_api_url\"`\n\t\tCustomModelName string `json:\"custom_model_name\"`\n\t}{\n\t\t\"deepseek\": {\n\t\t\tEnabled: true,\n\t\t\tAPIKey: \"sk-1234567890abcdefghijklmnopqrstuvwxyz\",\n\t\t\tCustomAPIURL: \"https://api.deepseek.com\",\n\t\t\tCustomModelName: \"deepseek-chat\",\n\t\t},\n\t}\n\n\tresult := SanitizeModelConfigForLog(models)\n\n\tdeepseekConfig, ok := result[\"deepseek\"].(map[string]interface{})\n\tif !ok {\n\t\tt.Fatal(\"deepseek config not found or wrong type\")\n\t}\n\n\tif deepseekConfig[\"enabled\"] != true {\n\t\tt.Errorf(\"expected enabled=true, got %v\", deepseekConfig[\"enabled\"])\n\t}\n\n\tmaskedKey, ok := deepseekConfig[\"api_key\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"api_key not found or wrong type\")\n\t}\n\n\tif maskedKey != \"sk-1****wxyz\" {\n\t\tt.Errorf(\"expected masked api_key='sk-1****wxyz', got %q\", maskedKey)\n\t}\n\n\tif deepseekConfig[\"custom_api_url\"] != \"https://api.deepseek.com\" {\n\t\tt.Errorf(\"custom_api_url should not be masked\")\n\t}\n}\n\nfunc TestSanitizeExchangeConfigForLog(t *testing.T) {\n\texchanges := map[string]struct {\n\t\tEnabled bool `json:\"enabled\"`\n\t\tAPIKey string `json:\"api_key\"`\n\t\tSecretKey string `json:\"secret_key\"`\n\t\tTestnet bool `json:\"testnet\"`\n\t\tHyperliquidWalletAddr string `json:\"hyperliquid_wallet_addr\"`\n\t\tAsterUser string `json:\"aster_user\"`\n\t\tAsterSigner string `json:\"aster_signer\"`\n\t\tAsterPrivateKey string `json:\"aster_private_key\"`\n\t\tLighterWalletAddr string `json:\"lighter_wallet_addr\"`\n\t\tLighterPrivateKey string `json:\"lighter_private_key\"`\n\t}{\n\t\t\"binance\": {\n\t\t\tEnabled: true,\n\t\t\tAPIKey: \"binance_api_key_1234567890abcdef\",\n\t\t\tSecretKey: \"binance_secret_key_1234567890abcdef\",\n\t\t\tTestnet: false,\n\t\t\tLighterWalletAddr: \"\",\n\t\t\tLighterPrivateKey: \"\",\n\t\t},\n\t\t\"hyperliquid\": {\n\t\t\tEnabled: true,\n\t\t\tHyperliquidWalletAddr: \"0x1234567890abcdef1234567890abcdef12345678\",\n\t\t\tTestnet: false,\n\t\t\tLighterWalletAddr: \"\",\n\t\t\tLighterPrivateKey: \"\",\n\t\t},\n\t}\n\n\tresult := SanitizeExchangeConfigForLog(exchanges)\n\n\t// Check Binance configuration\n\tbinanceConfig, ok := result[\"binance\"].(map[string]interface{})\n\tif !ok {\n\t\tt.Fatal(\"binance config not found or wrong type\")\n\t}\n\n\tmaskedAPIKey, ok := binanceConfig[\"api_key\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"binance api_key not found or wrong type\")\n\t}\n\n\tif maskedAPIKey != \"bina****cdef\" {\n\t\tt.Errorf(\"expected masked api_key='bina****cdef', got %q\", maskedAPIKey)\n\t}\n\n\tmaskedSecretKey, ok := binanceConfig[\"secret_key\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"binance secret_key not found or wrong type\")\n\t}\n\n\tif maskedSecretKey != \"bina****cdef\" {\n\t\tt.Errorf(\"expected masked secret_key='bina****cdef', got %q\", maskedSecretKey)\n\t}\n\n\t// Check Hyperliquid configuration\n\thlConfig, ok := result[\"hyperliquid\"].(map[string]interface{})\n\tif !ok {\n\t\tt.Fatal(\"hyperliquid config not found or wrong type\")\n\t}\n\n\twalletAddr, ok := hlConfig[\"hyperliquid_wallet_addr\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"hyperliquid_wallet_addr not found or wrong type\")\n\t}\n\n\t// Wallet address should not be masked\n\tif walletAddr != \"0x1234567890abcdef1234567890abcdef12345678\" {\n\t\tt.Errorf(\"wallet address should not be masked, got %q\", walletAddr)\n\t}\n}\n\nfunc TestMaskEmail(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\tinput string\n\t\texpected string\n\t}{\n\t\t{\n\t\t\tname: \"Empty email\",\n\t\t\tinput: \"\",\n\t\t\texpected: \"\",\n\t\t},\n\t\t{\n\t\t\tname: \"Invalid format\",\n\t\t\tinput: \"notanemail\",\n\t\t\texpected: \"****\",\n\t\t},\n\t\t{\n\t\t\tname: \"Normal email\",\n\t\t\tinput: \"user@example.com\",\n\t\t\texpected: \"us****@example.com\",\n\t\t},\n\t\t{\n\t\t\tname: \"Short username\",\n\t\t\tinput: \"a@example.com\",\n\t\t\texpected: \"**@example.com\",\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tresult := MaskEmail(tt.input)\n\t\t\tif result != tt.expected {\n\t\t\t\tt.Errorf(\"MaskEmail(%q) = %q, want %q\", tt.input, result, tt.expected)\n\t\t\t}\n\t\t})\n\t}\n}\n"}, "cc6e0832bc6f2c20719efdbaffc31b8d9cd6e087": {"t": 1785759834.2730198, "n": 5030, "h": "86c9d721c665c725", "c": "package api\n\nimport (\n\t\"testing\"\n)\n\nfunc TestMaskSensitiveString(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\tinput string\n\t\texpected string\n\t}{\n\t\t{\n\t\t\tname: \"Empty string\",\n\t\t\tinput: \"\",\n\t\t\texpected: \"\",\n\t\t},\n\t\t{\n\t\t\tname: \"Short string (8 characters or less)\",\n\t\t\tinput: \"short\",\n\t\t\texpected: \"****\",\n\t\t},\n\t\t{\n\t\t\tname: \"Normal API key\",\n\t\t\tinput: \"sk-1234567890abcdefghijklmnopqrstuvwxyz\",\n\t\t\texpected: \"sk-1****wxyz\",\n\t\t},\n\t\t{\n\t\t\tname: \"Normal private key\",\n\t\t\tinput: \"0x1234567890abcdef1234567890abcdef12345678\",\n\t\t\texpected: \"0x12****5678\",\n\t\t},\n\t\t{\n\t\t\tname: \"Exactly 9 characters\",\n\t\t\tinput: \"123456789\",\n\t\t\texpected: \"1234****6789\",\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tresult := MaskSensitiveString(tt.input)\n\t\t\tif result != tt.expected {\n\t\t\t\tt.Errorf(\"MaskSensitiveString(%q) = %q, want %q\", tt.input, result, tt.expected)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestSanitizeModelConfigForLog(t *testing.T) {\n\tmodels := map[string]struct {\n\t\tEnabled bool `json:\"enabled\"`\n\t\tAPIKey string `json:\"api_key\"`\n\t\tCustomAPIURL string `json:\"custom_api_url\"`\n\t\tCustomModelName string `json:\"custom_model_name\"`\n\t}{\n\t\t\"deepseek\": {\n\t\t\tEnabled: true,\n\t\t\tAPIKey: \"sk-1234567890abcdefghijklmnopqrstuvwxyz\",\n\t\t\tCustomAPIURL: \"https://api.deepseek.com\",\n\t\t\tCustomModelName: \"deepseek-chat\",\n\t\t},\n\t}\n\n\tresult := SanitizeModelConfigForLog(models)\n\n\tdeepseekConfig, ok := result[\"deepseek\"].(map[string]interface{})\n\tif !ok {\n\t\tt.Fatal(\"deepseek config not found or wrong type\")\n\t}\n\n\tif deepseekConfig[\"enabled\"] != true {\n\t\tt.Errorf(\"expected enabled=true, got %v\", deepseekConfig[\"enabled\"])\n\t}\n\n\tmaskedKey, ok := deepseekConfig[\"api_key\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"api_key not found or wrong type\")\n\t}\n\n\tif maskedKey != \"sk-1****wxyz\" {\n\t\tt.Errorf(\"expected masked api_key='sk-1****wxyz', got %q\", maskedKey)\n\t}\n\n\tif deepseekConfig[\"custom_api_url\"] != \"https://api.deepseek.com\" {\n\t\tt.Errorf(\"custom_api_url should not be masked\")\n\t}\n}\n\nfunc TestSanitizeExchangeConfigForLog(t *testing.T) {\n\texchanges := map[string]struct {\n\t\tEnabled bool `json:\"enabled\"`\n\t\tAPIKey string `json:\"api_key\"`\n\t\tSecretKey string `json:\"secret_key\"`\n\t\tTestnet bool `json:\"testnet\"`\n\t\tHyperliquidWalletAddr string `json:\"hyperliquid_wallet_addr\"`\n\t\tAsterUser string `json:\"aster_user\"`\n\t\tAsterSigner string `json:\"aster_signer\"`\n\t\tAsterPrivateKey string `json:\"aster_private_key\"`\n\t\tLighterWalletAddr string `json:\"lighter_wallet_addr\"`\n\t\tLighterPrivateKey string `json:\"lighter_private_key\"`\n\t}{\n\t\t\"binance\": {\n\t\t\tEnabled: true,\n\t\t\tAPIKey: \"binance_api_key_1234567890abcdef\",\n\t\t\tSecretKey: \"binance_secret_key_1234567890abcdef\",\n\t\t\tTestnet: false,\n\t\t\tLighterWalletAddr: \"\",\n\t\t\tLighterPrivateKey: \"\",\n\t\t},\n\t\t\"hyperliquid\": {\n\t\t\tEnabled: true,\n\t\t\tHyperliquidWalletAddr: \"0x1234567890abcdef1234567890abcdef12345678\",\n\t\t\tTestnet: false,\n\t\t\tLighterWalletAddr: \"\",\n\t\t\tLighterPrivateKey: \"\",\n\t\t},\n\t}\n\n\tresult := SanitizeExchangeConfigForLog(exchanges)\n\n\t// Check Binance configuration\n\tbinanceConfig, ok := result[\"binance\"].(map[string]interface{})\n\tif !ok {\n\t\tt.Fatal(\"binance config not found or wrong type\")\n\t}\n\n\tmaskedAPIKey, ok := binanceConfig[\"api_key\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"binance api_key not found or wrong type\")\n\t}\n\n\tif maskedAPIKey != \"bina****cdef\" {\n\t\tt.Errorf(\"expected masked api_key='bina****cdef', got %q\", maskedAPIKey)\n\t}\n\n\tmaskedSecretKey, ok := binanceConfig[\"secret_key\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"binance secret_key not found or wrong type\")\n\t}\n\n\tif maskedSecretKey != \"bina****cdef\" {\n\t\tt.Errorf(\"expected masked secret_key='bina****cdef', got %q\", maskedSecretKey)\n\t}\n\n\t// Check Hyperliquid configuration\n\thlConfig, ok := result[\"hyperliquid\"].(map[string]interface{})\n\tif !ok {\n\t\tt.Fatal(\"hyperliquid config not found or wrong type\")\n\t}\n\n\twalletAddr, ok := hlConfig[\"hyperliquid_wallet_addr\"].(string)\n\tif !ok {\n\t\tt.Fatal(\"hyperliquid_wallet_addr not found or wrong type\")\n\t}\n\n\t// Wallet address should not be masked\n\tif walletAddr != \"0x1234567890abcdef1234567890abcdef12345678\" {\n\t\tt.Errorf(\"wallet address should not be masked, got %q\", walletAddr)\n\t}\n}\n\nfunc TestMaskEmail(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\tinput string\n\t\texpected string\n\t}{\n\t\t{\n\t\t\tname: \"Empty email\",\n\t\t\tinput: \"\",\n\t\t\texpected: \"\",\n\t\t},\n\t\t{\n\t\t\tname: \"Invalid format\",\n\t\t\tinput: \"notanemail\",\n\t\t\texpected: \"****\",\n\t\t},\n\t\t{\n\t\t\tname: \"Normal email\",\n\t\t\tinput: \"user@example.com\",\n\t\t\texpected: \"us****@example.com\",\n\t\t},\n\t\t{\n\t\t\tname: \"Short username\",\n\t\t\tinput: \"a@example.com\",\n\t\t\texpected: \"**@example.com\",\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tresult := MaskEmail(tt.input)\n\t\t\tif result != tt.expected {\n\t\t\t\tt.Errorf(\"MaskEmail(%q) = %q, want %q\", tt.input, result, tt.expected)\n\t\t\t}\n\t\t})\n\t}\n}\n"}}}} |