Release 3.8.0.2: app.zip updates, lock hygiene, secret-safe getState.
This commit is contained in:
@@ -40,6 +40,29 @@ func RedactProfileList(in []ProfileInfo) []ProfileInfo {
|
||||
return out
|
||||
}
|
||||
|
||||
func RedactProxyURI(proxy string) string {
|
||||
proxy = strings.TrimSpace(proxy)
|
||||
if proxy == "" {
|
||||
return ""
|
||||
}
|
||||
lower := strings.ToLower(proxy)
|
||||
if strings.Contains(lower, "[interface]") || strings.Contains(lower, "privatekey") {
|
||||
return "[конфиг скрыт — откройте редактор профиля]"
|
||||
}
|
||||
if i := strings.Index(proxy, "://"); i >= 0 {
|
||||
scheme := proxy[:i+3]
|
||||
rest := proxy[i+3:]
|
||||
if at := strings.LastIndex(rest, "@"); at >= 0 {
|
||||
return scheme + "***@" + rest[at+1:]
|
||||
}
|
||||
return scheme + rest
|
||||
}
|
||||
if at := strings.LastIndex(proxy, "@"); at >= 0 {
|
||||
return "***@" + proxy[at+1:]
|
||||
}
|
||||
return proxyHost(proxy)
|
||||
}
|
||||
|
||||
func proxyHost(proxy string) string {
|
||||
proxy = strings.TrimSpace(proxy)
|
||||
if proxy == "" {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRedactProxyURI(t *testing.T) {
|
||||
got := RedactProxyURI("https://user:pass@example.com:443/?x=1")
|
||||
if got != "https://***@example.com:443/?x=1" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
if RedactProxyURI("") != "" {
|
||||
t.Fatal("empty")
|
||||
}
|
||||
r := RedactProxyURI("[Interface]\nPrivateKey = abc\n")
|
||||
if !strings.Contains(r, "скрыт") {
|
||||
t.Fatalf("awg redact: %q", r)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user