docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
return "", fmt.Errorf("parsing private key: %w", err)
<mask> } <mask> <mask> _, keyType, err := parsePrivateKey(key.Bytes) <mask> if err != nil { <mask> return fmt.Errorf("parsing private key: %w", err) <mask> } <mask> <mask> if keyType == keyTypeED25519 { <mask> return errors.Error( <mask> "ED25519 keys are not supported by browsers; " + </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove return errors.Error( </s> add return "", errors.Error( </s> remove _, keyType, err := parsePrivateKey(key.Bytes) </s> add _, keyType, err = parsePrivateKey(key.Bytes) </s> remove return errors.Error("no valid keys were found") </s> add return "", errors.Error("no valid keys were found") </s> remove _, err = tls.X509KeyPair(certChain, pkey) if err != nil { err = fmt.Errorf("certificate-key pair: %w", err) status.WarningValidation = err.Error() return err </s> add _, pairErr := tls.X509KeyPair(certChain, pkey) if pairErr != nil { return fmt.Errorf("certificate-key pair: %w", pairErr) </s> remove return err </s> add return fmt.Errorf("certificate does not verify: %w", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
return "", errors.Error(
<mask> return fmt.Errorf("parsing private key: %w", err) <mask> } <mask> <mask> if keyType == keyTypeED25519 { <mask> return errors.Error( <mask> "ED25519 keys are not supported by browsers; " + <mask> "did you mean to use X25519 for key exchange?", <mask> ) <mask> } <mask> </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove return fmt.Errorf("parsing private key: %w", err) </s> add return "", fmt.Errorf("parsing private key: %w", err) </s> remove status.ValidKey = true status.KeyType = keyType return nil </s> add return keyType, nil </s> remove _, keyType, err := parsePrivateKey(key.Bytes) </s> add _, keyType, err = parsePrivateKey(key.Bytes) </s> remove return errors.Error("no valid keys were found") </s> add return "", errors.Error("no valid keys were found")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
return keyType, nil
<mask> "did you mean to use X25519 for key exchange?", <mask> ) <mask> } <mask> <mask> status.ValidKey = true <mask> status.KeyType = keyType <mask> <mask> return nil <mask> } <mask> <mask> // validateCertificates processes certificate data and its private key. All <mask> // parameters are optional. status must not be nil. The returned error is also <mask> // set in status.WarningValidation. </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove // validateCertificates processes certificate data and its private key. All // parameters are optional. status must not be nil. The returned error is also // set in status.WarningValidation. </s> add // validateCertificates processes certificate data and its private key. status // must not be nil, since it's used to accumulate the validation results. Other // parameters are optional. </s> remove return errors.Error( </s> add return "", errors.Error( </s> remove // validatePKey validates the private key and sets data in status. The returned // error is also set in status.WarningValidation. func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) { defer func() { if err != nil { status.WarningValidation = err.Error() } }() </s> add // validatePKey validates the private key, returning its type. It returns an // empty string if error occurs. func validatePKey(pkey []byte) (keyType string, err error) { </s> remove // validateCertChain validates the certificate chain and sets data in status. // The returned error is also set in status.WarningValidation. func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) { defer func() { if err != nil { status.WarningValidation = err.Error() } }() log.Debug("tls: got certificate chain: %d bytes", len(certChain)) var certs []*pem.Block pemblock := certChain for { var decoded *pem.Block decoded, pemblock = pem.Decode(pemblock) if decoded == nil { break } </s> add // validateCertChain verifies certs using the first as the main one and others // as intermediate. srvName stands for the expected DNS name. func validateCertChain(certs []*x509.Certificate, srvName string) (err error) { main, others := certs[0], certs[1:]
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
// validateCertificates processes certificate data and its private key. status // must not be nil, since it's used to accumulate the validation results. Other // parameters are optional.
<mask> <mask> return nil <mask> } <mask> <mask> // validateCertificates processes certificate data and its private key. All <mask> // parameters are optional. status must not be nil. The returned error is also <mask> // set in status.WarningValidation. <mask> func validateCertificates( <mask> status *tlsConfigStatus, <mask> certChain []byte, <mask> pkey []byte, <mask> serverName string, </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove status.ValidKey = true status.KeyType = keyType return nil </s> add return keyType, nil </s> remove // validatePKey validates the private key and sets data in status. The returned // error is also set in status.WarningValidation. func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) { defer func() { if err != nil { status.WarningValidation = err.Error() } }() </s> add // validatePKey validates the private key, returning its type. It returns an // empty string if error occurs. func validatePKey(pkey []byte) (keyType string, err error) { </s> remove // validateCertChain validates the certificate chain and sets data in status. // The returned error is also set in status.WarningValidation. func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) { defer func() { if err != nil { status.WarningValidation = err.Error() } }() log.Debug("tls: got certificate chain: %d bytes", len(certChain)) var certs []*pem.Block pemblock := certChain for { var decoded *pem.Block decoded, pemblock = pem.Decode(pemblock) if decoded == nil { break } </s> add // validateCertChain verifies certs using the first as the main one and others // as intermediate. srvName stands for the expected DNS name. func validateCertChain(certs []*x509.Certificate, srvName string) (err error) { main, others := certs[0], certs[1:] </s> remove defer func() { // Capitalize the warning for the UI. Assume that warnings are all // ASCII-only. // // TODO(a.garipov): Figure out a better way to do this. Perhaps a // custom string or error type. if w := status.WarningValidation; w != "" { status.WarningValidation = strings.ToUpper(w[:1]) + w[1:] } }() </s> add </s> remove pool := x509.NewCertPool() for _, cert := range parsedCerts[1:] { log.Info("tls: got an intermediate cert") pool.AddCert(cert) } </s> add // parseCertChain parses the certificate chain from raw data, and returns it. // If ok is true, the returned error, if any, is not critical. func parseCertChain(chain []byte) (parsedCerts []*x509.Certificate, ok bool, err error) { log.Debug("tls: got certificate chain: %d bytes", len(chain))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
<mask> certChain []byte, <mask> pkey []byte, <mask> serverName string, <mask> ) (err error) { <mask> defer func() { <mask> // Capitalize the warning for the UI. Assume that warnings are all <mask> // ASCII-only. <mask> // <mask> // TODO(a.garipov): Figure out a better way to do this. Perhaps a <mask> // custom string or error type. <mask> if w := status.WarningValidation; w != "" { <mask> status.WarningValidation = strings.ToUpper(w[:1]) + w[1:] <mask> } <mask> }() <mask> <mask> // Check only the public certificate separately from the key. <mask> if len(certChain) > 0 { <mask> err = validateCertChain(status, certChain, serverName) <mask> if err != nil { <mask> return err </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove err = validateCertChain(status, certChain, serverName) if err != nil { </s> add var certs []*x509.Certificate certs, status.ValidCert, err = parseCertChain(certChain) if !status.ValidCert { // Don't wrap the error, since it's informative enough as is. </s> remove // validatePKey validates the private key and sets data in status. The returned // error is also set in status.WarningValidation. func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) { defer func() { if err != nil { status.WarningValidation = err.Error() } }() </s> add // validatePKey validates the private key, returning its type. It returns an // empty string if error occurs. func validatePKey(pkey []byte) (keyType string, err error) { </s> remove // validateCertChain validates the certificate chain and sets data in status. // The returned error is also set in status.WarningValidation. func validateCertChain(status *tlsConfigStatus, certChain []byte, serverName string) (err error) { defer func() { if err != nil { status.WarningValidation = err.Error() } }() log.Debug("tls: got certificate chain: %d bytes", len(certChain)) var certs []*pem.Block pemblock := certChain for { var decoded *pem.Block decoded, pemblock = pem.Decode(pemblock) if decoded == nil { break } </s> add // validateCertChain verifies certs using the first as the main one and others // as intermediate. srvName stands for the expected DNS name. func validateCertChain(certs []*x509.Certificate, srvName string) (err error) { main, others := certs[0], certs[1:]
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
var certs []*x509.Certificate certs, status.ValidCert, err = parseCertChain(certChain) if !status.ValidCert { // Don't wrap the error, since it's informative enough as is.
<mask> }() <mask> <mask> // Check only the public certificate separately from the key. <mask> if len(certChain) > 0 { <mask> err = validateCertChain(status, certChain, serverName) <mask> if err != nil { <mask> return err <mask> } <mask> } <mask> <mask> // Validate the private key by parsing it. </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove defer func() { // Capitalize the warning for the UI. Assume that warnings are all // ASCII-only. // // TODO(a.garipov): Figure out a better way to do this. Perhaps a // custom string or error type. if w := status.WarningValidation; w != "" { status.WarningValidation = strings.ToUpper(w[:1]) + w[1:] } }() </s> add </s> remove err = validatePKey(status, pkey) if err != nil { return err </s> add var keyErr error status.KeyType, keyErr = validatePKey(pkey) if keyErr != nil { // Don't wrap the error, since it's informative enough as is. return keyErr </s> remove _, err = tls.X509KeyPair(certChain, pkey) if err != nil { err = fmt.Errorf("certificate-key pair: %w", err) status.WarningValidation = err.Error() return err </s> add _, pairErr := tls.X509KeyPair(certChain, pkey) if pairErr != nil { return fmt.Errorf("certificate-key pair: %w", pairErr)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
mainCert := certs[0] status.Subject = mainCert.Subject.String() status.Issuer = mainCert.Issuer.String() status.NotAfter = mainCert.NotAfter status.NotBefore = mainCert.NotBefore status.DNSNames = mainCert.DNSNames if chainErr := validateCertChain(certs, serverName); chainErr != nil { // Let self-signed certs through and don't return this error to set // its message into the status.WarningValidation afterwards. err = chainErr } else { status.ValidChain = true }
<mask> // Don't wrap the error, since it's informative enough as is. <mask> return err <mask> } <mask> } <mask> <mask> // Validate the private key by parsing it. <mask> if len(pkey) > 0 { <mask> var keyErr error </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove err = validatePKey(status, pkey) if err != nil { return err </s> add var keyErr error status.KeyType, keyErr = validatePKey(pkey) if keyErr != nil { // Don't wrap the error, since it's informative enough as is. return keyErr </s> remove err = validateCertChain(status, certChain, serverName) if err != nil { </s> add var certs []*x509.Certificate certs, status.ValidCert, err = parseCertChain(certChain) if !status.ValidCert { // Don't wrap the error, since it's informative enough as is. </s> remove // validatePKey validates the private key and sets data in status. The returned // error is also set in status.WarningValidation. func validatePKey(status *tlsConfigStatus, pkey []byte) (err error) { defer func() { if err != nil { status.WarningValidation = err.Error() } }() </s> add // validatePKey validates the private key, returning its type. It returns an // empty string if error occurs. func validatePKey(pkey []byte) (keyType string, err error) { </s> remove _, err = tls.X509KeyPair(certChain, pkey) if err != nil { err = fmt.Errorf("certificate-key pair: %w", err) status.WarningValidation = err.Error() return err </s> add _, pairErr := tls.X509KeyPair(certChain, pkey) if pairErr != nil { return fmt.Errorf("certificate-key pair: %w", pairErr)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
var keyErr error status.KeyType, keyErr = validatePKey(pkey) if keyErr != nil { // Don't wrap the error, since it's informative enough as is. return keyErr
<mask> } <mask> <mask> // Validate the private key by parsing it. <mask> if len(pkey) > 0 { <mask> err = validatePKey(status, pkey) <mask> if err != nil { <mask> return err <mask> } <mask> } <mask> <mask> // If both are set, validate together. <mask> if len(certChain) > 0 && len(pkey) > 0 { </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove _, err = tls.X509KeyPair(certChain, pkey) if err != nil { err = fmt.Errorf("certificate-key pair: %w", err) status.WarningValidation = err.Error() return err </s> add _, pairErr := tls.X509KeyPair(certChain, pkey) if pairErr != nil { return fmt.Errorf("certificate-key pair: %w", pairErr) </s> remove err = validateCertChain(status, certChain, serverName) if err != nil { </s> add var certs []*x509.Certificate certs, status.ValidCert, err = parseCertChain(certChain) if !status.ValidCert { // Don't wrap the error, since it's informative enough as is. </s> remove status.ValidCert = true </s> add return nil } // certHasIP returns true if cert has at least a single IP address either in its // DNS names or in the IP addresses section. func certHasIP(cert *x509.Certificate) (ok bool) { if len(cert.IPAddresses) > 0 { return true }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
status.ValidKey = true
<mask> return keyErr <mask> } <mask> } <mask> <mask> // If both are set, validate together. <mask> if len(certChain) > 0 && len(pkey) > 0 { <mask> _, pairErr := tls.X509KeyPair(certChain, pkey) <mask> if pairErr != nil { </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove _, err = tls.X509KeyPair(certChain, pkey) if err != nil { err = fmt.Errorf("certificate-key pair: %w", err) status.WarningValidation = err.Error() return err </s> add _, pairErr := tls.X509KeyPair(certChain, pkey) if pairErr != nil { return fmt.Errorf("certificate-key pair: %w", pairErr) </s> remove err = validatePKey(status, pkey) if err != nil { return err </s> add var keyErr error status.KeyType, keyErr = validatePKey(pkey) if keyErr != nil { // Don't wrap the error, since it's informative enough as is. return keyErr </s> remove err = validateCertChain(status, certChain, serverName) if err != nil { </s> add var certs []*x509.Certificate certs, status.ValidCert, err = parseCertChain(certChain) if !status.ValidCert { // Don't wrap the error, since it's informative enough as is. </s> remove status.ValidCert = true </s> add return nil } // certHasIP returns true if cert has at least a single IP address either in its // DNS names or in the IP addresses section. func certHasIP(cert *x509.Certificate) (ok bool) { if len(cert.IPAddresses) > 0 { return true }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
_, pairErr := tls.X509KeyPair(certChain, pkey) if pairErr != nil { return fmt.Errorf("certificate-key pair: %w", pairErr)
<mask> } <mask> <mask> // If both are set, validate together. <mask> if len(certChain) > 0 && len(pkey) > 0 { <mask> _, err = tls.X509KeyPair(certChain, pkey) <mask> if err != nil { <mask> err = fmt.Errorf("certificate-key pair: %w", err) <mask> status.WarningValidation = err.Error() <mask> <mask> return err <mask> } <mask> <mask> status.ValidPair = true <mask> } <mask> </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove err = validatePKey(status, pkey) if err != nil { return err </s> add var keyErr error status.KeyType, keyErr = validatePKey(pkey) if keyErr != nil { // Don't wrap the error, since it's informative enough as is. return keyErr </s> remove err = validateCertChain(status, certChain, serverName) if err != nil { </s> add var certs []*x509.Certificate certs, status.ValidCert, err = parseCertChain(certChain) if !status.ValidCert { // Don't wrap the error, since it's informative enough as is.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
return err
<mask> <mask> status.ValidPair = true <mask> } <mask> <mask> return nil <mask> } <mask> <mask> // Key types. <mask> const ( <mask> keyTypeECDSA = "ECDSA" </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove _, err = tls.X509KeyPair(certChain, pkey) if err != nil { err = fmt.Errorf("certificate-key pair: %w", err) status.WarningValidation = err.Error() return err </s> add _, pairErr := tls.X509KeyPair(certChain, pkey) if pairErr != nil { return fmt.Errorf("certificate-key pair: %w", pairErr) </s> remove // Let self-signed certs through and don't return this error. status.WarningValidation = fmt.Sprintf("certificate does not verify: %s", err) } else { status.ValidChain = true </s> add return nil, false, err </s> remove status.ValidKey = true status.KeyType = keyType return nil </s> add return keyType, nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls.go
"github.com/AdguardTeam/golibs/testutil"
<mask> "time" <mask> <mask> "github.com/stretchr/testify/assert" <mask> ) <mask> <mask> var testCertChainData = []byte(`-----BEGIN CERTIFICATE----- <mask> MIICKzCCAZSgAwIBAgIJAMT9kPVJdM7LMA0GCSqGSIb3DQEBCwUAMC0xFDASBgNV </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove status.ValidKey = true status.KeyType = keyType return nil </s> add return keyType, nil </s> remove pemblock := []byte(pkey) for { var decoded *pem.Block decoded, pemblock = pem.Decode(pemblock) if decoded == nil { break } </s> add for decoded, pemblock := pem.Decode([]byte(pkey)); decoded != nil; { </s> remove return errors.Error( </s> add return "", errors.Error( </s> remove opts.Intermediates = pool </s> add var certs []*pem.Block for decoded, pemblock := pem.Decode(chain); decoded != nil; { if decoded.Type == "CERTIFICATE" { certs = append(certs, decoded) } decoded, pemblock = pem.Decode(pemblock) }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls_internal_test.go
testutil.AssertErrorMsg(t, "empty certificate", err)
<mask> func TestValidateCertificates(t *testing.T) { <mask> t.Run("bad_certificate", func(t *testing.T) { <mask> status := &tlsConfigStatus{} <mask> err := validateCertificates(status, []byte("bad cert"), nil, "") <mask> assert.Error(t, err) <mask> assert.NotEmpty(t, status.WarningValidation) <mask> assert.False(t, status.ValidCert) <mask> assert.False(t, status.ValidChain) <mask> }) <mask> <mask> t.Run("bad_private_key", func(t *testing.T) { </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove assert.Error(t, err) assert.NotEmpty(t, status.WarningValidation) </s> add testutil.AssertErrorMsg(t, "no valid keys were found", err) </s> remove assert.NoError(t, err) </s> add assert.Error(t, err) </s> remove assert.NotEmpty(t, status.WarningValidation) </s> add </s> remove // Let self-signed certs through and don't return this error. status.WarningValidation = fmt.Sprintf("certificate does not verify: %s", err) } else { status.ValidChain = true </s> add return nil, false, err
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls_internal_test.go
testutil.AssertErrorMsg(t, "no valid keys were found", err)
<mask> <mask> t.Run("bad_private_key", func(t *testing.T) { <mask> status := &tlsConfigStatus{} <mask> err := validateCertificates(status, nil, []byte("bad priv key"), "") <mask> assert.Error(t, err) <mask> assert.NotEmpty(t, status.WarningValidation) <mask> assert.False(t, status.ValidKey) <mask> }) <mask> <mask> t.Run("valid", func(t *testing.T) { <mask> status := &tlsConfigStatus{} </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove assert.Error(t, err) assert.NotEmpty(t, status.WarningValidation) </s> add testutil.AssertErrorMsg(t, "empty certificate", err) </s> remove assert.NoError(t, err) </s> add assert.Error(t, err) </s> remove assert.NotEmpty(t, status.WarningValidation) </s> add </s> remove // Let self-signed certs through and don't return this error. status.WarningValidation = fmt.Sprintf("certificate does not verify: %s", err) } else { status.ValidChain = true </s> add return nil, false, err </s> remove return err </s> add return fmt.Errorf("certificate does not verify: %w", err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls_internal_test.go
assert.Error(t, err)
<mask> <mask> t.Run("valid", func(t *testing.T) { <mask> status := &tlsConfigStatus{} <mask> err := validateCertificates(status, testCertChainData, testPrivateKeyData, "") <mask> assert.NoError(t, err) <mask> <mask> notBefore := time.Date(2019, 2, 27, 9, 24, 23, 0, time.UTC) <mask> notAfter := time.Date(2046, 7, 14, 9, 24, 23, 0, time.UTC) <mask> <mask> assert.NotEmpty(t, status.WarningValidation) </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove assert.NotEmpty(t, status.WarningValidation) </s> add </s> remove assert.Error(t, err) assert.NotEmpty(t, status.WarningValidation) </s> add testutil.AssertErrorMsg(t, "no valid keys were found", err) </s> remove assert.Error(t, err) assert.NotEmpty(t, status.WarningValidation) </s> add testutil.AssertErrorMsg(t, "empty certificate", err) </s> remove return err </s> add return fmt.Errorf("certificate does not verify: %w", err) </s> remove opts := x509.VerifyOptions{ DNSName: serverName, Roots: Context.tlsRoots, </s> add for _, name := range cert.DNSNames { if _, err := netip.ParseAddr(name); err == nil { return true }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls_internal_test.go
<mask> <mask> notBefore := time.Date(2019, 2, 27, 9, 24, 23, 0, time.UTC) <mask> notAfter := time.Date(2046, 7, 14, 9, 24, 23, 0, time.UTC) <mask> <mask> assert.NotEmpty(t, status.WarningValidation) <mask> assert.True(t, status.ValidCert) <mask> assert.False(t, status.ValidChain) <mask> assert.True(t, status.ValidKey) <mask> assert.Equal(t, "RSA", status.KeyType) <mask> assert.Equal(t, "CN=AdGuard Home,O=AdGuard Ltd", status.Subject) </s> Pull request: 4898-redirect-https Merge in DNS/adguard-home from 4898-redirect-https to master Updates #4898. Updates #4927. Squashed commit of the following: commit bc41b6cae7ede0f1235e3956ab49204af1c9f38d Merge: 815e2991 ac7634da Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 13:02:23 2022 +0300 Merge branch 'master' into 4898-redirect-https commit 815e299137224fc3c7fd46924d7b936515b95d67 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Nov 1 12:58:28 2022 +0300 home: imp ip addr detection commit 9d4ecd9ab0e13ef6c19c3b923363bff43394ea4c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 17:23:41 2022 +0300 home: imp cyclo commit 86c47b68fe6e3916cec97eee5d34e3e6c18e4892 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 15:06:05 2022 +0300 all: imp text commit bcc25697b551668d1dab53a874e716fcadd83f09 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Oct 31 11:47:57 2022 +0300 home: fix test commit bb51a74cb82eeaa977821fa7314810c7b8be55cb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Oct 30 23:23:40 2022 +0300 home: imp code commit 38522330691baf8475a59ed4f40b1d45363df1e3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Oct 28 17:00:50 2022 +0300 home: imp code commit 7284f7288feb7491560f0f5d2754044c7a9f603a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:42:57 2022 +0300 all: log changes commit 540efcb013e15294b98efe581323f75ceefc8f5a Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Oct 27 19:24:21 2022 +0300 home: imp tls </s> remove assert.NoError(t, err) </s> add assert.Error(t, err) </s> remove assert.Error(t, err) assert.NotEmpty(t, status.WarningValidation) </s> add testutil.AssertErrorMsg(t, "empty certificate", err) </s> remove assert.Error(t, err) assert.NotEmpty(t, status.WarningValidation) </s> add testutil.AssertErrorMsg(t, "no valid keys were found", err) </s> remove opts := x509.VerifyOptions{ DNSName: serverName, Roots: Context.tlsRoots, </s> add for _, name := range cert.DNSNames { if _, err := netip.ParseAddr(name); err == nil { return true } </s> remove if decoded.Type == "CERTIFICATE" { certs = append(certs, decoded) } </s> add pool := x509.NewCertPool() for _, cert := range others { log.Info("tls: got an intermediate cert") pool.AddCert(cert)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5565a9e4e5e3cd54dd6d8c34e326c5f166ec401
internal/home/tls_internal_test.go
cd ./dist/
<mask> #!/bin/sh <mask> <mask> set -e -f -u -x <mask> export CHANNEL="${bamboo.channel}" <mask> ./bamboo-deploy-publisher/deploy.sh adguard-home-"$CHANNEL" <mask> 'final-tasks': <mask> - 'clean' <mask> 'requirements': <mask> - 'adg-docker': 'true' </s> Pull request: bamboo-specs: cd into dist Merge in DNS/adguard-home from fix-specs to master Squashed commit of the following: commit 4a46f6f417e3a82c3adc819dc5428125f97bd747 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 8 16:20:16 2021 +0300 bamboo-specs: cd into dist
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5f4d0ce44fe6d8b06560be6d882764905c302d4
bamboo-specs/release.yaml
cd ./dist/
<mask> - | <mask> #!/bin/sh <mask> <mask> set -e -f -u -x <mask> env\ <mask> SNAPCRAFT_CHANNEL=edge\ <mask> SNAPCRAFT_EMAIL="${bamboo.snapcraftEmail}"\ <mask> SNAPCRAFT_MACAROON="${bamboo.snapcraftMacaroonPassword}"\ <mask> SNAPCRAFT_UBUNTU_DISCHARGE="${bamboo.snapcraftUbuntuDischargePassword}"\ </s> Pull request: bamboo-specs: cd into dist Merge in DNS/adguard-home from fix-specs to master Squashed commit of the following: commit 4a46f6f417e3a82c3adc819dc5428125f97bd747 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 8 16:20:16 2021 +0300 bamboo-specs: cd into dist
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5f4d0ce44fe6d8b06560be6d882764905c302d4
bamboo-specs/release.yaml
cd ./dist/
<mask> set -e -f -u -x <mask> <mask> export CHANNEL="${bamboo.channel}" <mask> if [ "$CHANNEL" != 'release' -a "${CHANNEL}" != 'beta' ] <mask> then <mask> echo "don't publish to Github Releases for this channel" </s> Pull request: bamboo-specs: cd into dist Merge in DNS/adguard-home from fix-specs to master Squashed commit of the following: commit 4a46f6f417e3a82c3adc819dc5428125f97bd747 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 8 16:20:16 2021 +0300 bamboo-specs: cd into dist
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c5f4d0ce44fe6d8b06560be6d882764905c302d4
bamboo-specs/release.yaml
github.com/ameshkov/dnscrypt/v2 v2.2.7
<mask> github.com/AdguardTeam/dnsproxy v0.48.3 <mask> github.com/AdguardTeam/golibs v0.13.2 <mask> github.com/AdguardTeam/urlfilter v0.16.1 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/ameshkov/dnscrypt/v2 v2.2.6 <mask> github.com/digineo/go-ipset/v2 v2.2.1 <mask> github.com/dimfeld/httptreemux/v5 v5.5.0 <mask> github.com/fsnotify/fsnotify v1.6.0 <mask> github.com/go-ping/ping v1.1.0 <mask> github.com/google/go-cmp v0.5.9 </s> Pull request 1827: upd-deps Merge in DNS/adguard-home from upd-deps to master Squashed commit of the following: commit 4892dc4ed6df76d8733e6799744b095c5db1db6c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 13 18:22:10 2023 +0300 all: upd dnscrypt, skel </s> remove github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59 h1:UATfPbxkH89nm8B1SvwvfptuqPWyLd8UoqfXQRN3VR8= github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59/go.mod h1:qPWhwz6FdSmuK7W4sMyvogrez4MWdtzosdqlr0Rg3ow= </s> add github.com/ameshkov/dnscrypt/v2 v2.2.7 h1:aEitLIR8HcxVodZ79mgRcCiC0A0I5kZPBuWGFwwulAw= github.com/ameshkov/dnscrypt/v2 v2.2.7/go.mod h1:qPWhwz6FdSmuK7W4sMyvogrez4MWdtzosdqlr0Rg3ow= </s> remove // TODO(a.garipov): Remove the replace when @a.meshkov merges // https://github.com/ameshkov/dnscrypt/pull/21. replace github.com/ameshkov/dnscrypt/v2 => github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59 </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c6d4f2317e3ae19ccd13945391ba65ddcd3e2cab
go.mod
<mask> golang.org/x/sync v0.1.0 // indirect <mask> golang.org/x/text v0.9.0 // indirect <mask> golang.org/x/tools v0.8.0 // indirect <mask> ) <mask> <mask> // TODO(a.garipov): Remove the replace when @a.meshkov merges <mask> // https://github.com/ameshkov/dnscrypt/pull/21. <mask> replace github.com/ameshkov/dnscrypt/v2 => github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59 </s> Pull request 1827: upd-deps Merge in DNS/adguard-home from upd-deps to master Squashed commit of the following: commit 4892dc4ed6df76d8733e6799744b095c5db1db6c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 13 18:22:10 2023 +0300 all: upd dnscrypt, skel </s> remove github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59 h1:UATfPbxkH89nm8B1SvwvfptuqPWyLd8UoqfXQRN3VR8= github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59/go.mod h1:qPWhwz6FdSmuK7W4sMyvogrez4MWdtzosdqlr0Rg3ow= </s> add github.com/ameshkov/dnscrypt/v2 v2.2.7 h1:aEitLIR8HcxVodZ79mgRcCiC0A0I5kZPBuWGFwwulAw= github.com/ameshkov/dnscrypt/v2 v2.2.7/go.mod h1:qPWhwz6FdSmuK7W4sMyvogrez4MWdtzosdqlr0Rg3ow= </s> remove github.com/ameshkov/dnscrypt/v2 v2.2.6 </s> add github.com/ameshkov/dnscrypt/v2 v2.2.7
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c6d4f2317e3ae19ccd13945391ba65ddcd3e2cab
go.mod
github.com/ameshkov/dnscrypt/v2 v2.2.7 h1:aEitLIR8HcxVodZ79mgRcCiC0A0I5kZPBuWGFwwulAw= github.com/ameshkov/dnscrypt/v2 v2.2.7/go.mod h1:qPWhwz6FdSmuK7W4sMyvogrez4MWdtzosdqlr0Rg3ow=
<mask> github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY= <mask> github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= <mask> github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 h1:52m0LGchQBBVqJRyYYufQuIbVqRawmubW3OFGqK1ekw= <mask> github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635/go.mod h1:lmLxL+FV291OopO93Bwf9fQLQeLyt33VJRUg5VJ30us= <mask> github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59 h1:UATfPbxkH89nm8B1SvwvfptuqPWyLd8UoqfXQRN3VR8= <mask> github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59/go.mod h1:qPWhwz6FdSmuK7W4sMyvogrez4MWdtzosdqlr0Rg3ow= <mask> github.com/ameshkov/dnsstamps v1.0.3 h1:Srzik+J9mivH1alRACTbys2xOxs0lRH9qnTA7Y1OYVo= <mask> github.com/ameshkov/dnsstamps v1.0.3/go.mod h1:Ii3eUu73dx4Vw5O4wjzmT5+lkCwovjzaEZZ4gKyIH5A= <mask> github.com/beefsack/go-rate v0.0.0-20220214233405-116f4ca011a0 h1:0b2vaepXIfMsG++IsjHiI2p4bxALD1Y2nQKGMR5zDQM= <mask> github.com/beefsack/go-rate v0.0.0-20220214233405-116f4ca011a0/go.mod h1:6YNgTHLutezwnBvyneBbwvB8C82y3dcoOj5EQJIdGXA= <mask> github.com/bluele/gcache v0.0.2 h1:WcbfdXICg7G/DGBh1PFfcirkWOQV+v077yF1pSy3DGw= </s> Pull request 1827: upd-deps Merge in DNS/adguard-home from upd-deps to master Squashed commit of the following: commit 4892dc4ed6df76d8733e6799744b095c5db1db6c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 13 18:22:10 2023 +0300 all: upd dnscrypt, skel </s> remove // TODO(a.garipov): Remove the replace when @a.meshkov merges // https://github.com/ameshkov/dnscrypt/pull/21. replace github.com/ameshkov/dnscrypt/v2 => github.com/ainar-g/dnscrypt/v2 v2.0.1-0.20230413122657-d2ec675d1c59 </s> add </s> remove github.com/ameshkov/dnscrypt/v2 v2.2.6 </s> add github.com/ameshkov/dnscrypt/v2 v2.2.7
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c6d4f2317e3ae19ccd13945391ba65ddcd3e2cab
go.sum
t.Run("empty", func(t *testing.T) { sh := theOnlyCmd("cmd", 0, "", nil) substShell(t, sh.RunCmd) err := a.Refresh() require.NoError(t, err) assert.Empty(t, a.Neighbors()) })
<mask> testutil.AssertErrorMsg(t, "cmd arpdb: running command: unexpected exit code 1", err) <mask> }) <mask> } <mask> <mask> func TestEmptyARPDB(t *testing.T) { <mask> a := EmptyARPDB{} </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove assert.NotEmpty(t, addrs) </s> add substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return nil, errAddrs }) _, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, wantErrMsg, err) }) </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs) </s> remove // theOnlyCmd returns s that only handles a single command and arguments </s> add // theOnlyCmd returns mapShell that only handles a single command and arguments </s> remove assert.Equal(t, tc.want, GatewayIP("ifaceName")) </s> add assert.Equal(t, tc.want, GatewayIP(ifaceName)) </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } })
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/arpdb_test.go
// generateIPv4Hostname generates the hostname by IP address version 4.
<mask> ipv4HostnameMaxLen = len("192-168-100-100") <mask> ipv6HostnameMaxLen = len("ff80-f076-0000-0000-0000-0000-0000-0010") <mask> ) <mask> <mask> // generateIPv4Hostname generates the hostname for specific IP version. <mask> func generateIPv4Hostname(ipv4 net.IP) (hostname string) { <mask> hnData := make([]byte, 0, ipv4HostnameMaxLen) <mask> for i, part := range ipv4 { <mask> if i > 0 { <mask> hnData = append(hnData, '-') </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove // generateIPv6Hostname generates the hostname for specific IP version. </s> add // generateIPv6Hostname generates the hostname by IP address version 6. </s> remove } else if ipv6 := ip.To16(); ipv6 != nil { return generateIPv6Hostname(ipv6) </s> add </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } }) </s> remove func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gatewayIP, dnsIP net.IP) (conf string) { var body []byte add := fmt.Sprintf( "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", </s> add func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gwIP net.IP) (conf string) { b := &strings.Builder{} stringutil.WriteToBuilder( b, "\n# ",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/hostgen.go
// generateIPv6Hostname generates the hostname by IP address version 6.
<mask> <mask> return string(hnData) <mask> } <mask> <mask> // generateIPv6Hostname generates the hostname for specific IP version. <mask> func generateIPv6Hostname(ipv6 net.IP) (hostname string) { <mask> hnData := make([]byte, 0, ipv6HostnameMaxLen) <mask> for i, partsNum := 0, net.IPv6len/2; i < partsNum; i++ { <mask> if i > 0 { <mask> hnData = append(hnData, '-') </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove // generateIPv4Hostname generates the hostname for specific IP version. </s> add // generateIPv4Hostname generates the hostname by IP address version 4. </s> remove } else if ipv6 := ip.To16(); ipv6 != nil { return generateIPv6Hostname(ipv6) </s> add </s> remove // interface through dhcpdc.conf. </s> add // interface through dhcpcd.conf. </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } })
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/hostgen.go
// ip must be either an IPv4 or an IPv6.
<mask> // <mask> // ff80-f076-0000-0000-0000-0000-0000-0010 <mask> // <mask> func GenerateHostname(ip net.IP) (hostname string) { <mask> if ipv4 := ip.To4(); ipv4 != nil { <mask> return generateIPv4Hostname(ipv4) <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove } else if ipv6 := ip.To16(); ipv6 != nil { return generateIPv6Hostname(ipv6) </s> add </s> remove // generateIPv4Hostname generates the hostname for specific IP version. </s> add // generateIPv4Hostname generates the hostname by IP address version 4. </s> remove // generateIPv6Hostname generates the hostname for specific IP version. </s> add // generateIPv6Hostname generates the hostname by IP address version 6. </s> remove func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gatewayIP, dnsIP net.IP) (conf string) { var body []byte add := fmt.Sprintf( "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", </s> add func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gwIP net.IP) (conf string) { b := &strings.Builder{} stringutil.WriteToBuilder( b, "\n# ",
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/hostgen.go
<mask> // <mask> func GenerateHostname(ip net.IP) (hostname string) { <mask> if ipv4 := ip.To4(); ipv4 != nil { <mask> return generateIPv4Hostname(ipv4) <mask> } else if ipv6 := ip.To16(); ipv6 != nil { <mask> return generateIPv6Hostname(ipv6) <mask> } <mask> <mask> return "" <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove return "" </s> add return generateIPv6Hostname(ip) </s> remove // generateIPv4Hostname generates the hostname for specific IP version. </s> add // generateIPv4Hostname generates the hostname by IP address version 4. </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/hostgen.go
return generateIPv6Hostname(ip)
<mask> } else if ipv6 := ip.To16(); ipv6 != nil { <mask> return generateIPv6Hostname(ipv6) <mask> } <mask> <mask> return "" <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove } else if ipv6 := ip.To16(); ipv6 != nil { return generateIPv6Hostname(ipv6) </s> add </s> remove for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) if err != nil { return nil, fmt.Errorf("parsing cidr: %w", err) } addrs = append(addrs, ip.String()) } </s> add addrs = append(addrs, ip.String()) </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> add body, err := os.ReadFile(dhcpcdConf)
[ "keep", "keep", "keep", "keep", "replace", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/hostgen.go
t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }}
<mask> "github.com/stretchr/testify/assert" <mask> ) <mask> <mask> func TestGenerateHostName(t *testing.T) { <mask> testCases := []struct { <mask> name string <mask> want string <mask> ip net.IP <mask> }{{ <mask> name: "good_ipv4", <mask> want: "127-0-0-1", <mask> ip: net.IP{127, 0, 0, 1}, <mask> }, { <mask> name: "bad_ipv4", <mask> want: "", <mask> ip: net.IP{127, 0, 0, 1, 0}, <mask> }, { <mask> name: "good_ipv6", <mask> want: "fe00-0000-0000-0000-0000-0000-0000-0001", <mask> ip: net.ParseIP("fe00::1"), <mask> }, { <mask> name: "bad_ipv6", <mask> want: "", <mask> ip: net.IP{ <mask> 0xff, 0xff, 0xff, 0xff, <mask> 0xff, 0xff, 0xff, 0xff, <mask> 0xff, 0xff, 0xff, 0xff, <mask> 0xff, 0xff, 0xff, <mask> }, <mask> }, { <mask> name: "nil", <mask> want: "", <mask> ip: nil, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> hostname := GenerateHostname(tc.ip) <mask> assert.Equal(t, tc.want, hostname) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } }) </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), </s> add shell: theOnlyCmd(cmd, 1, "", nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), </s> add shell: theOnlyCmd(cmd, 0, "", errors.Error("can't run command")), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `non-default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via 1.2.3.4 onlink`, nil),
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/hostgen_test.go
for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } })
<mask> want: "", <mask> ip: nil, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> hostname := GenerateHostname(tc.ip) <mask> assert.Equal(t, tc.want, hostname) <mask> }) <mask> } <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }} </s> remove assert.Equal(t, tc.want, GatewayIP("ifaceName")) </s> add assert.Equal(t, tc.want, GatewayIP(ifaceName)) </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), </s> add shell: theOnlyCmd(cmd, 1, "", nil), </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs) </s> remove func TestSetStaticIP_dhcpcdConfIface(t *testing.T) { testCases := []struct { name string dhcpcdConf string routers net.IP }{{ name: "with_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static routers=192.168.0.1` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: net.IP{192, 168, 0, 1}, }, { name: "without_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: nil, }} ipNet := &net.IPNet{ IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 255, 0}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { s := dhcpcdConfIface("wlan0", ipNet, tc.routers, net.IP{192, 168, 0, 2}) assert.Equal(t, tc.dhcpcdConf, s) }) } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/hostgen_test.go
// Variables and functions to substitute in tests. var ( // aghosRunCommand is the function to run shell commands. aghosRunCommand = aghos.RunCommand
<mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/netutil" <mask> ) <mask> <mask> // aghosRunCommand is the function to run shell commands. It's an unexported <mask> // variable instead of a direct call to make it substitutable in tests. <mask> var aghosRunCommand = aghos.RunCommand <mask> <mask> // rootDirFS is the filesystem pointing to the root directory. It's an <mask> // unexported variable instead to make it substitutable in tests. <mask> var rootDirFS = aghos.RootDirFS() <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> add // netInterfaces is the function to get the available network interfaces. netInterfaceAddrs = net.InterfaceAddrs // rootDirFS is the filesystem pointing to the root directory. rootDirFS = aghos.RootDirFS() ) </s> remove if runtime.GOOS == "windows" { // On Windows we need to have admin rights to run properly admin, _ := aghos.HaveAdminRights() if admin { return } </s> add if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil { </s> remove ok, err := aghnet.CanBindPort(53) if ok { log.Info("AdGuard Home can bind to port 53") return } if errors.Is(err, os.ErrPermission) { msg := `Permission check failed. </s> add err := aghnet.CheckPort("tcp", net.IP{127, 0, 0, 1}, defaultPortDNS) if err != nil { if errors.Is(err, os.ErrPermission) { log.Fatal(`Permission check failed. </s> remove log.Fatal(msg) </s> add log.Info( "AdGuard failed to bind to port 53: %s\n\n"+ "Please note, that this is crucial for a DNS server to be able to use that port.", err, ) </s> remove msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v Please note, that this is crucial for a DNS server to be able to use that port.`, err) log.Info(msg) </s> add log.Info("AdGuard Home can bind to port 53")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
// netInterfaces is the function to get the available network interfaces. netInterfaceAddrs = net.InterfaceAddrs // rootDirFS is the filesystem pointing to the root directory. rootDirFS = aghos.RootDirFS() )
<mask> // aghosRunCommand is the function to run shell commands. It's an unexported <mask> // variable instead of a direct call to make it substitutable in tests. <mask> var aghosRunCommand = aghos.RunCommand <mask> <mask> // rootDirFS is the filesystem pointing to the root directory. It's an <mask> // unexported variable instead to make it substitutable in tests. <mask> var rootDirFS = aghos.RootDirFS() <mask> <mask> // ErrNoStaticIPInfo is returned by IfaceHasStaticIP when no information about <mask> // the IP being static is available. <mask> const ErrNoStaticIPInfo errors.Error = "no information about static ip" <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand </s> add // Variables and functions to substitute in tests. var ( // aghosRunCommand is the function to run shell commands. aghosRunCommand = aghos.RunCommand </s> remove if runtime.GOOS == "windows" { // On Windows we need to have admin rights to run properly admin, _ := aghos.HaveAdminRights() if admin { return } </s> add if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil { </s> remove ok, err := aghnet.CanBindPort(53) if ok { log.Info("AdGuard Home can bind to port 53") return } if errors.Is(err, os.ErrPermission) { msg := `Permission check failed. </s> add err := aghnet.CheckPort("tcp", net.IP{127, 0, 0, 1}, defaultPortDNS) if err != nil { if errors.Is(err, os.ErrPermission) { log.Fatal(`Permission check failed. </s> remove log.Fatal(msg) </s> add log.Info( "AdGuard failed to bind to port 53: %s\n\n"+ "Please note, that this is crucial for a DNS server to be able to use that port.", err, ) </s> remove msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v Please note, that this is crucial for a DNS server to be able to use that port.`, err) log.Info(msg) </s> add log.Info("AdGuard Home can bind to port 53")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
<mask> <mask> return net.ParseIP(string(fields[2])) <mask> } <mask> <mask> // CanBindPort checks if we can bind to the given port. <mask> func CanBindPort(port int) (can bool, err error) { <mask> var addr *net.TCPAddr <mask> addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) <mask> if err != nil { <mask> return false, err <mask> } <mask> <mask> var listener *net.TCPListener <mask> listener, err = net.ListenTCP("tcp", addr) <mask> if err != nil { <mask> return false, err <mask> } <mask> _ = listener.Close() <mask> return true, nil <mask> } <mask> <mask> // CanBindPrivilegedPorts checks if current process can bind to privileged <mask> // ports. <mask> func CanBindPrivilegedPorts() (can bool, err error) { <mask> return canBindPrivilegedPorts() <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() return cnbs == 1 || adm, err } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
// MarshalText implements the json.Marshaler interface for NetInterface. func (iface NetInterface) MarshalText() ([]byte, error) {
<mask> Flags net.Flags `json:"flags"` <mask> MTU int `json:"mtu"` <mask> } <mask> <mask> // MarshalJSON implements the json.Marshaler interface for NetInterface. <mask> func (iface NetInterface) MarshalJSON() ([]byte, error) { <mask> type netInterface NetInterface <mask> return json.Marshal(&struct { <mask> HardwareAddr string `json:"hardware_address"` <mask> Flags string `json:"flags"` <mask> netInterface </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove return netInterfaces, nil </s> add return netIfaces, nil </s> remove // theOnlyCmd returns s that only handles a single command and arguments </s> add // theOnlyCmd returns mapShell that only handles a single command and arguments </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove // interface through dhcpdc.conf. </s> add // interface through dhcpcd.conf.
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
// GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) {
<mask> netInterface: netInterface(iface), <mask> }) <mask> } <mask> <mask> // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only <mask> // we do not return link-local addresses here <mask> func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { <mask> ifaces, err := net.Interfaces() <mask> if err != nil { <mask> return nil, fmt.Errorf("couldn't get interfaces: %w", err) <mask> } else if len(ifaces) == 0 { <mask> return nil, errors.Error("couldn't find any legible interface") </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs() </s> remove return nil, fmt.Errorf("getting network interfaces: %w", err) </s> add return nil, fmt.Errorf("getting interfaces addresses: %w", err) </s> remove for _, iface := range ifaces { var ifaceAddrs []net.Addr ifaceAddrs, err = iface.Addrs() </s> add for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) </s> remove // theOnlyCmd returns s that only handles a single command and arguments </s> add // theOnlyCmd returns mapShell that only handles a single command and arguments
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
netIfaces = append(netIfaces, netIface)
<mask> } <mask> <mask> // Discard interfaces with no addresses. <mask> if len(netIface.Addresses) != 0 { <mask> netInterfaces = append(netInterfaces, netIface) <mask> } <mask> } <mask> <mask> return netInterfaces, nil <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove return netInterfaces, nil </s> add return netIfaces, nil </s> remove // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only // we do not return link-local addresses here func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> add // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) { </s> remove } else if ipv6 := ip.To16(); ipv6 != nil { return generateIPv6Hostname(ipv6) </s> add </s> remove // CanBindPort checks if we can bind to the given port. func CanBindPort(port int) (can bool, err error) { var addr *net.TCPAddr addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false, err } var listener *net.TCPListener listener, err = net.ListenTCP("tcp", addr) if err != nil { return false, err } _ = listener.Close() return true, nil } </s> add </s> remove return "" </s> add return generateIPv6Hostname(ip)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
return netIfaces, nil
<mask> netInterfaces = append(netInterfaces, netIface) <mask> } <mask> } <mask> <mask> return netInterfaces, nil <mask> } <mask> <mask> // GetInterfaceByIP returns the name of interface containing provided ip. <mask> func GetInterfaceByIP(ip net.IP) string { <mask> ifaces, err := GetValidNetInterfacesForWeb() </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove netInterfaces = append(netInterfaces, netIface) </s> add netIfaces = append(netIfaces, netIface) </s> remove // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only // we do not return link-local addresses here func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> add // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) { </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
// // TODO(e.burkov): See TODO on GetValidInterfacesForWeb.
<mask> return netIfaces, nil <mask> } <mask> <mask> // GetInterfaceByIP returns the name of interface containing provided ip. <mask> func GetInterfaceByIP(ip net.IP) string { <mask> ifaces, err := GetValidNetInterfacesForWeb() <mask> if err != nil { <mask> return "" </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove return netInterfaces, nil </s> add return netIfaces, nil </s> remove } else if ipv6 := ip.To16(); ipv6 != nil { return generateIPv6Hostname(ipv6) </s> add </s> remove // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only // we do not return link-local addresses here func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> add // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) { </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs()
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
// // TODO(e.burkov): See TODO on GetValidInterfacesForWeb.
<mask> <mask> // GetSubnet returns pointer to net.IPNet for the specified interface or nil if <mask> // the search fails. <mask> func GetSubnet(ifaceName string) *net.IPNet { <mask> netIfaces, err := GetValidNetInterfacesForWeb() <mask> if err != nil { <mask> log.Error("Could not get network interfaces info: %v", err) <mask> return nil <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only // we do not return link-local addresses here func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> add // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) { </s> remove return netInterfaces, nil </s> add return netIfaces, nil </s> remove // interface through dhcpdc.conf. </s> add // interface through dhcpcd.conf. </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs()
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs()
<mask> <mask> // CollectAllIfacesAddrs returns the slice of all network interfaces IP <mask> // addresses without port number. <mask> func CollectAllIfacesAddrs() (addrs []string, err error) { <mask> var ifaces []net.Interface <mask> ifaces, err = net.Interfaces() <mask> if err != nil { <mask> return nil, fmt.Errorf("getting network interfaces: %w", err) <mask> } <mask> <mask> for _, iface := range ifaces { </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove return nil, fmt.Errorf("getting network interfaces: %w", err) </s> add return nil, fmt.Errorf("getting interfaces addresses: %w", err) </s> remove for _, iface := range ifaces { var ifaceAddrs []net.Addr ifaceAddrs, err = iface.Addrs() </s> add for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) </s> remove return nil, fmt.Errorf("getting addresses for %q: %w", iface.Name, err) </s> add return nil, fmt.Errorf("parsing cidr: %w", err) </s> remove // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only // we do not return link-local addresses here func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> add // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) { </s> remove for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) if err != nil { return nil, fmt.Errorf("parsing cidr: %w", err) } addrs = append(addrs, ip.String()) } </s> add addrs = append(addrs, ip.String())
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
return nil, fmt.Errorf("getting interfaces addresses: %w", err)
<mask> func CollectAllIfacesAddrs() (addrs []string, err error) { <mask> var ifaces []net.Interface <mask> ifaces, err = net.Interfaces() <mask> if err != nil { <mask> return nil, fmt.Errorf("getting network interfaces: %w", err) <mask> } <mask> <mask> for _, iface := range ifaces { <mask> var ifaceAddrs []net.Addr <mask> ifaceAddrs, err = iface.Addrs() </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs() </s> remove for _, iface := range ifaces { var ifaceAddrs []net.Addr ifaceAddrs, err = iface.Addrs() </s> add for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) </s> remove return nil, fmt.Errorf("getting addresses for %q: %w", iface.Name, err) </s> add return nil, fmt.Errorf("parsing cidr: %w", err) </s> remove for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) if err != nil { return nil, fmt.Errorf("parsing cidr: %w", err) } addrs = append(addrs, ip.String()) } </s> add addrs = append(addrs, ip.String()) </s> remove assert.NotEmpty(t, addrs) </s> add substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return nil, errAddrs }) _, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, wantErrMsg, err) })
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr)
<mask> if err != nil { <mask> return nil, fmt.Errorf("getting network interfaces: %w", err) <mask> } <mask> <mask> for _, iface := range ifaces { <mask> var ifaceAddrs []net.Addr <mask> ifaceAddrs, err = iface.Addrs() <mask> if err != nil { <mask> return nil, fmt.Errorf("getting addresses for %q: %w", iface.Name, err) <mask> } <mask> <mask> for _, addr := range ifaceAddrs { </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove return nil, fmt.Errorf("getting addresses for %q: %w", iface.Name, err) </s> add return nil, fmt.Errorf("parsing cidr: %w", err) </s> remove return nil, fmt.Errorf("getting network interfaces: %w", err) </s> add return nil, fmt.Errorf("getting interfaces addresses: %w", err) </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs() </s> remove for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) if err != nil { return nil, fmt.Errorf("parsing cidr: %w", err) } addrs = append(addrs, ip.String()) } </s> add addrs = append(addrs, ip.String()) </s> remove // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only // we do not return link-local addresses here func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> add // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
return nil, fmt.Errorf("parsing cidr: %w", err)
<mask> for _, iface := range ifaces { <mask> var ifaceAddrs []net.Addr <mask> ifaceAddrs, err = iface.Addrs() <mask> if err != nil { <mask> return nil, fmt.Errorf("getting addresses for %q: %w", iface.Name, err) <mask> } <mask> <mask> for _, addr := range ifaceAddrs { <mask> cidr := addr.String() <mask> var ip net.IP </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove for _, iface := range ifaces { var ifaceAddrs []net.Addr ifaceAddrs, err = iface.Addrs() </s> add for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) </s> remove for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) if err != nil { return nil, fmt.Errorf("parsing cidr: %w", err) } addrs = append(addrs, ip.String()) } </s> add addrs = append(addrs, ip.String()) </s> remove return nil, fmt.Errorf("getting network interfaces: %w", err) </s> add return nil, fmt.Errorf("getting interfaces addresses: %w", err) </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs() </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } })
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
addrs = append(addrs, ip.String())
<mask> if err != nil { <mask> return nil, fmt.Errorf("getting addresses for %q: %w", iface.Name, err) <mask> } <mask> <mask> for _, addr := range ifaceAddrs { <mask> cidr := addr.String() <mask> var ip net.IP <mask> ip, _, err = net.ParseCIDR(cidr) <mask> if err != nil { <mask> return nil, fmt.Errorf("parsing cidr: %w", err) <mask> } <mask> <mask> addrs = append(addrs, ip.String()) <mask> } <mask> } <mask> <mask> return addrs, nil <mask> } <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove return nil, fmt.Errorf("getting addresses for %q: %w", iface.Name, err) </s> add return nil, fmt.Errorf("parsing cidr: %w", err) </s> remove for _, iface := range ifaces { var ifaceAddrs []net.Addr ifaceAddrs, err = iface.Addrs() </s> add for _, addr := range ifaceAddrs { cidr := addr.String() var ip net.IP ip, _, err = net.ParseCIDR(cidr) </s> remove return nil, fmt.Errorf("getting network interfaces: %w", err) </s> add return nil, fmt.Errorf("getting interfaces addresses: %w", err) </s> remove var ifaces []net.Interface ifaces, err = net.Interfaces() </s> add var ifaceAddrs []net.Addr ifaceAddrs, err = netInterfaceAddrs() </s> remove assert.NotEmpty(t, addrs) </s> add substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return nil, errAddrs }) _, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, wantErrMsg, err) })
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net.go
<mask> gatewayIP string <mask> static bool <mask> } <mask> <mask> func canBindPrivilegedPorts() (can bool, err error) { <mask> return aghos.HaveAdminRights() <mask> } <mask> <mask> func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { <mask> portInfo, err := getCurrentHardwarePortInfo(ifaceName) <mask> if err != nil { <mask> return false, err <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove // CanBindPort checks if we can bind to the given port. func CanBindPort(port int) (can bool, err error) { var addr *net.TCPAddr addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false, err } var listener *net.TCPListener listener, err = net.ListenTCP("tcp", addr) if err != nil { return false, err } _ = listener.Close() return true, nil } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() return cnbs == 1 || adm, err } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_darwin.go
<mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> ) <mask> <mask> func canBindPrivilegedPorts() (can bool, err error) { <mask> return aghos.HaveAdminRights() <mask> } <mask> <mask> func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { <mask> const rcConfFilename = "etc/rc.conf" <mask> <mask> walker := aghos.FileWalker(interfaceName(ifaceName).rcConfStaticConfig) <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() return cnbs == 1 || adm, err } </s> add </s> remove // CanBindPort checks if we can bind to the given port. func CanBindPort(port int) (can bool, err error) { var addr *net.TCPAddr addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false, err } var listener *net.TCPListener listener, err = net.ListenTCP("tcp", addr) if err != nil { return false, err } _ = listener.Close() return true, nil } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_freebsd.go
func TestIfaceHasStaticIP(t *testing.T) {
<mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> func TestRcConfStaticConfig(t *testing.T) { <mask> const ( <mask> ifaceName = `em0` <mask> rcConf = "etc/rc.conf" <mask> ) <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove "net" </s> add </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_freebsd_test.go
filename: dhcpcdConf,
<mask> aghos.FileWalker <mask> filename string <mask> }{{ <mask> FileWalker: iface.dhcpcdStaticConfig, <mask> filename: "etc/dhcpcd.conf", <mask> }, { <mask> FileWalker: iface.ifacesStaticConfig, <mask> filename: "etc/network/interfaces", <mask> }} { <mask> has, err = pair.Walk(rootDirFS, pair.filename) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }} </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } }) </s> remove t.Skip("TODO(e.burkov): Substitute the net.Interfaces.") </s> add testCases := []struct { name string wantErrMsg string addrs []net.Addr wantAddrs []string }{{ name: "success", wantErrMsg: ``, addrs: []net.Addr{&net.IPNet{ IP: net.IP{1, 2, 3, 4}, Mask: net.CIDRMask(24, netutil.IPv4BitLen), }, &net.IPNet{ IP: net.IP{4, 3, 2, 1}, Mask: net.CIDRMask(16, netutil.IPv4BitLen), }}, wantAddrs: []string{"1.2.3.4", "4.3.2.1"}, }, { name: "not_cidr", wantErrMsg: `parsing cidr: invalid CIDR address: 1.2.3.4`, addrs: []net.Addr{&net.IPAddr{ IP: net.IP{1, 2, 3, 4}, }}, wantAddrs: nil, }, { name: "empty", wantErrMsg: ``, addrs: []net.Addr{}, wantAddrs: nil, }} </s> remove func TestSetStaticIP_dhcpcdConfIface(t *testing.T) { testCases := []struct { name string dhcpcdConf string routers net.IP }{{ name: "with_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static routers=192.168.0.1` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: net.IP{192, 168, 0, 1}, }, { name: "without_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: nil, }} ipNet := &net.IPNet{ IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 255, 0}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { s := dhcpcdConfIface("wlan0", ipNet, tc.routers, net.IP{192, 168, 0, 2}) assert.Equal(t, tc.dhcpcdConf, s) }) } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
<mask> <mask> return false, ErrNoStaticIPInfo <mask> } <mask> <mask> func canBindPrivilegedPorts() (can bool, err error) { <mask> cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) <mask> // Don't check the error because it's always nil on Linux. <mask> adm, _ := aghos.HaveAdminRights() <mask> <mask> return cnbs == 1 || adm, err <mask> } <mask> <mask> // findIfaceLine scans s until it finds the line that declares an interface with <mask> // the given name. If findIfaceLine can't find the line, it returns false. <mask> func findIfaceLine(s *bufio.Scanner, name string) (ok bool) { <mask> for s.Scan() { <mask> line := strings.TrimSpace(s.Text()) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove // CanBindPort checks if we can bind to the given port. func CanBindPort(port int) (can bool, err error) { var addr *net.TCPAddr addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false, err } var listener *net.TCPListener listener, err = net.ListenTCP("tcp", addr) if err != nil { return false, err } _ = listener.Close() return true, nil } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
// interface through dhcpcd.conf.
<mask> return false <mask> } <mask> <mask> // ifaceSetStaticIP configures the system to retain its current IP on the <mask> // interface through dhcpdc.conf. <mask> func ifaceSetStaticIP(ifaceName string) (err error) { <mask> ipNet := GetSubnet(ifaceName) <mask> if ipNet.IP == nil { <mask> return errors.Error("can't get IP address") <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> add body, err := os.ReadFile(dhcpcdConf) </s> remove func canBindPrivilegedPorts() (can bool, err error) { cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() return cnbs == 1 || adm, err } </s> add </s> remove // generateIPv6Hostname generates the hostname for specific IP version. </s> add // generateIPv6Hostname generates the hostname by IP address version 6.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
body, err := os.ReadFile(dhcpcdConf)
<mask> if ipNet.IP == nil { <mask> return errors.Error("can't get IP address") <mask> } <mask> <mask> gatewayIP := GatewayIP(ifaceName) <mask> add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) <mask> <mask> const filename = "/etc/dhcpcd.conf" <mask> <mask> body, err := os.ReadFile(filename) <mask> if err != nil && !errors.Is(err, os.ErrNotExist) { <mask> return err <mask> } <mask> <mask> body = append(body, []byte(add)...) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove // interface through dhcpdc.conf. </s> add // interface through dhcpcd.conf. </s> remove err = maybe.WriteFile(filename, body, 0o644) </s> add err = maybe.WriteFile(dhcpcdConf, body, 0o644) </s> remove if gatewayIP != nil { add = fmt.Sprintf("static routers=%s\n", gatewayIP) body = append(body, []byte(add)...) </s> add if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n") </s> remove ipNet) body = append(body, []byte(add)...) </s> add " added by AdGuard Home.\ninterface ", ifaceName, "\nstatic ip_address=", ipNet.String(), "\n", )
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP)
<mask> } <mask> <mask> body = append(body, []byte(add)...) <mask> err = maybe.WriteFile(dhcpcdConf, body, 0o644) <mask> if err != nil { <mask> return fmt.Errorf("writing conf: %w", err) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove err = maybe.WriteFile(filename, body, 0o644) </s> add err = maybe.WriteFile(dhcpcdConf, body, 0o644) </s> remove gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> add body, err := os.ReadFile(dhcpcdConf) </s> remove if gatewayIP != nil { add = fmt.Sprintf("static routers=%s\n", gatewayIP) body = append(body, []byte(add)...) </s> add if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n") </s> remove add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) body = append(body, []byte(add)...) </s> add stringutil.WriteToBuilder(b, "static domain_name_servers=", ipNet.IP.String(), "\n\n") </s> remove ipNet) body = append(body, []byte(add)...) </s> add " added by AdGuard Home.\ninterface ", ifaceName, "\nstatic ip_address=", ipNet.String(), "\n", )
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
err = maybe.WriteFile(dhcpcdConf, body, 0o644)
<mask> return err <mask> } <mask> <mask> body = append(body, []byte(add)...) <mask> err = maybe.WriteFile(filename, body, 0o644) <mask> if err != nil { <mask> return fmt.Errorf("writing conf: %w", err) <mask> } <mask> <mask> return nil </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> add body, err := os.ReadFile(dhcpcdConf) </s> remove add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) body = append(body, []byte(add)...) </s> add stringutil.WriteToBuilder(b, "static domain_name_servers=", ipNet.IP.String(), "\n\n") </s> remove return string(body) </s> add return b.String() </s> remove if gatewayIP != nil { add = fmt.Sprintf("static routers=%s\n", gatewayIP) body = append(body, []byte(add)...) </s> add if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gwIP net.IP) (conf string) { b := &strings.Builder{} stringutil.WriteToBuilder( b, "\n# ",
<mask> } <mask> <mask> // dhcpcdConfIface returns configuration lines for the dhcpdc.conf files that <mask> // configure the interface to have a static IP. <mask> func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gatewayIP, dnsIP net.IP) (conf string) { <mask> var body []byte <mask> <mask> add := fmt.Sprintf( <mask> "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", <mask> ifaceName, <mask> ipNet) <mask> body = append(body, []byte(add)...) <mask> <mask> if gatewayIP != nil { </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove ipNet) body = append(body, []byte(add)...) </s> add " added by AdGuard Home.\ninterface ", ifaceName, "\nstatic ip_address=", ipNet.String(), "\n", ) </s> remove if gatewayIP != nil { add = fmt.Sprintf("static routers=%s\n", gatewayIP) body = append(body, []byte(add)...) </s> add if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n") </s> remove gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> add body, err := os.ReadFile(dhcpcdConf) </s> remove // interface through dhcpdc.conf. </s> add // interface through dhcpcd.conf.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
" added by AdGuard Home.\ninterface ", ifaceName, "\nstatic ip_address=", ipNet.String(), "\n", )
<mask> <mask> add := fmt.Sprintf( <mask> "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", <mask> ifaceName, <mask> ipNet) <mask> body = append(body, []byte(add)...) <mask> <mask> if gatewayIP != nil { <mask> add = fmt.Sprintf("static routers=%s\n", gatewayIP) <mask> body = append(body, []byte(add)...) <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gatewayIP, dnsIP net.IP) (conf string) { var body []byte add := fmt.Sprintf( "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", </s> add func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gwIP net.IP) (conf string) { b := &strings.Builder{} stringutil.WriteToBuilder( b, "\n# ", </s> remove if gatewayIP != nil { add = fmt.Sprintf("static routers=%s\n", gatewayIP) body = append(body, []byte(add)...) </s> add if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n") </s> remove add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) body = append(body, []byte(add)...) </s> add stringutil.WriteToBuilder(b, "static domain_name_servers=", ipNet.IP.String(), "\n\n") </s> remove return string(body) </s> add return b.String()
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n")
<mask> ifaceName, <mask> ipNet) <mask> body = append(body, []byte(add)...) <mask> <mask> if gatewayIP != nil { <mask> add = fmt.Sprintf("static routers=%s\n", gatewayIP) <mask> body = append(body, []byte(add)...) <mask> } <mask> <mask> add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) <mask> body = append(body, []byte(add)...) <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) body = append(body, []byte(add)...) </s> add stringutil.WriteToBuilder(b, "static domain_name_servers=", ipNet.IP.String(), "\n\n") </s> remove ipNet) body = append(body, []byte(add)...) </s> add " added by AdGuard Home.\ninterface ", ifaceName, "\nstatic ip_address=", ipNet.String(), "\n", ) </s> remove return string(body) </s> add return b.String() </s> remove func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gatewayIP, dnsIP net.IP) (conf string) { var body []byte add := fmt.Sprintf( "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", </s> add func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gwIP net.IP) (conf string) { b := &strings.Builder{} stringutil.WriteToBuilder( b, "\n# ",
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
stringutil.WriteToBuilder(b, "static domain_name_servers=", ipNet.IP.String(), "\n\n")
<mask> add = fmt.Sprintf("static routers=%s\n", gatewayIP) <mask> body = append(body, []byte(add)...) <mask> } <mask> <mask> add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) <mask> body = append(body, []byte(add)...) <mask> <mask> return string(body) <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove if gatewayIP != nil { add = fmt.Sprintf("static routers=%s\n", gatewayIP) body = append(body, []byte(add)...) </s> add if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n") </s> remove return string(body) </s> add return b.String() </s> remove ipNet) body = append(body, []byte(add)...) </s> add " added by AdGuard Home.\ninterface ", ifaceName, "\nstatic ip_address=", ipNet.String(), "\n", ) </s> remove gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> add body, err := os.ReadFile(dhcpcdConf)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
return b.String()
<mask> <mask> add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) <mask> body = append(body, []byte(add)...) <mask> <mask> return string(body) <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove add = fmt.Sprintf("static domain_name_servers=%s\n\n", dnsIP) body = append(body, []byte(add)...) </s> add stringutil.WriteToBuilder(b, "static domain_name_servers=", ipNet.IP.String(), "\n\n") </s> remove if gatewayIP != nil { add = fmt.Sprintf("static routers=%s\n", gatewayIP) body = append(body, []byte(add)...) </s> add if gwIP != nil { stringutil.WriteToBuilder(b, "static routers=", gwIP.String(), "\n") </s> remove ipNet) body = append(body, []byte(add)...) </s> add " added by AdGuard Home.\ninterface ", ifaceName, "\nstatic ip_address=", ipNet.String(), "\n", ) </s> remove gatewayIP := GatewayIP(ifaceName) add := dhcpcdConfIface(ifaceName, ipNet, gatewayIP, ipNet.IP) const filename = "/etc/dhcpcd.conf" body, err := os.ReadFile(filename) </s> add body, err := os.ReadFile(dhcpcdConf)
[ "keep", "keep", "keep", "keep", "replace", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux.go
<mask> package aghnet <mask> <mask> import ( <mask> "io/fs" <mask> "net" <mask> "testing" <mask> "testing/fstest" <mask> <mask> "github.com/AdguardTeam/golibs/testutil" <mask> "github.com/stretchr/testify/assert" </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func TestRcConfStaticConfig(t *testing.T) { </s> add func TestIfaceHasStaticIP(t *testing.T) { </s> remove // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand </s> add // Variables and functions to substitute in tests. var ( // aghosRunCommand is the function to run shell commands. aghosRunCommand = aghos.RunCommand </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }} </s> remove msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v Please note, that this is crucial for a DNS server to be able to use that port.`, err) log.Info(msg) </s> add log.Info("AdGuard Home can bind to port 53")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux_test.go
<mask> tc.wantHas(t, has) <mask> }) <mask> } <mask> } <mask> <mask> func TestSetStaticIP_dhcpcdConfIface(t *testing.T) { <mask> testCases := []struct { <mask> name string <mask> dhcpcdConf string <mask> routers net.IP <mask> }{{ <mask> name: "with_gateway", <mask> dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + <mask> `interface wlan0` + nl + <mask> `static ip_address=192.168.0.2/24` + nl + <mask> `static routers=192.168.0.1` + nl + <mask> `static domain_name_servers=192.168.0.2` + nl + nl, <mask> routers: net.IP{192, 168, 0, 1}, <mask> }, { <mask> name: "without_gateway", <mask> dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + <mask> `interface wlan0` + nl + <mask> `static ip_address=192.168.0.2/24` + nl + <mask> `static domain_name_servers=192.168.0.2` + nl + nl, <mask> routers: nil, <mask> }} <mask> <mask> ipNet := &net.IPNet{ <mask> IP: net.IP{192, 168, 0, 2}, <mask> Mask: net.IPMask{255, 255, 255, 0}, <mask> } <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> s := dhcpcdConfIface("wlan0", ipNet, tc.routers, net.IP{192, 168, 0, 2}) <mask> assert.Equal(t, tc.dhcpcdConf, s) <mask> }) <mask> } <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs) </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } }) </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }}
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_linux_test.go
<mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> ) <mask> <mask> func canBindPrivilegedPorts() (can bool, err error) { <mask> return aghos.HaveAdminRights() <mask> } <mask> <mask> func ifaceHasStaticIP(ifaceName string) (ok bool, err error) { <mask> filename := fmt.Sprintf("etc/hostname.%s", ifaceName) <mask> <mask> return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename) <mask> } </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() return cnbs == 1 || adm, err } </s> add </s> remove // CanBindPort checks if we can bind to the given port. func CanBindPort(port int) (can bool, err error) { var addr *net.TCPAddr addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false, err } var listener *net.TCPListener listener, err = net.ListenTCP("tcp", addr) if err != nil { return false, err } _ = listener.Close() return true, nil } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_openbsd.go
// theOnlyCmd returns mapShell that only handles a single command and arguments
<mask> out string <mask> code int <mask> } <mask> <mask> // theOnlyCmd returns s that only handles a single command and arguments <mask> // combination from cmd. <mask> func theOnlyCmd(cmd string, code int, out string, err error) (s mapShell) { <mask> return mapShell{cmd: {code: code, out: out, err: err}} <mask> } <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only // we do not return link-local addresses here func GetValidNetInterfacesForWeb() (netInterfaces []*NetInterface, err error) { </s> add // GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and // WEB only we do not return link-local addresses here. // // TODO(e.burkov): Can't properly test the function since it's nontrivial to // substitute net.Interface.Addrs and the net.InterfaceAddrs can't be used. func GetValidNetInterfacesForWeb() (netIfaces []*NetInterface, err error) { </s> remove func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gatewayIP, dnsIP net.IP) (conf string) { var body []byte add := fmt.Sprintf( "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", </s> add func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gwIP net.IP) (conf string) { b := &strings.Builder{} stringutil.WriteToBuilder( b, "\n# ", </s> remove // MarshalJSON implements the json.Marshaler interface for NetInterface. func (iface NetInterface) MarshalJSON() ([]byte, error) { </s> add // MarshalText implements the json.Marshaler interface for NetInterface. func (iface NetInterface) MarshalText() ([]byte, error) { </s> remove func canBindPrivilegedPorts() (can bool, err error) { cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() return cnbs == 1 || adm, err } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
// ifaceAddrsFunc is the signature of net.InterfaceAddrs function. type ifaceAddrsFunc func() (ifaces []net.Addr, err error) // substNetInterfaceAddrs replaces the the net.InterfaceAddrs function used // throughout the package with f for tests ran under t. func substNetInterfaceAddrs(t *testing.T, f ifaceAddrsFunc) { t.Helper() prev := netInterfaceAddrs t.Cleanup(func() { netInterfaceAddrs = prev }) netInterfaceAddrs = f }
<mask> } <mask> <mask> func TestGatewayIP(t *testing.T) { <mask> const ifaceName = "ifaceName" <mask> const cmd = "ip route show dev " + ifaceName <mask> </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func TestRcConfStaticConfig(t *testing.T) { </s> add func TestIfaceHasStaticIP(t *testing.T) { </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs) </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), </s> add shell: theOnlyCmd(cmd, 1, "", nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), </s> add shell: theOnlyCmd(cmd, 0, "", errors.Error("can't run command")),
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
const ifaceName = "ifaceName" const cmd = "ip route show dev " + ifaceName
<mask> } <mask> <mask> func TestGatewayIP(t *testing.T) { <mask> testCases := []struct { <mask> name string <mask> shell mapShell <mask> want net.IP <mask> }{{ </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }} </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } }) </s> remove func TestSetStaticIP_dhcpcdConfIface(t *testing.T) { testCases := []struct { name string dhcpcdConf string routers net.IP }{{ name: "with_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static routers=192.168.0.1` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: net.IP{192, 168, 0, 1}, }, { name: "without_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: nil, }} ipNet := &net.IPNet{ IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 255, 0}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { s := dhcpcdConfIface("wlan0", ipNet, tc.routers, net.IP{192, 168, 0, 2}) assert.Equal(t, tc.dhcpcdConf, s) }) } } </s> add </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via 1.2.3.4 onlink`, nil), </s> remove t.Skip("TODO(e.burkov): Substitute the net.Interfaces.") </s> add testCases := []struct { name string wantErrMsg string addrs []net.Addr wantAddrs []string }{{ name: "success", wantErrMsg: ``, addrs: []net.Addr{&net.IPNet{ IP: net.IP{1, 2, 3, 4}, Mask: net.CIDRMask(24, netutil.IPv4BitLen), }, &net.IPNet{ IP: net.IP{4, 3, 2, 1}, Mask: net.CIDRMask(16, netutil.IPv4BitLen), }}, wantAddrs: []string{"1.2.3.4", "4.3.2.1"}, }, { name: "not_cidr", wantErrMsg: `parsing cidr: invalid CIDR address: 1.2.3.4`, addrs: []net.Addr{&net.IPAddr{ IP: net.IP{1, 2, 3, 4}, }}, wantAddrs: nil, }, { name: "empty", wantErrMsg: ``, addrs: []net.Addr{}, wantAddrs: nil, }}
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
shell: theOnlyCmd(cmd, 0, `default via 1.2.3.4 onlink`, nil),
<mask> shell mapShell <mask> want net.IP <mask> }{{ <mask> name: "success_v4", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), <mask> want: net.IP{1, 2, 3, 4}.To16(), <mask> }, { <mask> name: "success_v6", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), <mask> want: net.IP{ </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via ::ffff onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `non-default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), </s> add shell: theOnlyCmd(cmd, 0, "", errors.Error("can't run command")), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), </s> add shell: theOnlyCmd(cmd, 1, "", nil),
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
shell: theOnlyCmd(cmd, 0, `default via ::ffff onlink`, nil),
<mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), <mask> want: net.IP{1, 2, 3, 4}.To16(), <mask> }, { <mask> name: "success_v6", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), <mask> want: net.IP{ <mask> 0x0, 0x0, 0x0, 0x0, <mask> 0x0, 0x0, 0x0, 0x0, <mask> 0x0, 0x0, 0x0, 0x0, <mask> 0x0, 0x0, 0xFF, 0xFF, </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `non-default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), </s> add shell: theOnlyCmd(cmd, 0, "", errors.Error("can't run command")), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), </s> add shell: theOnlyCmd(cmd, 1, "", nil), </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
shell: theOnlyCmd(cmd, 0, `non-default via 1.2.3.4 onlink`, nil),
<mask> 0x0, 0x0, 0xFF, 0xFF, <mask> }, <mask> }, { <mask> name: "bad_output", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), <mask> want: nil, <mask> }, { <mask> name: "err_runcmd", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), <mask> want: nil, </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), </s> add shell: theOnlyCmd(cmd, 0, "", errors.Error("can't run command")), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via ::ffff onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), </s> add shell: theOnlyCmd(cmd, 1, "", nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via 1.2.3.4 onlink`, nil), </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
shell: theOnlyCmd(cmd, 0, "", errors.Error("can't run command")),
<mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), <mask> want: nil, <mask> }, { <mask> name: "err_runcmd", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), <mask> want: nil, <mask> }, { <mask> name: "bad_code", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), <mask> want: nil, </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `non-default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), </s> add shell: theOnlyCmd(cmd, 1, "", nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via ::ffff onlink`, nil), </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
shell: theOnlyCmd(cmd, 1, "", nil),
<mask> shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), <mask> want: nil, <mask> }, { <mask> name: "bad_code", <mask> shell: theOnlyCmd("ip route show dev ifaceName", 1, "", nil), <mask> want: nil, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, "", errors.Error("can't run command")), </s> add shell: theOnlyCmd(cmd, 0, "", errors.Error("can't run command")), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `non-default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `non-default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via 1.2.3.4 onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via 1.2.3.4 onlink`, nil), </s> remove shell: theOnlyCmd("ip route show dev ifaceName", 0, `default via ::ffff onlink`, nil), </s> add shell: theOnlyCmd(cmd, 0, `default via ::ffff onlink`, nil), </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } })
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
assert.Equal(t, tc.want, GatewayIP(ifaceName))
<mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> substShell(t, tc.shell.RunCmd) <mask> <mask> assert.Equal(t, tc.want, GatewayIP("ifaceName")) <mask> }) <mask> } <mask> } <mask> <mask> func TestGetInterfaceByIP(t *testing.T) { </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } }) </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs) </s> remove testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "bad_ipv4", want: "", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "bad_ipv6", want: "", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", want: "", ip: nil, }} </s> add t.Run("valid", func(t *testing.T) { testCases := []struct { name string want string ip net.IP }{{ name: "good_ipv4", want: "127-0-0-1", ip: net.IP{127, 0, 0, 1}, }, { name: "good_ipv6", want: "fe00-0000-0000-0000-0000-0000-0000-0001", ip: net.ParseIP("fe00::1"), }, { name: "4to6", want: "1-2-3-4", ip: net.ParseIP("::ffff:1.2.3.4"), }} </s> remove func TestSetStaticIP_dhcpcdConfIface(t *testing.T) { testCases := []struct { name string dhcpcdConf string routers net.IP }{{ name: "with_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static routers=192.168.0.1` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: net.IP{192, 168, 0, 1}, }, { name: "without_gateway", dhcpcdConf: nl + `# wlan0 added by AdGuard Home.` + nl + `interface wlan0` + nl + `static ip_address=192.168.0.2/24` + nl + `static domain_name_servers=192.168.0.2` + nl + nl, routers: nil, }} ipNet := &net.IPNet{ IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 255, 0}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { s := dhcpcdConfIface("wlan0", ipNet, tc.routers, net.IP{192, 168, 0, 2}) assert.Equal(t, tc.dhcpcdConf, s) }) } } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
testCases := []struct { name string wantErrMsg string addrs []net.Addr wantAddrs []string }{{ name: "success", wantErrMsg: ``, addrs: []net.Addr{&net.IPNet{ IP: net.IP{1, 2, 3, 4}, Mask: net.CIDRMask(24, netutil.IPv4BitLen), }, &net.IPNet{ IP: net.IP{4, 3, 2, 1}, Mask: net.CIDRMask(16, netutil.IPv4BitLen), }}, wantAddrs: []string{"1.2.3.4", "4.3.2.1"}, }, { name: "not_cidr", wantErrMsg: `parsing cidr: invalid CIDR address: 1.2.3.4`, addrs: []net.Addr{&net.IPAddr{ IP: net.IP{1, 2, 3, 4}, }}, wantAddrs: nil, }, { name: "empty", wantErrMsg: ``, addrs: []net.Addr{}, wantAddrs: nil, }}
<mask> }) <mask> } <mask> <mask> func TestCollectAllIfacesAddrs(t *testing.T) { <mask> t.Skip("TODO(e.burkov): Substitute the net.Interfaces.") <mask> <mask> addrs, err := CollectAllIfacesAddrs() <mask> require.NoError(t, err) <mask> <mask> assert.NotEmpty(t, addrs) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs) </s> remove assert.NotEmpty(t, addrs) </s> add substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return nil, errAddrs }) _, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, wantErrMsg, err) }) </s> remove assert.Equal(t, tc.want, GatewayIP("ifaceName")) </s> add assert.Equal(t, tc.want, GatewayIP(ifaceName)) </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } })
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs)
<mask> <mask> func TestCollectAllIfacesAddrs(t *testing.T) { <mask> t.Skip("TODO(e.burkov): Substitute the net.Interfaces.") <mask> <mask> addrs, err := CollectAllIfacesAddrs() <mask> require.NoError(t, err) <mask> <mask> assert.NotEmpty(t, addrs) <mask> } <mask> <mask> func TestIsAddrInUse(t *testing.T) { </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove assert.NotEmpty(t, addrs) </s> add substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return nil, errAddrs }) _, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, wantErrMsg, err) }) </s> remove t.Skip("TODO(e.burkov): Substitute the net.Interfaces.") </s> add testCases := []struct { name string wantErrMsg string addrs []net.Addr wantAddrs []string }{{ name: "success", wantErrMsg: ``, addrs: []net.Addr{&net.IPNet{ IP: net.IP{1, 2, 3, 4}, Mask: net.CIDRMask(24, netutil.IPv4BitLen), }, &net.IPNet{ IP: net.IP{4, 3, 2, 1}, Mask: net.CIDRMask(16, netutil.IPv4BitLen), }}, wantAddrs: []string{"1.2.3.4", "4.3.2.1"}, }, { name: "not_cidr", wantErrMsg: `parsing cidr: invalid CIDR address: 1.2.3.4`, addrs: []net.Addr{&net.IPAddr{ IP: net.IP{1, 2, 3, 4}, }}, wantAddrs: nil, }, { name: "empty", wantErrMsg: ``, addrs: []net.Addr{}, wantAddrs: nil, }} </s> remove assert.Equal(t, tc.want, GatewayIP("ifaceName")) </s> add assert.Equal(t, tc.want, GatewayIP(ifaceName)) </s> remove func TestRcConfStaticConfig(t *testing.T) { </s> add func TestIfaceHasStaticIP(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return nil, errAddrs }) _, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, wantErrMsg, err) })
<mask> <mask> addrs, err := CollectAllIfacesAddrs() <mask> require.NoError(t, err) <mask> <mask> assert.NotEmpty(t, addrs) <mask> } <mask> <mask> func TestIsAddrInUse(t *testing.T) { <mask> t.Run("addr_in_use", func(t *testing.T) { <mask> l, err := net.Listen("tcp", "0.0.0.0:0") </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove addrs, err := CollectAllIfacesAddrs() require.NoError(t, err) </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { substNetInterfaceAddrs(t, func() ([]net.Addr, error) { return tc.addrs, nil }) addrs, err := CollectAllIfacesAddrs() testutil.AssertErrorMsg(t, tc.wantErrMsg, err) assert.Equal(t, tc.wantAddrs, addrs) }) } t.Run("internal_error", func(t *testing.T) { const errAddrs errors.Error = "can't get addresses" const wantErrMsg string = `getting interfaces addresses: ` + string(errAddrs) </s> remove t.Skip("TODO(e.burkov): Substitute the net.Interfaces.") </s> add testCases := []struct { name string wantErrMsg string addrs []net.Addr wantAddrs []string }{{ name: "success", wantErrMsg: ``, addrs: []net.Addr{&net.IPNet{ IP: net.IP{1, 2, 3, 4}, Mask: net.CIDRMask(24, netutil.IPv4BitLen), }, &net.IPNet{ IP: net.IP{4, 3, 2, 1}, Mask: net.CIDRMask(16, netutil.IPv4BitLen), }}, wantAddrs: []string{"1.2.3.4", "4.3.2.1"}, }, { name: "not_cidr", wantErrMsg: `parsing cidr: invalid CIDR address: 1.2.3.4`, addrs: []net.Addr{&net.IPAddr{ IP: net.IP{1, 2, 3, 4}, }}, wantAddrs: nil, }, { name: "empty", wantErrMsg: ``, addrs: []net.Addr{}, wantAddrs: nil, }} </s> remove assert.Equal(t, tc.want, GatewayIP("ifaceName")) </s> add assert.Equal(t, tc.want, GatewayIP(ifaceName)) </s> remove for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } </s> add for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { hostname := GenerateHostname(tc.ip) assert.Equal(t, tc.want, hostname) }) } }) t.Run("invalid", func(t *testing.T) { testCases := []struct { name string ip net.IP }{{ name: "bad_ipv4", ip: net.IP{127, 0, 0, 1, 0}, }, { name: "bad_ipv6", ip: net.IP{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }, }, { name: "nil", ip: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { assert.Panics(t, func() { GenerateHostname(tc.ip) }) }) } })
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_test.go
<mask> "github.com/AdguardTeam/golibs/errors" <mask> "golang.org/x/sys/windows" <mask> ) <mask> <mask> func canBindPrivilegedPorts() (can bool, err error) { <mask> return aghos.HaveAdminRights() <mask> } <mask> <mask> func ifaceHasStaticIP(string) (ok bool, err error) { <mask> return false, aghos.Unsupported("checking static ip") <mask> } <mask> <mask> func ifaceSetStaticIP(string) (err error) { </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { return aghos.HaveAdminRights() } </s> add </s> remove // CanBindPort checks if we can bind to the given port. func CanBindPort(port int) (can bool, err error) { var addr *net.TCPAddr addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false, err } var listener *net.TCPListener listener, err = net.ListenTCP("tcp", addr) if err != nil { return false, err } _ = listener.Close() return true, nil } </s> add </s> remove func canBindPrivilegedPorts() (can bool, err error) { cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0) // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() return cnbs == 1 || adm, err } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/aghnet/net_windows.go
if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil {
<mask> // Check if the current user permissions are enough to run AdGuard Home <mask> func checkPermissions() { <mask> log.Info("Checking if AdGuard Home has necessary permissions") <mask> <mask> if runtime.GOOS == "windows" { <mask> // On Windows we need to have admin rights to run properly <mask> <mask> admin, _ := aghos.HaveAdminRights() <mask> if admin { <mask> return <mask> } <mask> <mask> log.Fatal("This is the first launch of AdGuard Home. You must run it as Administrator.") <mask> } <mask> <mask> // We should check if AdGuard Home is able to bind to port 53 <mask> ok, err := aghnet.CanBindPort(53) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove ok, err := aghnet.CanBindPort(53) if ok { log.Info("AdGuard Home can bind to port 53") return } if errors.Is(err, os.ErrPermission) { msg := `Permission check failed. </s> add err := aghnet.CheckPort("tcp", net.IP{127, 0, 0, 1}, defaultPortDNS) if err != nil { if errors.Is(err, os.ErrPermission) { log.Fatal(`Permission check failed. </s> remove https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser` </s> add https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser`) } </s> remove log.Fatal(msg) </s> add log.Info( "AdGuard failed to bind to port 53: %s\n\n"+ "Please note, that this is crucial for a DNS server to be able to use that port.", err, ) </s> remove msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v Please note, that this is crucial for a DNS server to be able to use that port.`, err) log.Info(msg) </s> add log.Info("AdGuard Home can bind to port 53") </s> remove // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand </s> add // Variables and functions to substitute in tests. var ( // aghosRunCommand is the function to run shell commands. aghosRunCommand = aghos.RunCommand
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/home/home.go
err := aghnet.CheckPort("tcp", net.IP{127, 0, 0, 1}, defaultPortDNS) if err != nil { if errors.Is(err, os.ErrPermission) { log.Fatal(`Permission check failed.
<mask> log.Fatal("This is the first launch of AdGuard Home. You must run it as Administrator.") <mask> } <mask> <mask> // We should check if AdGuard Home is able to bind to port 53 <mask> ok, err := aghnet.CanBindPort(53) <mask> <mask> if ok { <mask> log.Info("AdGuard Home can bind to port 53") <mask> return <mask> } <mask> <mask> if errors.Is(err, os.ErrPermission) { <mask> msg := `Permission check failed. <mask> <mask> AdGuard Home is not allowed to bind to privileged ports (for instance, port 53). <mask> Please note, that this is crucial for a server to be able to use privileged ports. <mask> <mask> You have two options: </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove if runtime.GOOS == "windows" { // On Windows we need to have admin rights to run properly admin, _ := aghos.HaveAdminRights() if admin { return } </s> add if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil { </s> remove msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v Please note, that this is crucial for a DNS server to be able to use that port.`, err) log.Info(msg) </s> add log.Info("AdGuard Home can bind to port 53") </s> remove log.Fatal(msg) </s> add log.Info( "AdGuard failed to bind to port 53: %s\n\n"+ "Please note, that this is crucial for a DNS server to be able to use that port.", err, ) </s> remove https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser` </s> add https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser`) } </s> remove // aghosRunCommand is the function to run shell commands. It's an unexported // variable instead of a direct call to make it substitutable in tests. var aghosRunCommand = aghos.RunCommand </s> add // Variables and functions to substitute in tests. var ( // aghosRunCommand is the function to run shell commands. aghosRunCommand = aghos.RunCommand
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/home/home.go
https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser`) }
<mask> <mask> You have two options: <mask> 1. Run AdGuard Home with root privileges <mask> 2. On Linux you can grant the CAP_NET_BIND_SERVICE capability: <mask> https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser` <mask> <mask> log.Fatal(msg) <mask> } <mask> <mask> msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove log.Fatal(msg) </s> add log.Info( "AdGuard failed to bind to port 53: %s\n\n"+ "Please note, that this is crucial for a DNS server to be able to use that port.", err, ) </s> remove msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v Please note, that this is crucial for a DNS server to be able to use that port.`, err) log.Info(msg) </s> add log.Info("AdGuard Home can bind to port 53") </s> remove ok, err := aghnet.CanBindPort(53) if ok { log.Info("AdGuard Home can bind to port 53") return } if errors.Is(err, os.ErrPermission) { msg := `Permission check failed. </s> add err := aghnet.CheckPort("tcp", net.IP{127, 0, 0, 1}, defaultPortDNS) if err != nil { if errors.Is(err, os.ErrPermission) { log.Fatal(`Permission check failed. </s> remove if runtime.GOOS == "windows" { // On Windows we need to have admin rights to run properly admin, _ := aghos.HaveAdminRights() if admin { return } </s> add if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil { </s> remove // CanBindPort checks if we can bind to the given port. func CanBindPort(port int) (can bool, err error) { var addr *net.TCPAddr addr, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { return false, err } var listener *net.TCPListener listener, err = net.ListenTCP("tcp", addr) if err != nil { return false, err } _ = listener.Close() return true, nil } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/home/home.go
log.Info( "AdGuard failed to bind to port 53: %s\n\n"+ "Please note, that this is crucial for a DNS server to be able to use that port.", err, )
<mask> 1. Run AdGuard Home with root privileges <mask> 2. On Linux you can grant the CAP_NET_BIND_SERVICE capability: <mask> https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser` <mask> <mask> log.Fatal(msg) <mask> } <mask> <mask> msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v <mask> <mask> Please note, that this is crucial for a DNS server to be able to use that port.`, err) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser` </s> add https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser`) } </s> remove msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v Please note, that this is crucial for a DNS server to be able to use that port.`, err) log.Info(msg) </s> add log.Info("AdGuard Home can bind to port 53") </s> remove ok, err := aghnet.CanBindPort(53) if ok { log.Info("AdGuard Home can bind to port 53") return } if errors.Is(err, os.ErrPermission) { msg := `Permission check failed. </s> add err := aghnet.CheckPort("tcp", net.IP{127, 0, 0, 1}, defaultPortDNS) if err != nil { if errors.Is(err, os.ErrPermission) { log.Fatal(`Permission check failed. </s> remove if runtime.GOOS == "windows" { // On Windows we need to have admin rights to run properly admin, _ := aghos.HaveAdminRights() if admin { return } </s> add if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil { </s> remove // rootDirFS is the filesystem pointing to the root directory. It's an // unexported variable instead to make it substitutable in tests. var rootDirFS = aghos.RootDirFS() </s> add // netInterfaces is the function to get the available network interfaces. netInterfaceAddrs = net.InterfaceAddrs // rootDirFS is the filesystem pointing to the root directory. rootDirFS = aghos.RootDirFS() )
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/home/home.go
log.Info("AdGuard Home can bind to port 53")
<mask> <mask> log.Fatal(msg) <mask> } <mask> <mask> msg := fmt.Sprintf(`AdGuard failed to bind to port 53 due to %v <mask> <mask> Please note, that this is crucial for a DNS server to be able to use that port.`, err) <mask> <mask> log.Info(msg) <mask> } <mask> <mask> // Write PID to a file <mask> func writePIDFile(fn string) bool { <mask> data := fmt.Sprintf("%d", os.Getpid()) </s> Pull request: 2846 cover aghnet vol.4 Merge in DNS/adguard-home from 2846-cover-aghnet-vol.4 to master Updates #2846. Squashed commit of the following: commit 576ef857628a403ce1478c10a4aad23985c09613 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 19:38:57 2022 +0300 aghnet: imp code commit 5b4b17ff52867aaab2c9d30a0fc7fc2fe31ff4d5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 31 14:58:34 2022 +0300 aghnet: imp coverage </s> remove log.Fatal(msg) </s> add log.Info( "AdGuard failed to bind to port 53: %s\n\n"+ "Please note, that this is crucial for a DNS server to be able to use that port.", err, ) </s> remove ok, err := aghnet.CanBindPort(53) if ok { log.Info("AdGuard Home can bind to port 53") return } if errors.Is(err, os.ErrPermission) { msg := `Permission check failed. </s> add err := aghnet.CheckPort("tcp", net.IP{127, 0, 0, 1}, defaultPortDNS) if err != nil { if errors.Is(err, os.ErrPermission) { log.Fatal(`Permission check failed. </s> remove https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser` </s> add https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#running-without-superuser`) } </s> remove if runtime.GOOS == "windows" { // On Windows we need to have admin rights to run properly admin, _ := aghos.HaveAdminRights() if admin { return } </s> add if ok, err := aghnet.CanBindPrivilegedPorts(); !ok || err != nil { </s> remove func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gatewayIP, dnsIP net.IP) (conf string) { var body []byte add := fmt.Sprintf( "\n# %[1]s added by AdGuard Home.\ninterface %[1]s\nstatic ip_address=%s\n", </s> add func dhcpcdConfIface(ifaceName string, ipNet *net.IPNet, gwIP net.IP) (conf string) { b := &strings.Builder{} stringutil.WriteToBuilder( b, "\n# ",
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c70f941bf87b92d819e6a7adf5255bc43404b026
internal/home/home.go
github.com/AdguardTeam/urlfilter v0.11.1
<mask> <mask> require ( <mask> github.com/AdguardTeam/dnsproxy v0.29.1 <mask> github.com/AdguardTeam/golibs v0.4.2 <mask> github.com/AdguardTeam/urlfilter v0.11.0 <mask> github.com/NYTimes/gziphandler v1.1.1 <mask> github.com/fsnotify/fsnotify v1.4.7 <mask> github.com/gobuffalo/packr v1.30.1 <mask> github.com/joomcode/errorx v1.0.1 <mask> github.com/kardianos/service v1.1.0 </s> * use urlfilter v0.11.1 Squashed commit of the following: commit 35d2c34355b093ec1daa40f156809a7cae089c20 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jul 23 18:00:43 2020 +0300 * use urlfilter v0.11.1 </s> remove github.com/AdguardTeam/urlfilter v0.11.0 h1:tgZss6uZs1UZAaxpovD/QuX+VVIQLDOlKc7rdF8dwNw= github.com/AdguardTeam/urlfilter v0.11.0/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY= </s> add github.com/AdguardTeam/urlfilter v0.11.1 h1:XQvPVqRPekqIj3xkH7V3NdvMO1InTm8KKQPVcFHFAn0= github.com/AdguardTeam/urlfilter v0.11.1/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY= </s> remove log.Debug("Using settings for client with IP %s", clientAddr) </s> add log.Debug("Using settings for client %s with IP %s", c.Name, clientAddr)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71b8d3ad2196743d0d82c09e7bad16621729b39
go.mod
github.com/AdguardTeam/urlfilter v0.11.1 h1:XQvPVqRPekqIj3xkH7V3NdvMO1InTm8KKQPVcFHFAn0= github.com/AdguardTeam/urlfilter v0.11.1/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY=
<mask> github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o= <mask> github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= <mask> github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= <mask> github.com/AdguardTeam/urlfilter v0.11.0 h1:tgZss6uZs1UZAaxpovD/QuX+VVIQLDOlKc7rdF8dwNw= <mask> github.com/AdguardTeam/urlfilter v0.11.0/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY= <mask> github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= <mask> github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= <mask> github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= <mask> github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= <mask> github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= </s> * use urlfilter v0.11.1 Squashed commit of the following: commit 35d2c34355b093ec1daa40f156809a7cae089c20 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jul 23 18:00:43 2020 +0300 * use urlfilter v0.11.1 </s> remove github.com/AdguardTeam/urlfilter v0.11.0 </s> add github.com/AdguardTeam/urlfilter v0.11.1 </s> remove log.Debug("Using settings for client with IP %s", clientAddr) </s> add log.Debug("Using settings for client %s with IP %s", c.Name, clientAddr)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71b8d3ad2196743d0d82c09e7bad16621729b39
go.sum
log.Debug("Using settings for client %s with IP %s", c.Name, clientAddr)
<mask> if !ok { <mask> return <mask> } <mask> <mask> log.Debug("Using settings for client with IP %s", clientAddr) <mask> <mask> if c.UseOwnBlockedServices { <mask> Context.dnsFilter.ApplyBlockedServices(setts, c.BlockedServices, false) <mask> } <mask> </s> * use urlfilter v0.11.1 Squashed commit of the following: commit 35d2c34355b093ec1daa40f156809a7cae089c20 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jul 23 18:00:43 2020 +0300 * use urlfilter v0.11.1 </s> remove github.com/AdguardTeam/urlfilter v0.11.0 h1:tgZss6uZs1UZAaxpovD/QuX+VVIQLDOlKc7rdF8dwNw= github.com/AdguardTeam/urlfilter v0.11.0/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY= </s> add github.com/AdguardTeam/urlfilter v0.11.1 h1:XQvPVqRPekqIj3xkH7V3NdvMO1InTm8KKQPVcFHFAn0= github.com/AdguardTeam/urlfilter v0.11.1/go.mod h1:aMuejlNxpWppOVjiEV87X6z0eMf7wsXHTAIWQuylfZY= </s> remove github.com/AdguardTeam/urlfilter v0.11.0 </s> add github.com/AdguardTeam/urlfilter v0.11.1
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71b8d3ad2196743d0d82c09e7bad16621729b39
home/dns.go
func TestSafeSearchCacheYandex(t *testing.T) {
<mask> } <mask> } <mask> } <mask> <mask> func TestSafeSearchCacheYandex (t *testing.T) { <mask> d := NewForTest() <mask> defer d.Destroy() <mask> domain := "yandex.ru" <mask> <mask> // Check host with disabled safesearch </s> Fix race in safesearch tests </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) { </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) } </s> remove func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { </s> add func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsfilter/dnsfilter_test.go
var result Result var err error
<mask> defer d.Destroy() <mask> domain := "yandex.ru" <mask> <mask> // Check host with disabled safesearch <mask> result, err = d.CheckHost(domain) <mask> if err != nil { <mask> t.Fatalf("Cannot check host due to %s", err) <mask> } <mask> if result.IP != nil { </s> Fix race in safesearch tests </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) } </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) { </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) { </s> remove func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { </s> add func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsfilter/dnsfilter_test.go
result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) }
<mask> defer d.Destroy() <mask> domain := "yandex.ru" <mask> <mask> // Check host with disabled safesearch <mask> result, err := d.CheckHost(domain) <mask> if result.IP != nil { <mask> t.Fatalf("SafeSearch is not enabled but there is an answer for `%s` !", domain) <mask> } <mask> <mask> // Enable safesearch </s> Fix race in safesearch tests </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) { </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) { </s> remove exchangeAndAssertResponse(t, client, addr, host, ip.String()) </s> add exchangeAndAssertResponse(t, &client, addr, host, ip.String())
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsfilter/dnsfilter_test.go
func TestSafeSearchCacheGoogle(t *testing.T) {
<mask> t.Fatalf("Wrong IP in cache for %s safesearch: %s", domain, cachedValue.IP.String()) <mask> } <mask> } <mask> <mask> func TestSafeSearchCacheGoogle (t *testing.T) { <mask> d := NewForTest() <mask> defer d.Destroy() <mask> domain := "www.google.ru" <mask> result, err := d.CheckHost(domain) <mask> if result.IP != nil { </s> Fix race in safesearch tests </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) { </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) } </s> remove func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { </s> add func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsfilter/dnsfilter_test.go
if err != nil { t.Fatalf("Cannot check host due to %s", err) }
<mask> defer d.Destroy() <mask> domain := "www.google.ru" <mask> result, err := d.CheckHost(domain) <mask> if result.IP != nil { <mask> t.Fatalf("SafeSearch is not enabled but there is an answer!") <mask> } <mask> <mask> // Enable safesearch and check host </s> Fix race in safesearch tests </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) } </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) { </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) { </s> remove func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { </s> add func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsfilter/dnsfilter_test.go
"yandex.com": "213.180.193.56", "yandex.ru": "213.180.193.56", "yandex.ua": "213.180.193.56", "yandex.by": "213.180.193.56", "yandex.kz": "213.180.193.56",
<mask> package dnsfilter <mask> <mask> var safeSearchDomains = map[string]string{ <mask> "yandex.com": "213.180.193.56", <mask> "yandex.ru": "213.180.193.56", <mask> "yandex.ua": "213.180.193.56", <mask> "yandex.by": "213.180.193.56", <mask> "yandex.kz": "213.180.193.56", <mask> "www.yandex.com": "213.180.193.56", <mask> "www.yandex.ru": "213.180.193.56", <mask> "www.yandex.ua": "213.180.193.56", <mask> "www.yandex.by": "213.180.193.56", <mask> "www.yandex.kz": "213.180.193.56", </s> Fix race in safesearch tests </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) }
[ "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsfilter/safesearch.go
exchangeAndAssertResponse(t, &client, addr, host, "213.180.193.56")
<mask> addr := s.dnsProxy.Addr(proxy.ProtoUDP) <mask> client := dns.Client{Net: "udp"} <mask> yandexDomains := []string{"yandex.com.", "yandex.by.", "yandex.kz.", "yandex.ru.", "yandex.com."} <mask> for _, host := range yandexDomains { <mask> exchangeAndAssertResponse(t, client, addr, host, "213.180.193.56") <mask> } <mask> <mask> // Check aggregated stats <mask> assert.Equal(t, s.GetAggregatedStats()["replaced_safesearch"], float64(len(yandexDomains))) <mask> assert.Equal(t, s.GetAggregatedStats()["blocked_filtering"], float64(len(yandexDomains))) </s> Fix race in safesearch tests </s> remove exchangeAndAssertResponse(t, client, addr, host, ip.String()) </s> add exchangeAndAssertResponse(t, &client, addr, host, ip.String()) </s> remove exchangeAndAssertResponse(t, client, addr, "google-public-dns-a.google.com.", "8.8.8.8") </s> add exchangeAndAssertResponse(t, &client, addr, "google-public-dns-a.google.com.", "8.8.8.8") </s> remove func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { </s> add func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) { </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) { </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsforward/dnsforward_test.go
exchangeAndAssertResponse(t, &client, addr, host, ip.String())
<mask> <mask> // Test safe search for google. <mask> googleDomains := []string{"www.google.com.", "www.google.com.af.", "www.google.be.", "www.google.by."} <mask> for _, host := range googleDomains { <mask> exchangeAndAssertResponse(t, client, addr, host, ip.String()) <mask> } <mask> <mask> // Check aggregated stats <mask> assert.Equal(t, s.GetAggregatedStats()["replaced_safesearch"], float64(len(yandexDomains)+len(googleDomains))) <mask> assert.Equal(t, s.GetAggregatedStats()["blocked_filtering"], float64(len(yandexDomains)+len(googleDomains))) </s> Fix race in safesearch tests </s> remove exchangeAndAssertResponse(t, client, addr, "google-public-dns-a.google.com.", "8.8.8.8") </s> add exchangeAndAssertResponse(t, &client, addr, "google-public-dns-a.google.com.", "8.8.8.8") </s> remove exchangeAndAssertResponse(t, client, addr, host, "213.180.193.56") </s> add exchangeAndAssertResponse(t, &client, addr, host, "213.180.193.56") </s> remove func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { </s> add func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) { </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) } </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsforward/dnsforward_test.go
exchangeAndAssertResponse(t, &client, addr, "google-public-dns-a.google.com.", "8.8.8.8")
<mask> assert.Equal(t, s.GetAggregatedStats()["blocked_filtering"], float64(len(yandexDomains)+len(googleDomains))) <mask> assert.Equal(t, s.GetAggregatedStats()["dns_queries"], float64(len(yandexDomains)+len(googleDomains))) <mask> <mask> // Do one more exchange <mask> exchangeAndAssertResponse(t, client, addr, "google-public-dns-a.google.com.", "8.8.8.8") <mask> <mask> // Check aggregated stats <mask> assert.Equal(t, s.GetAggregatedStats()["replaced_safesearch"], float64(len(yandexDomains)+len(googleDomains))) <mask> assert.Equal(t, s.GetAggregatedStats()["blocked_filtering"], float64(len(yandexDomains)+len(googleDomains))) <mask> assert.Equal(t, s.GetAggregatedStats()["dns_queries"], float64(len(yandexDomains)+len(googleDomains)+1)) </s> Fix race in safesearch tests </s> remove exchangeAndAssertResponse(t, client, addr, host, ip.String()) </s> add exchangeAndAssertResponse(t, &client, addr, host, ip.String()) </s> remove exchangeAndAssertResponse(t, client, addr, host, "213.180.193.56") </s> add exchangeAndAssertResponse(t, &client, addr, host, "213.180.193.56") </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) } </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsforward/dnsforward_test.go
func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) {
<mask> assertGoogleAResponse(t, res) <mask> } <mask> } <mask> <mask> func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { <mask> req := createTestMessage(host) <mask> reply, _, err := client.Exchange(req, addr.String()) <mask> if err != nil { <mask> t.Fatalf("Couldn't talk to server %s: %s", addr, err) <mask> } </s> Fix race in safesearch tests </s> remove exchangeAndAssertResponse(t, client, addr, host, "213.180.193.56") </s> add exchangeAndAssertResponse(t, &client, addr, host, "213.180.193.56") </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) } </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsforward/dnsforward_test.go
periodic.Lock()
<mask> <mask> func initPeriodicStats(periodic *periodicStats, period time.Duration) { <mask> periodic.entries = statsEntries{} <mask> periodic.lastRotate = time.Now() <mask> periodic.period = period <mask> periodic.Unlock() </s> Fix race in safesearch tests </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) { </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) {
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsforward/stats.go
periodic.Unlock()
<mask> periodic.lastRotate = time.Now() <mask> periodic.period = period <mask> } <mask> <mask> func (s *stats) purgeStats() { <mask> initPeriodicStats(&s.perSecond, time.Second) </s> Fix race in safesearch tests </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) { </s> remove func TestSafeSearchCacheGoogle (t *testing.T) { </s> add func TestSafeSearchCacheGoogle(t *testing.T) { </s> remove func exchangeAndAssertResponse(t *testing.T, client dns.Client, addr net.Addr, host, ip string) { </s> add func exchangeAndAssertResponse(t *testing.T, client *dns.Client, addr net.Addr, host, ip string) {
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsforward/stats.go
stats.RLock() defer stats.RUnlock()
<mask> } <mask> <mask> func (s *stats) generateMapFromStats(stats *periodicStats, start int, end int) map[string]interface{} { <mask> // clamp <mask> start = clamp(start, 0, statsHistoryElements) <mask> end = clamp(end, 0, statsHistoryElements) <mask> </s> Fix race in safesearch tests </s> remove func TestSafeSearchCacheYandex (t *testing.T) { </s> add func TestSafeSearchCacheYandex(t *testing.T) { </s> remove result, err := d.CheckHost(domain) </s> add result, err = d.CheckHost(domain) if err != nil { t.Fatalf("Cannot check host due to %s", err) }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c71d6ed4334287b01b5c41db7597d4e5f060e06a
dnsforward/stats.go
"client_not_in_allowed_clients": "The client is not allowed because it is not in the \"Allowed clients\" list.",
<mask> "original_response": "Original response", <mask> "click_to_view_queries": "Click to view queries", <mask> "port_53_faq_link": "Port 53 is often occupied by \"DNSStubListener\" or \"systemd-resolved\" services. Please read <0>this instruction</0> on how to resolve this.", <mask> "adg_will_drop_dns_queries": "AdGuard Home will be dropping all DNS queries from this client.", <mask> "experimental": "Experimental" <mask> } </s> + client: Move the client access check to the server-side Squashed commit of the following: commit 1aab0f62e94ce665a1b996552fac41dc4e769b4d Merge: cdf5eb6e c1f5fdae Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 24 15:36:05 2020 +0300 Merge branch '1920-client-find' into feature/1925 commit cdf5eb6ea67a665d21a3155d8cf89bba9a5a9948 Merge: b6c20b1c 10f67bd3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 23 20:28:51 2020 +0300 Merge branch 'master' into feature/1925 commit b6c20b1c7359a0e5902405b0551712f936848a80 Merge: 97d388ef 96512433 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:44:25 2020 +0300 Merge branch 'master' into feature/1925 commit 97d388ef6571d590f21da00f86d889e881ca0c3d Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:30:50 2020 +0300 Extract buttons commit ca45fde11fc2b2812ff2b84dbd67aff0b5341be1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:46:09 2020 +0300 Handle errors in updateLogs commit f15e03c2e5a7115db984f70f72b0ddd870ece73d Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:39:34 2020 +0300 Update mobile block status on click commit 033b28db3b324f6d529ac1a0ef657886cdbe02bd Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 20:53:42 2020 +0300 Fix mobile block buttons, auto open page on web serve start commit 2730937b23309167a066b9154728ac53ffe81a49 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:58:37 2020 +0300 Disable allow this client button when isNotInAllowedList is true commit 818cf869d63654c184762ad2701c4429a3e3011e Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:06:01 2020 +0300 Update client block state on option click commit a072b8983757f419645c0207ea78e6e867c440cb Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 20:17:16 2020 +0300 Adapt to api changes commit 28ab2bd8b3f14f60bc822b5a69fa1801db67d816 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 14:12:20 2020 +0300 Change query log block confirm messages commit 9b0b6f6f9b1ec168fa71dbedd036152da59006e3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 12:00:46 2020 +0300 Refactor inner work with disallowed commit 05f76154b8f489738d032fdaa835edb371ce70c7 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Sep 7 16:11:37 2020 +0300 + client: Move the client access check to the server-side </s> remove /** * The purpose of this method is to quickly check * if this IP can possibly be in the specified CIDR range. * * @param ip {string} * @param listItem {string} * @returns {boolean} */ const isIpQuickMatchCIDR = (ip, listItem) => { const ipv6 = ip.indexOf(':') !== -1; const cidrIpv6 = listItem.indexOf(':') !== -1; if (ipv6 !== cidrIpv6) { // CIDR is for a different IP type return false; } if (cidrIpv6) { // We don't do quick check for IPv6 addresses return true; } const idx = listItem.indexOf('/'); if (idx === -1) { // Not a CIDR, return false immediately return false; } const cidrIp = listItem.substring(0, idx); const cidrRange = parseInt(listItem.substring(idx + 1), 10); if (Number.isNaN(cidrRange)) { // Not a valid CIDR return false; } const parts = cidrIp.split('.'); if (parts.length !== 4) { // Invalid IP, return immediately return false; } // Now depending on the range we check if the IP can possibly be in that range if (cidrRange < 8) { // Use the slow approach return true; } if (cidrRange < 16) { // Check the first part // Example: 0.0.0.0/8 matches 0.*.*.* return ip.indexOf(`${parts[0]}.`) === 0; } if (cidrRange < 24) { // Check the first two parts // Example: 0.0.0.0/16 matches 0.0.*.* return ip.indexOf(`${parts[0]}.${parts[1]}.`) === 0; } if (cidrRange <= 32) { // Check the first two parts // Example: 0.0.0.0/16 matches 0.0.*.* return ip.indexOf(`${parts[0]}.${parts[1]}.${parts[2]}.`) === 0; } // range for IPv4 CIDR cannot be more than 32 // no need to check further, this CIDR is invalid return false; }; </s> add </s> remove import { countClientsStatistics, findAddressType, getIpMatchListStatus, sortIp, } from '../helpers/helpers'; import { ADDRESS_TYPES, IP_MATCH_LIST_STATUS } from '../helpers/constants'; describe('getIpMatchListStatus', () => { describe('IPv4', () => { test('should return EXACT on find the exact ip match', () => { const list = `127.0.0.2 2001:db8:11a3:9d7:0:0:0:0 192.168.0.1/8 127.0.0.1 127.0.0.3`; expect(getIpMatchListStatus('127.0.0.1', list)) .toEqual(IP_MATCH_LIST_STATUS.EXACT); }); test('should return CIDR on find the cidr match', () => { const list = `127.0.0.2 2001:db8:11a3:9d7:0:0:0:0 192.168.0.1/8 127.0.0.0/24 127.0.0.3`; expect(getIpMatchListStatus('127.0.0.1', list)) .toEqual(IP_MATCH_LIST_STATUS.CIDR); }); test('should return NOT_FOUND if the ip is not in the list', () => { const list = `127.0.0.1 2001:db8:11a3:9d7:0:0:0:0 192.168.0.1/8 127.0.0.2 127.0.0.3`; expect(getIpMatchListStatus('127.0.0.4', list)) .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); }); test('should return the first EXACT or CIDR match in the list', () => { const list1 = `2001:db8:11a3:9d7:0:0:0:0 127.0.0.1 127.0.0.8/24 127.0.0.3`; expect(getIpMatchListStatus('127.0.0.1', list1)) .toEqual(IP_MATCH_LIST_STATUS.EXACT); const list2 = `2001:db8:11a3:9d7:ffff:ffff:ffff:ffff 2001:0db8:11a3:09d7:0000:0000:0000:0000/64 127.0.0.0/24 127.0.0.1 127.0.0.8/24 127.0.0.3`; expect(getIpMatchListStatus('127.0.0.1', list2)) .toEqual(IP_MATCH_LIST_STATUS.CIDR); }); }); describe('IPv6', () => { test('should return EXACT on find the exact ip match', () => { const list = `127.0.0.0 2001:db8:11a3:9d7:0:0:0:0 2001:db8:11a3:9d7:ffff:ffff:ffff:ffff 127.0.0.1`; expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list)) .toEqual(IP_MATCH_LIST_STATUS.EXACT); }); test('should return EXACT on find the exact ip match of short and long notation', () => { const list = `127.0.0.0 192.168.0.1/8 2001:db8:: 127.0.0.2`; expect(getIpMatchListStatus('2001:db8:0:0:0:0:0:0', list)) .toEqual(IP_MATCH_LIST_STATUS.EXACT); }); test('should return CIDR on find the cidr match', () => { const list1 = `2001:0db8:11a3:09d7:0000:0000:0000:0000/64 127.0.0.1 127.0.0.2`; expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list1)) .toEqual(IP_MATCH_LIST_STATUS.CIDR); const list2 = `2001:0db8::/16 127.0.0.0 2001:db8:11a3:9d7:0:0:0:0 2001:db8:: 2001:db8:11a3:9d7:ffff:ffff:ffff:ffff 127.0.0.1`; expect(getIpMatchListStatus('2001:db1::', list2)) .toEqual(IP_MATCH_LIST_STATUS.CIDR); }); test('should return NOT_FOUND if the ip is not in the list', () => { const list = `2001:db8:11a3:9d7:0:0:0:0 2001:0db8:11a3:09d7:0000:0000:0000:0000/64 127.0.0.1 127.0.0.2`; expect(getIpMatchListStatus('::', list)) .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); }); test('should return the first EXACT or CIDR match in the list', () => { const list1 = `2001:db8:11a3:9d7:0:0:0:0 2001:0db8:11a3:09d7:0000:0000:0000:0000/64 127.0.0.3`; expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list1)) .toEqual(IP_MATCH_LIST_STATUS.EXACT); const list2 = `2001:0db8:11a3:09d7:0000:0000:0000:0000/64 2001:db8:11a3:9d7:0:0:0:0 127.0.0.3`; expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list2)) .toEqual(IP_MATCH_LIST_STATUS.CIDR); }); }); describe('Empty list or IP', () => { test('should return NOT_FOUND on empty ip', () => { const list = `127.0.0.0 2001:db8:11a3:9d7:0:0:0:0 2001:db8:11a3:9d7:ffff:ffff:ffff:ffff 127.0.0.1`; expect(getIpMatchListStatus('', list)) .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); }); test('should return NOT_FOUND on empty list', () => { const list = ''; expect(getIpMatchListStatus('127.0.0.1', list)) .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); }); }); }); </s> add import { sortIp, countClientsStatistics, findAddressType } from '../helpers/helpers'; import { ADDRESS_TYPES } from '../helpers/constants'; </s> remove /** * @param ip {string} * @param list {string} * @returns {'EXACT' | 'CIDR' | 'NOT_FOND'} */ export const getIpMatchListStatus = (ip, list) => { if (!ip || !list) { return IP_MATCH_LIST_STATUS.NOT_FOUND; } const listArr = list.trim() .split('\n'); try { for (let i = 0; i < listArr.length; i += 1) { const listItem = listArr[i]; if (ip === listItem.trim()) { return IP_MATCH_LIST_STATUS.EXACT; } // Using ipaddr.js is quite slow so we first do a quick check // to see if it's possible that this IP may be in the specified CIDR range if (isIpQuickMatchCIDR(ip, listItem)) { const parsedIp = ipaddr.parse(ip); const isItemAnIp = ipaddr.isValid(listItem); const parsedItem = isItemAnIp ? ipaddr.parse(listItem) : ipaddr.parseCIDR(listItem); if (isItemAnIp && parsedIp.toString() === parsedItem.toString()) { return IP_MATCH_LIST_STATUS.EXACT; } if (!isItemAnIp && isIpMatchCidr(parsedIp, parsedItem)) { return IP_MATCH_LIST_STATUS.CIDR; } } } return IP_MATCH_LIST_STATUS.NOT_FOUND; } catch (e) { console.error(e); return IP_MATCH_LIST_STATUS.NOT_FOUND; } }; </s> add </s> remove import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; import { BLOCK_ACTIONS, IP_MATCH_LIST_STATUS, STATUS_COLORS } from '../../helpers/constants'; </s> add import { getPercent, sortIp } from '../../helpers/helpers'; import { BLOCK_ACTIONS, STATUS_COLORS } from '../../helpers/constants';
[ "keep", "keep", "keep", "add", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c72cd58f69b71e4981d8b182b2f7d53ea5e30868
client/src/__locales/en.json
import { sortIp, countClientsStatistics, findAddressType } from '../helpers/helpers'; import { ADDRESS_TYPES } from '../helpers/constants';
<mask> import { <mask> countClientsStatistics, findAddressType, getIpMatchListStatus, sortIp, <mask> } from '../helpers/helpers'; <mask> import { ADDRESS_TYPES, IP_MATCH_LIST_STATUS } from '../helpers/constants'; <mask> <mask> describe('getIpMatchListStatus', () => { <mask> describe('IPv4', () => { <mask> test('should return EXACT on find the exact ip match', () => { <mask> const list = `127.0.0.2 <mask> 2001:db8:11a3:9d7:0:0:0:0 <mask> 192.168.0.1/8 <mask> 127.0.0.1 <mask> 127.0.0.3`; <mask> expect(getIpMatchListStatus('127.0.0.1', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.EXACT); <mask> }); <mask> <mask> test('should return CIDR on find the cidr match', () => { <mask> const list = `127.0.0.2 <mask> 2001:db8:11a3:9d7:0:0:0:0 <mask> 192.168.0.1/8 <mask> 127.0.0.0/24 <mask> 127.0.0.3`; <mask> expect(getIpMatchListStatus('127.0.0.1', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.CIDR); <mask> }); <mask> <mask> test('should return NOT_FOUND if the ip is not in the list', () => { <mask> const list = `127.0.0.1 <mask> 2001:db8:11a3:9d7:0:0:0:0 <mask> 192.168.0.1/8 <mask> 127.0.0.2 <mask> 127.0.0.3`; <mask> expect(getIpMatchListStatus('127.0.0.4', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); <mask> }); <mask> <mask> test('should return the first EXACT or CIDR match in the list', () => { <mask> const list1 = `2001:db8:11a3:9d7:0:0:0:0 <mask> 127.0.0.1 <mask> 127.0.0.8/24 <mask> 127.0.0.3`; <mask> expect(getIpMatchListStatus('127.0.0.1', list1)) <mask> .toEqual(IP_MATCH_LIST_STATUS.EXACT); <mask> <mask> const list2 = `2001:db8:11a3:9d7:ffff:ffff:ffff:ffff <mask> 2001:0db8:11a3:09d7:0000:0000:0000:0000/64 <mask> 127.0.0.0/24 <mask> 127.0.0.1 <mask> 127.0.0.8/24 <mask> 127.0.0.3`; <mask> expect(getIpMatchListStatus('127.0.0.1', list2)) <mask> .toEqual(IP_MATCH_LIST_STATUS.CIDR); <mask> }); <mask> }); <mask> <mask> describe('IPv6', () => { <mask> test('should return EXACT on find the exact ip match', () => { <mask> const list = `127.0.0.0 <mask> 2001:db8:11a3:9d7:0:0:0:0 <mask> 2001:db8:11a3:9d7:ffff:ffff:ffff:ffff <mask> 127.0.0.1`; <mask> expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.EXACT); <mask> }); <mask> <mask> test('should return EXACT on find the exact ip match of short and long notation', () => { <mask> const list = `127.0.0.0 <mask> 192.168.0.1/8 <mask> 2001:db8:: <mask> 127.0.0.2`; <mask> expect(getIpMatchListStatus('2001:db8:0:0:0:0:0:0', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.EXACT); <mask> }); <mask> <mask> test('should return CIDR on find the cidr match', () => { <mask> const list1 = `2001:0db8:11a3:09d7:0000:0000:0000:0000/64 <mask> 127.0.0.1 <mask> 127.0.0.2`; <mask> expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list1)) <mask> .toEqual(IP_MATCH_LIST_STATUS.CIDR); <mask> <mask> const list2 = `2001:0db8::/16 <mask> 127.0.0.0 <mask> 2001:db8:11a3:9d7:0:0:0:0 <mask> 2001:db8:: <mask> 2001:db8:11a3:9d7:ffff:ffff:ffff:ffff <mask> 127.0.0.1`; <mask> expect(getIpMatchListStatus('2001:db1::', list2)) <mask> .toEqual(IP_MATCH_LIST_STATUS.CIDR); <mask> }); <mask> <mask> test('should return NOT_FOUND if the ip is not in the list', () => { <mask> const list = `2001:db8:11a3:9d7:0:0:0:0 <mask> 2001:0db8:11a3:09d7:0000:0000:0000:0000/64 <mask> 127.0.0.1 <mask> 127.0.0.2`; <mask> expect(getIpMatchListStatus('::', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); <mask> }); <mask> <mask> test('should return the first EXACT or CIDR match in the list', () => { <mask> const list1 = `2001:db8:11a3:9d7:0:0:0:0 <mask> 2001:0db8:11a3:09d7:0000:0000:0000:0000/64 <mask> 127.0.0.3`; <mask> expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list1)) <mask> .toEqual(IP_MATCH_LIST_STATUS.EXACT); <mask> <mask> const list2 = `2001:0db8:11a3:09d7:0000:0000:0000:0000/64 <mask> 2001:db8:11a3:9d7:0:0:0:0 <mask> 127.0.0.3`; <mask> expect(getIpMatchListStatus('2001:db8:11a3:9d7:0:0:0:0', list2)) <mask> .toEqual(IP_MATCH_LIST_STATUS.CIDR); <mask> }); <mask> }); <mask> <mask> describe('Empty list or IP', () => { <mask> test('should return NOT_FOUND on empty ip', () => { <mask> const list = `127.0.0.0 <mask> 2001:db8:11a3:9d7:0:0:0:0 <mask> 2001:db8:11a3:9d7:ffff:ffff:ffff:ffff <mask> 127.0.0.1`; <mask> expect(getIpMatchListStatus('', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); <mask> }); <mask> <mask> test('should return NOT_FOUND on empty list', () => { <mask> const list = ''; <mask> expect(getIpMatchListStatus('127.0.0.1', list)) <mask> .toEqual(IP_MATCH_LIST_STATUS.NOT_FOUND); <mask> }); <mask> }); <mask> }); <mask> <mask> describe('sortIp', () => { <mask> describe('ipv4', () => { <mask> test('one octet differ', () => { <mask> const arr = [ </s> + client: Move the client access check to the server-side Squashed commit of the following: commit 1aab0f62e94ce665a1b996552fac41dc4e769b4d Merge: cdf5eb6e c1f5fdae Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 24 15:36:05 2020 +0300 Merge branch '1920-client-find' into feature/1925 commit cdf5eb6ea67a665d21a3155d8cf89bba9a5a9948 Merge: b6c20b1c 10f67bd3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 23 20:28:51 2020 +0300 Merge branch 'master' into feature/1925 commit b6c20b1c7359a0e5902405b0551712f936848a80 Merge: 97d388ef 96512433 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:44:25 2020 +0300 Merge branch 'master' into feature/1925 commit 97d388ef6571d590f21da00f86d889e881ca0c3d Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:30:50 2020 +0300 Extract buttons commit ca45fde11fc2b2812ff2b84dbd67aff0b5341be1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:46:09 2020 +0300 Handle errors in updateLogs commit f15e03c2e5a7115db984f70f72b0ddd870ece73d Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:39:34 2020 +0300 Update mobile block status on click commit 033b28db3b324f6d529ac1a0ef657886cdbe02bd Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 20:53:42 2020 +0300 Fix mobile block buttons, auto open page on web serve start commit 2730937b23309167a066b9154728ac53ffe81a49 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:58:37 2020 +0300 Disable allow this client button when isNotInAllowedList is true commit 818cf869d63654c184762ad2701c4429a3e3011e Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:06:01 2020 +0300 Update client block state on option click commit a072b8983757f419645c0207ea78e6e867c440cb Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 20:17:16 2020 +0300 Adapt to api changes commit 28ab2bd8b3f14f60bc822b5a69fa1801db67d816 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 14:12:20 2020 +0300 Change query log block confirm messages commit 9b0b6f6f9b1ec168fa71dbedd036152da59006e3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 12:00:46 2020 +0300 Refactor inner work with disallowed commit 05f76154b8f489738d032fdaa835edb371ce70c7 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Sep 7 16:11:37 2020 +0300 + client: Move the client access check to the server-side </s> remove export const IP_MATCH_LIST_STATUS = { NOT_FOUND: 'NOT_FOUND', // not found in the list EXACT: 'EXACT', // found exact match (including the match of short and long forms) CIDR: 'CIDR', // the ip is in the specified CIDR range }; </s> add </s> remove dispatch(toggleClientBlock(type, ip)); </s> add await dispatch(toggleClientBlock(ip, disallowed, disallowed_rule)); await dispatch(getStats()); </s> remove const toggleClientStatus = (type, ip) => { const confirmMessage = type === BLOCK_ACTIONS.BLOCK ? `${t('adg_will_drop_dns_queries')} ${t('client_confirm_block', { ip })}` : t('client_confirm_unblock', { ip }); </s> add const toggleClientStatus = async (ip, disallowed, disallowed_rule) => { const confirmMessage = disallowed ? t('client_confirm_unblock', { ip: disallowed_rule }) : `${t('adg_will_drop_dns_queries')} ${t('client_confirm_block', { ip })}`; </s> remove /** * The purpose of this method is to quickly check * if this IP can possibly be in the specified CIDR range. * * @param ip {string} * @param listItem {string} * @returns {boolean} */ const isIpQuickMatchCIDR = (ip, listItem) => { const ipv6 = ip.indexOf(':') !== -1; const cidrIpv6 = listItem.indexOf(':') !== -1; if (ipv6 !== cidrIpv6) { // CIDR is for a different IP type return false; } if (cidrIpv6) { // We don't do quick check for IPv6 addresses return true; } const idx = listItem.indexOf('/'); if (idx === -1) { // Not a CIDR, return false immediately return false; } const cidrIp = listItem.substring(0, idx); const cidrRange = parseInt(listItem.substring(idx + 1), 10); if (Number.isNaN(cidrRange)) { // Not a valid CIDR return false; } const parts = cidrIp.split('.'); if (parts.length !== 4) { // Invalid IP, return immediately return false; } // Now depending on the range we check if the IP can possibly be in that range if (cidrRange < 8) { // Use the slow approach return true; } if (cidrRange < 16) { // Check the first part // Example: 0.0.0.0/8 matches 0.*.*.* return ip.indexOf(`${parts[0]}.`) === 0; } if (cidrRange < 24) { // Check the first two parts // Example: 0.0.0.0/16 matches 0.0.*.* return ip.indexOf(`${parts[0]}.${parts[1]}.`) === 0; } if (cidrRange <= 32) { // Check the first two parts // Example: 0.0.0.0/16 matches 0.0.*.* return ip.indexOf(`${parts[0]}.${parts[1]}.${parts[2]}.`) === 0; } // range for IPv4 CIDR cannot be more than 32 // no need to check further, this CIDR is invalid return false; }; </s> add </s> remove /** * @param ip {string} * @param list {string} * @returns {'EXACT' | 'CIDR' | 'NOT_FOND'} */ export const getIpMatchListStatus = (ip, list) => { if (!ip || !list) { return IP_MATCH_LIST_STATUS.NOT_FOUND; } const listArr = list.trim() .split('\n'); try { for (let i = 0; i < listArr.length; i += 1) { const listItem = listArr[i]; if (ip === listItem.trim()) { return IP_MATCH_LIST_STATUS.EXACT; } // Using ipaddr.js is quite slow so we first do a quick check // to see if it's possible that this IP may be in the specified CIDR range if (isIpQuickMatchCIDR(ip, listItem)) { const parsedIp = ipaddr.parse(ip); const isItemAnIp = ipaddr.isValid(listItem); const parsedItem = isItemAnIp ? ipaddr.parse(listItem) : ipaddr.parseCIDR(listItem); if (isItemAnIp && parsedIp.toString() === parsedItem.toString()) { return IP_MATCH_LIST_STATUS.EXACT; } if (!isItemAnIp && isIpMatchCidr(parsedIp, parsedItem)) { return IP_MATCH_LIST_STATUS.CIDR; } } } return IP_MATCH_LIST_STATUS.NOT_FOUND; } catch (e) { console.error(e); return IP_MATCH_LIST_STATUS.NOT_FOUND; } }; </s> add
[ "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "rep...
https://github.com/AdguardTeam/AdGuardHome/commit/c72cd58f69b71e4981d8b182b2f7d53ea5e30868
client/src/__tests__/helpers.test.js
<mask> import i18next from 'i18next'; <mask> <mask> import apiClient from '../api/Api'; <mask> import { addErrorToast, addSuccessToast } from './toasts'; <mask> import { BLOCK_ACTIONS } from '../helpers/constants'; <mask> import { splitByNewLine } from '../helpers/helpers'; <mask> <mask> export const getAccessListRequest = createAction('GET_ACCESS_LIST_REQUEST'); <mask> export const getAccessListFailure = createAction('GET_ACCESS_LIST_FAILURE'); <mask> export const getAccessListSuccess = createAction('GET_ACCESS_LIST_SUCCESS'); </s> + client: Move the client access check to the server-side Squashed commit of the following: commit 1aab0f62e94ce665a1b996552fac41dc4e769b4d Merge: cdf5eb6e c1f5fdae Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 24 15:36:05 2020 +0300 Merge branch '1920-client-find' into feature/1925 commit cdf5eb6ea67a665d21a3155d8cf89bba9a5a9948 Merge: b6c20b1c 10f67bd3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 23 20:28:51 2020 +0300 Merge branch 'master' into feature/1925 commit b6c20b1c7359a0e5902405b0551712f936848a80 Merge: 97d388ef 96512433 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:44:25 2020 +0300 Merge branch 'master' into feature/1925 commit 97d388ef6571d590f21da00f86d889e881ca0c3d Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:30:50 2020 +0300 Extract buttons commit ca45fde11fc2b2812ff2b84dbd67aff0b5341be1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:46:09 2020 +0300 Handle errors in updateLogs commit f15e03c2e5a7115db984f70f72b0ddd870ece73d Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:39:34 2020 +0300 Update mobile block status on click commit 033b28db3b324f6d529ac1a0ef657886cdbe02bd Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 20:53:42 2020 +0300 Fix mobile block buttons, auto open page on web serve start commit 2730937b23309167a066b9154728ac53ffe81a49 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:58:37 2020 +0300 Disable allow this client button when isNotInAllowedList is true commit 818cf869d63654c184762ad2701c4429a3e3011e Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:06:01 2020 +0300 Update client block state on option click commit a072b8983757f419645c0207ea78e6e867c440cb Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 20:17:16 2020 +0300 Adapt to api changes commit 28ab2bd8b3f14f60bc822b5a69fa1801db67d816 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 14:12:20 2020 +0300 Change query log block confirm messages commit 9b0b6f6f9b1ec168fa71dbedd036152da59006e3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 12:00:46 2020 +0300 Refactor inner work with disallowed commit 05f76154b8f489738d032fdaa835edb371ce70c7 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Sep 7 16:11:37 2020 +0300 + client: Move the client access check to the server-side </s> remove import { getIpMatchListStatus } from '../../../../helpers/helpers'; import { BLOCK_ACTIONS, IP_MATCH_LIST_STATUS } from '../../../../helpers/constants'; </s> add import i18next from 'i18next'; </s> remove import { getPercent, getIpMatchListStatus, sortIp } from '../../helpers/helpers'; import { BLOCK_ACTIONS, IP_MATCH_LIST_STATUS, STATUS_COLORS } from '../../helpers/constants'; </s> add import { getPercent, sortIp } from '../../helpers/helpers'; import { BLOCK_ACTIONS, STATUS_COLORS } from '../../helpers/constants';
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c72cd58f69b71e4981d8b182b2f7d53ea5e30868
client/src/actions/access.js
export const toggleClientBlock = (ip, disallowed, disallowed_rule) => async (dispatch) => {
<mask> export const toggleClientBlockRequest = createAction('TOGGLE_CLIENT_BLOCK_REQUEST'); <mask> export const toggleClientBlockFailure = createAction('TOGGLE_CLIENT_BLOCK_FAILURE'); <mask> export const toggleClientBlockSuccess = createAction('TOGGLE_CLIENT_BLOCK_SUCCESS'); <mask> <mask> export const toggleClientBlock = (type, ip) => async (dispatch) => { <mask> dispatch(toggleClientBlockRequest()); <mask> try { <mask> const { <mask> allowed_clients, disallowed_clients, blocked_hosts, <mask> } = await apiClient.getAccessList(); </s> + client: Move the client access check to the server-side Squashed commit of the following: commit 1aab0f62e94ce665a1b996552fac41dc4e769b4d Merge: cdf5eb6e c1f5fdae Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 24 15:36:05 2020 +0300 Merge branch '1920-client-find' into feature/1925 commit cdf5eb6ea67a665d21a3155d8cf89bba9a5a9948 Merge: b6c20b1c 10f67bd3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 23 20:28:51 2020 +0300 Merge branch 'master' into feature/1925 commit b6c20b1c7359a0e5902405b0551712f936848a80 Merge: 97d388ef 96512433 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:44:25 2020 +0300 Merge branch 'master' into feature/1925 commit 97d388ef6571d590f21da00f86d889e881ca0c3d Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:30:50 2020 +0300 Extract buttons commit ca45fde11fc2b2812ff2b84dbd67aff0b5341be1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:46:09 2020 +0300 Handle errors in updateLogs commit f15e03c2e5a7115db984f70f72b0ddd870ece73d Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:39:34 2020 +0300 Update mobile block status on click commit 033b28db3b324f6d529ac1a0ef657886cdbe02bd Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 20:53:42 2020 +0300 Fix mobile block buttons, auto open page on web serve start commit 2730937b23309167a066b9154728ac53ffe81a49 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:58:37 2020 +0300 Disable allow this client button when isNotInAllowedList is true commit 818cf869d63654c184762ad2701c4429a3e3011e Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:06:01 2020 +0300 Update client block state on option click commit a072b8983757f419645c0207ea78e6e867c440cb Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 20:17:16 2020 +0300 Adapt to api changes commit 28ab2bd8b3f14f60bc822b5a69fa1801db67d816 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 14:12:20 2020 +0300 Change query log block confirm messages commit 9b0b6f6f9b1ec168fa71dbedd036152da59006e3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 12:00:46 2020 +0300 Refactor inner work with disallowed commit 05f76154b8f489738d032fdaa835edb371ce70c7 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Sep 7 16:11:37 2020 +0300 + client: Move the client access check to the server-side </s> remove allowed_clients, disallowed_clients, blocked_hosts, </s> add allowed_clients, blocked_hosts, disallowed_clients = [], </s> remove let updatedDisallowedClients = disallowed_clients || []; </s> add </s> remove if (type === BLOCK_ACTIONS.UNBLOCK && updatedDisallowedClients.includes(ip)) { updatedDisallowedClients = updatedDisallowedClients.filter((client) => client !== ip); } else if (type === BLOCK_ACTIONS.BLOCK && !updatedDisallowedClients.includes(ip)) { updatedDisallowedClients.push(ip); } </s> add const updatedDisallowedClients = disallowed ? disallowed_clients.filter((client) => client !== disallowed_rule) : disallowed_clients.concat(ip); </s> remove export const getBlockClientInfo = (client, disallowed_clients) => { const ipMatchListStatus = getIpMatchListStatus(client, disallowed_clients); </s> add export const getBlockClientInfo = (ip, disallowed, disallowed_rule) => { const confirmMessage = disallowed ? i18next.t('client_confirm_unblock', { ip: disallowed_rule }) : `${i18next.t('adg_will_drop_dns_queries')} ${i18next.t('client_confirm_block', { ip })}`; </s> remove import { getIpMatchListStatus } from '../../../../helpers/helpers'; import { BLOCK_ACTIONS, IP_MATCH_LIST_STATUS } from '../../../../helpers/constants'; </s> add import i18next from 'i18next';
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c72cd58f69b71e4981d8b182b2f7d53ea5e30868
client/src/actions/access.js
allowed_clients, blocked_hosts, disallowed_clients = [],
<mask> export const toggleClientBlock = (type, ip) => async (dispatch) => { <mask> dispatch(toggleClientBlockRequest()); <mask> try { <mask> const { <mask> allowed_clients, disallowed_clients, blocked_hosts, <mask> } = await apiClient.getAccessList(); <mask> let updatedDisallowedClients = disallowed_clients || []; <mask> <mask> if (type === BLOCK_ACTIONS.UNBLOCK && updatedDisallowedClients.includes(ip)) { <mask> updatedDisallowedClients = updatedDisallowedClients.filter((client) => client !== ip); </s> + client: Move the client access check to the server-side Squashed commit of the following: commit 1aab0f62e94ce665a1b996552fac41dc4e769b4d Merge: cdf5eb6e c1f5fdae Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 24 15:36:05 2020 +0300 Merge branch '1920-client-find' into feature/1925 commit cdf5eb6ea67a665d21a3155d8cf89bba9a5a9948 Merge: b6c20b1c 10f67bd3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 23 20:28:51 2020 +0300 Merge branch 'master' into feature/1925 commit b6c20b1c7359a0e5902405b0551712f936848a80 Merge: 97d388ef 96512433 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:44:25 2020 +0300 Merge branch 'master' into feature/1925 commit 97d388ef6571d590f21da00f86d889e881ca0c3d Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 15 10:30:50 2020 +0300 Extract buttons commit ca45fde11fc2b2812ff2b84dbd67aff0b5341be1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:46:09 2020 +0300 Handle errors in updateLogs commit f15e03c2e5a7115db984f70f72b0ddd870ece73d Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Sep 10 12:39:34 2020 +0300 Update mobile block status on click commit 033b28db3b324f6d529ac1a0ef657886cdbe02bd Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 20:53:42 2020 +0300 Fix mobile block buttons, auto open page on web serve start commit 2730937b23309167a066b9154728ac53ffe81a49 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:58:37 2020 +0300 Disable allow this client button when isNotInAllowedList is true commit 818cf869d63654c184762ad2701c4429a3e3011e Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Sep 9 13:06:01 2020 +0300 Update client block state on option click commit a072b8983757f419645c0207ea78e6e867c440cb Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 20:17:16 2020 +0300 Adapt to api changes commit 28ab2bd8b3f14f60bc822b5a69fa1801db67d816 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 14:12:20 2020 +0300 Change query log block confirm messages commit 9b0b6f6f9b1ec168fa71dbedd036152da59006e3 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Sep 8 12:00:46 2020 +0300 Refactor inner work with disallowed commit 05f76154b8f489738d032fdaa835edb371ce70c7 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Sep 7 16:11:37 2020 +0300 + client: Move the client access check to the server-side </s> remove let updatedDisallowedClients = disallowed_clients || []; </s> add </s> remove if (type === BLOCK_ACTIONS.UNBLOCK && updatedDisallowedClients.includes(ip)) { updatedDisallowedClients = updatedDisallowedClients.filter((client) => client !== ip); } else if (type === BLOCK_ACTIONS.BLOCK && !updatedDisallowedClients.includes(ip)) { updatedDisallowedClients.push(ip); } </s> add const updatedDisallowedClients = disallowed ? disallowed_clients.filter((client) => client !== disallowed_rule) : disallowed_clients.concat(ip); </s> remove export const toggleClientBlock = (type, ip) => async (dispatch) => { </s> add export const toggleClientBlock = (ip, disallowed, disallowed_rule) => async (dispatch) => { </s> remove const toggleClientStatus = (type, ip) => { const confirmMessage = type === BLOCK_ACTIONS.BLOCK ? `${t('adg_will_drop_dns_queries')} ${t('client_confirm_block', { ip })}` : t('client_confirm_unblock', { ip }); </s> add const toggleClientStatus = async (ip, disallowed, disallowed_rule) => { const confirmMessage = disallowed ? t('client_confirm_unblock', { ip: disallowed_rule }) : `${t('adg_will_drop_dns_queries')} ${t('client_confirm_block', { ip })}`; </s> remove const onBlockingClientClick = () => { const message = `${blockType === BLOCK_ACTIONS.BLOCK ? t('adg_will_drop_dns_queries') : ''} ${t(confirmMessage, { ip: client })}`; if (window.confirm(message)) { dispatch(toggleClientBlock(blockType, client)); </s> add const onBlockingClientClick = async () => { if (window.confirm(confirmMessage)) { await dispatch(toggleClientBlock(client, disallowed, disallowed_rule)); await dispatch(updateLogs()); setModalOpened(false);
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/c72cd58f69b71e4981d8b182b2f7d53ea5e30868
client/src/actions/access.js