mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 13:05:36 +03:00
c5565a9e4e
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
77 lines
3.1 KiB
Go
77 lines
3.1 KiB
Go
package home
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/AdguardTeam/golibs/testutil"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var testCertChainData = []byte(`-----BEGIN CERTIFICATE-----
|
|
MIICKzCCAZSgAwIBAgIJAMT9kPVJdM7LMA0GCSqGSIb3DQEBCwUAMC0xFDASBgNV
|
|
BAoMC0FkR3VhcmQgTHRkMRUwEwYDVQQDDAxBZEd1YXJkIEhvbWUwHhcNMTkwMjI3
|
|
MDkyNDIzWhcNNDYwNzE0MDkyNDIzWjAtMRQwEgYDVQQKDAtBZEd1YXJkIEx0ZDEV
|
|
MBMGA1UEAwwMQWRHdWFyZCBIb21lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
|
|
gQCwvwUnPJiOvLcOaWmGu6Y68ksFr13nrXBcsDlhxlXy8PaohVi3XxEmt2OrVjKW
|
|
QFw/bdV4fZ9tdWFAVRRkgeGbIZzP7YBD1Ore/O5SQ+DbCCEafvjJCcXQIrTeKFE6
|
|
i9G3aSMHs0Pwq2LgV8U5mYotLrvyFiE8QPInJbDDMpaFYwIDAQABo1MwUTAdBgNV
|
|
HQ4EFgQUdLUmQpEqrhn4eKO029jYd2AAZEQwHwYDVR0jBBgwFoAUdLUmQpEqrhn4
|
|
eKO029jYd2AAZEQwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQB8
|
|
LwlXfbakf7qkVTlCNXgoY7RaJ8rJdPgOZPoCTVToEhT6u/cb1c2qp8QB0dNExDna
|
|
b0Z+dnODTZqQOJo6z/wIXlcUrnR4cQVvytXt8lFn+26l6Y6EMI26twC/xWr+1swq
|
|
Muj4FeWHVDerquH4yMr1jsYLD3ci+kc5sbIX6TfVxQ==
|
|
-----END CERTIFICATE-----`)
|
|
|
|
var testPrivateKeyData = []byte(`-----BEGIN PRIVATE KEY-----
|
|
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALC/BSc8mI68tw5p
|
|
aYa7pjrySwWvXeetcFywOWHGVfLw9qiFWLdfESa3Y6tWMpZAXD9t1Xh9n211YUBV
|
|
FGSB4ZshnM/tgEPU6t787lJD4NsIIRp++MkJxdAitN4oUTqL0bdpIwezQ/CrYuBX
|
|
xTmZii0uu/IWITxA8iclsMMyloVjAgMBAAECgYEAmjzoG1h27UDkIlB9BVWl95TP
|
|
QVPLB81D267xNFDnWk1Lgr5zL/pnNjkdYjyjgpkBp1yKyE4gHV4skv5sAFWTcOCU
|
|
QCgfPfUn/rDFcxVzAdJVWAa/CpJNaZgjTPR8NTGU+Ztod+wfBESNCP5tbnuw0GbL
|
|
MuwdLQJGbzeJYpsNysECQQDfFHYoRNfgxHwMbX24GCoNZIgk12uDmGTA9CS5E+72
|
|
9t3V1y4CfXxSkfhqNbd5RWrUBRLEw9BKofBS7L9NMDKDAkEAytQoIueE1vqEAaRg
|
|
a3A1YDUekKesU5wKfKfKlXvNgB7Hwh4HuvoQS9RCvVhf/60Dvq8KSu6hSjkFRquj
|
|
FQ5roQJBAMwKwyiCD5MfJPeZDmzcbVpiocRQ5Z4wPbffl9dRTDnIA5AciZDthlFg
|
|
An/jMjZSMCxNl6UyFcqt5Et1EGVhuFECQQCZLXxaT+qcyHjlHJTMzuMgkz1QFbEp
|
|
O5EX70gpeGQMPDK0QSWpaazg956njJSDbNCFM4BccrdQbJu1cW4qOsfBAkAMgZuG
|
|
O88slmgTRHX4JGFmy3rrLiHNI2BbJSuJ++Yllz8beVzh6NfvuY+HKRCmPqoBPATU
|
|
kXS9jgARhhiWXJrk
|
|
-----END PRIVATE KEY-----`)
|
|
|
|
func TestValidateCertificates(t *testing.T) {
|
|
t.Run("bad_certificate", func(t *testing.T) {
|
|
status := &tlsConfigStatus{}
|
|
err := validateCertificates(status, []byte("bad cert"), nil, "")
|
|
testutil.AssertErrorMsg(t, "empty certificate", err)
|
|
assert.False(t, status.ValidCert)
|
|
assert.False(t, status.ValidChain)
|
|
})
|
|
|
|
t.Run("bad_private_key", func(t *testing.T) {
|
|
status := &tlsConfigStatus{}
|
|
err := validateCertificates(status, nil, []byte("bad priv key"), "")
|
|
testutil.AssertErrorMsg(t, "no valid keys were found", err)
|
|
assert.False(t, status.ValidKey)
|
|
})
|
|
|
|
t.Run("valid", func(t *testing.T) {
|
|
status := &tlsConfigStatus{}
|
|
err := validateCertificates(status, testCertChainData, testPrivateKeyData, "")
|
|
assert.Error(t, err)
|
|
|
|
notBefore := time.Date(2019, 2, 27, 9, 24, 23, 0, time.UTC)
|
|
notAfter := time.Date(2046, 7, 14, 9, 24, 23, 0, time.UTC)
|
|
|
|
assert.True(t, status.ValidCert)
|
|
assert.False(t, status.ValidChain)
|
|
assert.True(t, status.ValidKey)
|
|
assert.Equal(t, "RSA", status.KeyType)
|
|
assert.Equal(t, "CN=AdGuard Home,O=AdGuard Ltd", status.Subject)
|
|
assert.Equal(t, "CN=AdGuard Home,O=AdGuard Ltd", status.Issuer)
|
|
assert.Equal(t, notBefore, status.NotBefore)
|
|
assert.Equal(t, notAfter, status.NotAfter)
|
|
assert.True(t, status.ValidPair)
|
|
})
|
|
}
|