Pull request: all: use "ClientID" consistently

Closes #4242.
Updates #4244.

Squashed commit of the following:

commit 3a2296a7a70006cf6777e54ce1e2fc3559aec5be
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Feb 9 21:23:43 2022 +0300

    client: imp more

commit 3aacc8696ac694ff459fd33ba7beeeabd2569a55
Merge: b28a120f 2a5b5f19
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Feb 9 21:21:59 2022 +0300

    Merge branch 'master' into 4244-imp-i18n

commit b28a120fe9aa68507b173717059b7b259097d6a4
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Feb 9 14:49:49 2022 +0300

    client: imp texts more

commit c1fa6ca336f2d5bdcc67836f348be4843a0a8f79
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Feb 8 21:12:15 2022 +0300

    all: use "ClientID" consistently
This commit is contained in:
Ainar Garipov
2022-02-10 15:42:59 +03:00
parent 2a5b5f1927
commit f53f48cc33
21 changed files with 142 additions and 143 deletions

View File

@@ -119,8 +119,8 @@ func (a *accessCtx) allowlistMode() (ok bool) {
func (a *accessCtx) isBlockedClientID(id string) (ok bool) {
allowlistMode := a.allowlistMode()
if id == "" {
// In allowlist mode, consider requests without client IDs
// blocked by default.
// In allowlist mode, consider requests without ClientIDs blocked by
// default.
return allowlistMode
}

View File

@@ -12,12 +12,12 @@ import (
"github.com/lucas-clemente/quic-go"
)
// ValidateClientID returns an error if clientID is not a valid client ID.
func ValidateClientID(clientID string) (err error) {
err = netutil.ValidateDomainNameLabel(clientID)
// ValidateClientID returns an error if id is not a valid ClientID.
func ValidateClientID(id string) (err error) {
err = netutil.ValidateDomainNameLabel(id)
if err != nil {
// Replace the domain name label wrapper with our own.
return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err))
return fmt.Errorf("invalid clientid %q: %w", id, errors.Unwrap(err))
}
return nil
@@ -33,7 +33,7 @@ func hasLabelSuffix(s, suffix string) (ok bool) {
return strings.HasSuffix(s, suffix) && s[len(s)-len(suffix)-1] == '.'
}
// clientIDFromClientServerName extracts and validates a client ID. hostSrvName
// clientIDFromClientServerName extracts and validates a ClientID. hostSrvName
// is the server name of the host. cliSrvName is the server name as sent by the
// client. When strict is true, and client and host server name don't match,
// clientIDFromClientServerName will return an error.
@@ -86,22 +86,22 @@ func clientIDFromDNSContextHTTPS(pctx *proxy.DNSContext) (clientID string, err e
}
if len(parts) == 0 || parts[0] != "dns-query" {
return "", fmt.Errorf("client id check: invalid path %q", origPath)
return "", fmt.Errorf("clientid check: invalid path %q", origPath)
}
switch len(parts) {
case 1:
// Just /dns-query, no client ID.
// Just /dns-query, no ClientID.
return "", nil
case 2:
clientID = parts[1]
default:
return "", fmt.Errorf("client id check: invalid path %q: extra parts", origPath)
return "", fmt.Errorf("clientid check: invalid path %q: extra parts", origPath)
}
err = ValidateClientID(clientID)
if err != nil {
return "", fmt.Errorf("client id check: %w", err)
return "", fmt.Errorf("clientid check: %w", err)
}
return clientID, nil
@@ -166,7 +166,7 @@ func (s *Server) clientIDFromDNSContext(pctx *proxy.DNSContext) (clientID string
s.conf.StrictSNICheck,
)
if err != nil {
return "", fmt.Errorf("client id check: %w", err)
return "", fmt.Errorf("clientid check: %w", err)
}
return clientID, nil

View File

@@ -65,7 +65,7 @@ func TestServer_clientIDFromDNSContext(t *testing.T) {
wantErrMsg: "",
strictSNI: false,
}, {
name: "tls_no_client_id",
name: "tls_no_clientid",
proto: proxy.ProtoTLS,
hostSrvName: "example.com",
cliSrvName: "example.com",
@@ -78,7 +78,7 @@ func TestServer_clientIDFromDNSContext(t *testing.T) {
hostSrvName: "example.com",
cliSrvName: "",
wantClientID: "",
wantErrMsg: `client id check: client server name "" ` +
wantErrMsg: `clientid check: client server name "" ` +
`doesn't match host server name "example.com"`,
strictSNI: true,
}, {
@@ -90,7 +90,7 @@ func TestServer_clientIDFromDNSContext(t *testing.T) {
wantErrMsg: "",
strictSNI: false,
}, {
name: "tls_client_id",
name: "tls_clientid",
proto: proxy.ProtoTLS,
hostSrvName: "example.com",
cliSrvName: "cli.example.com",
@@ -98,36 +98,36 @@ func TestServer_clientIDFromDNSContext(t *testing.T) {
wantErrMsg: "",
strictSNI: true,
}, {
name: "tls_client_id_hostname_error",
name: "tls_clientid_hostname_error",
proto: proxy.ProtoTLS,
hostSrvName: "example.com",
cliSrvName: "cli.example.net",
wantClientID: "",
wantErrMsg: `client id check: client server name "cli.example.net" ` +
wantErrMsg: `clientid check: client server name "cli.example.net" ` +
`doesn't match host server name "example.com"`,
strictSNI: true,
}, {
name: "tls_invalid_client_id",
name: "tls_invalid_clientid",
proto: proxy.ProtoTLS,
hostSrvName: "example.com",
cliSrvName: "!!!.example.com",
wantClientID: "",
wantErrMsg: `client id check: invalid client id "!!!": ` +
wantErrMsg: `clientid check: invalid clientid "!!!": ` +
`bad domain name label rune '!'`,
strictSNI: true,
}, {
name: "tls_client_id_too_long",
name: "tls_clientid_too_long",
proto: proxy.ProtoTLS,
hostSrvName: "example.com",
cliSrvName: `abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmno` +
`pqrstuvwxyz0123456789.example.com`,
wantClientID: "",
wantErrMsg: `client id check: invalid client id "abcdefghijklmno` +
wantErrMsg: `clientid check: invalid clientid "abcdefghijklmno` +
`pqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789": ` +
`domain name label is too long: got 72, max 63`,
strictSNI: true,
}, {
name: "quic_client_id",
name: "quic_clientid",
proto: proxy.ProtoQUIC,
hostSrvName: "example.com",
cliSrvName: "cli.example.com",
@@ -135,12 +135,12 @@ func TestServer_clientIDFromDNSContext(t *testing.T) {
wantErrMsg: "",
strictSNI: true,
}, {
name: "tls_client_id_issue3437",
name: "tls_clientid_issue3437",
proto: proxy.ProtoTLS,
hostSrvName: "example.com",
cliSrvName: "cli.myexample.com",
wantClientID: "",
wantErrMsg: `client id check: client server name "cli.myexample.com" ` +
wantErrMsg: `clientid check: client server name "cli.myexample.com" ` +
`doesn't match host server name "example.com"`,
strictSNI: true,
}}
@@ -191,22 +191,22 @@ func TestClientIDFromDNSContextHTTPS(t *testing.T) {
wantClientID string
wantErrMsg string
}{{
name: "no_client_id",
name: "no_clientid",
path: "/dns-query",
wantClientID: "",
wantErrMsg: "",
}, {
name: "no_client_id_slash",
name: "no_clientid_slash",
path: "/dns-query/",
wantClientID: "",
wantErrMsg: "",
}, {
name: "client_id",
name: "clientid",
path: "/dns-query/cli",
wantClientID: "cli",
wantErrMsg: "",
}, {
name: "client_id_slash",
name: "clientid_slash",
path: "/dns-query/cli/",
wantClientID: "cli",
wantErrMsg: "",
@@ -214,18 +214,17 @@ func TestClientIDFromDNSContextHTTPS(t *testing.T) {
name: "bad_url",
path: "/foo",
wantClientID: "",
wantErrMsg: `client id check: invalid path "/foo"`,
wantErrMsg: `clientid check: invalid path "/foo"`,
}, {
name: "extra",
path: "/dns-query/cli/foo",
wantClientID: "",
wantErrMsg: `client id check: invalid path "/dns-query/cli/foo": extra parts`,
wantErrMsg: `clientid check: invalid path "/dns-query/cli/foo": extra parts`,
}, {
name: "invalid_client_id",
name: "invalid_clientid",
path: "/dns-query/!!!",
wantClientID: "",
wantErrMsg: `client id check: invalid client id "!!!": ` +
`bad domain name label rune '!'`,
wantErrMsg: `clientid check: invalid clientid "!!!": bad domain name label rune '!'`,
}}
for _, tc := range testCases {

View File

@@ -150,8 +150,8 @@ type TLSConfig struct {
CertificateChainData []byte `yaml:"-" json:"-"`
PrivateKeyData []byte `yaml:"-" json:"-"`
// ServerName is the hostname of the server. Currently, it is only
// being used for client ID checking.
// ServerName is the hostname of the server. Currently, it is only being
// used for ClientID checking.
ServerName string `yaml:"-" json:"-"`
cert tls.Certificate

View File

@@ -35,7 +35,7 @@ type dnsContext struct {
// err is the error returned from a processing function.
err error
// clientID is the clientID from DoH, DoQ, or DoT, if provided.
// clientID is the ClientID from DoH, DoQ, or DoT, if provided.
clientID string
// origQuestion is the question received from the client. It is set
@@ -546,7 +546,7 @@ func (s *Server) processUpstream(dctx *dnsContext) (rc resultCode) {
}
if pctx.Addr != nil && s.conf.GetCustomUpstreamByClient != nil {
// Use the clientID first, since it has a higher priority.
// Use the ClientID first, since it has a higher priority.
id := stringutil.Coalesce(dctx.clientID, ipStringFromAddr(pctx.Addr))
upsConf, err := s.conf.GetCustomUpstreamByClient(id)
if err != nil {

View File

@@ -28,7 +28,7 @@ import (
// DefaultTimeout is the default upstream timeout
const DefaultTimeout = 10 * time.Second
// defaultClientIDCacheCount is the default count of items in the LRU client ID
// defaultClientIDCacheCount is the default count of items in the LRU ClientID
// cache. The assumption here is that there won't be more than this many
// requests between the BeforeRequestHandler stage and the actual processing.
const defaultClientIDCacheCount = 1024
@@ -88,8 +88,8 @@ type Server struct {
tableIPToHost *netutil.IPMap
tableIPToHostLock sync.Mutex
// clientIDCache is a temporary storage for clientIDs that were
// extracted during the BeforeRequestHandler stage.
// clientIDCache is a temporary storage for ClientIDs that were extracted
// during the BeforeRequestHandler stage.
clientIDCache cache.Cache
// DNS proxy instance for internal usage

View File

@@ -66,7 +66,7 @@ func TestProcessQueryLogsAndStats(t *testing.T) {
reason: filtering.NotFilteredNotFound,
wantStatResult: stats.RNotFiltered,
}, {
name: "success_tls_client_id",
name: "success_tls_clientid",
proto: proxy.ProtoTLS,
addr: &net.TCPAddr{IP: net.IP{1, 2, 3, 4}, Port: 1234},
clientID: "cli42",

View File

@@ -532,7 +532,7 @@ func (clients *clientsContainer) check(c *Client) (err error) {
} else if err = dnsforward.ValidateClientID(id); err == nil {
c.IDs[i] = id
} else {
return fmt.Errorf("invalid client id at index %d: %q", i, id)
return fmt.Errorf("invalid clientid at index %d: %q", i, id)
}
}

View File

@@ -318,7 +318,7 @@ func applyAdditionalFiltering(clientAddr net.IP, clientID string, setts *filteri
}
}
log.Debug("using settings for client %s with ip %s and id %q", c.Name, clientAddr, clientID)
log.Debug("using settings for client %s with ip %s and clientid %q", c.Name, clientAddr, clientID)
if c.UseOwnBlockedServices {
Context.dnsFilter.ApplyBlockedServices(setts, c.BlockedServices, false)

View File

@@ -8,7 +8,7 @@ import (
"github.com/AdguardTeam/golibs/log"
)
// client finds the client info, if any, by its client ID and IP address,
// client finds the client info, if any, by its ClientID and IP address,
// optionally checking the provided cache. It will use the IP address
// regardless of if the IP anonymization is enabled now, because the
// anonymization could have been disabled in the past, and client will try to
@@ -57,7 +57,7 @@ func (l *queryLog) searchMemory(params *searchParams, cache clientCache) (entrie
e.client, err = l.client(e.ClientID, e.IP.String(), cache)
if err != nil {
msg := "querylog: enriching memory record at time %s" +
" for client %q (client id %q): %s"
" for client %q (clientid %q): %s"
log.Error(msg, e.Time, e.IP, e.ClientID, err)
// Go on and try to match anyway.
@@ -216,8 +216,8 @@ func (f quickMatchClientFinder) findClient(clientID, ip string) (c *Client) {
var err error
c, err = f.client(clientID, ip, f.cache)
if err != nil {
log.Error("querylog: enriching file record for quick search:"+
" for client %q (client id %q): %s",
log.Error(
"querylog: enriching file record for quick search: for client %q (clientid %q): %s",
ip,
clientID,
err,
@@ -259,8 +259,7 @@ func (l *queryLog) readNextEntry(
e.client, err = l.client(e.ClientID, e.IP.String(), cache)
if err != nil {
log.Error(
"querylog: enriching file record at time %s"+
" for client %q (client id %q): %s",
"querylog: enriching file record at time %s for client %q (clientid %q): %s",
e.Time,
e.IP,
e.ClientID,