2019-06-10 08:33:19 +00:00
|
|
|
package home
|
2019-02-27 10:07:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
/* Tests performed:
|
|
|
|
. Bad certificate
|
|
|
|
. Bad private key
|
|
|
|
. Valid certificate & private key */
|
|
|
|
func TestValidateCertificates(t *testing.T) {
|
2019-02-27 11:11:41 +00:00
|
|
|
var data tlsConfigStatus
|
2019-02-27 10:07:29 +00:00
|
|
|
|
|
|
|
// bad cert
|
2019-02-27 11:11:41 +00:00
|
|
|
data = validateCertificates("bad cert", "", "")
|
2019-02-27 10:07:29 +00:00
|
|
|
if !(data.WarningValidation != "" &&
|
|
|
|
!data.ValidCert &&
|
|
|
|
!data.ValidChain) {
|
|
|
|
t.Fatalf("bad cert: validateCertificates(): %v", data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// bad priv key
|
2019-02-27 11:11:41 +00:00
|
|
|
data = validateCertificates("", "bad priv key", "")
|
2019-02-27 10:07:29 +00:00
|
|
|
if !(data.WarningValidation != "" &&
|
|
|
|
!data.ValidKey) {
|
|
|
|
t.Fatalf("bad priv key: validateCertificates(): %v", data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// valid cert & priv key
|
2019-02-27 11:11:41 +00:00
|
|
|
CertificateChain := `-----BEGIN CERTIFICATE-----
|
2019-02-27 10:07:29 +00:00
|
|
|
MIICKzCCAZSgAwIBAgIJAMT9kPVJdM7LMA0GCSqGSIb3DQEBCwUAMC0xFDASBgNV
|
|
|
|
BAoMC0FkR3VhcmQgTHRkMRUwEwYDVQQDDAxBZEd1YXJkIEhvbWUwHhcNMTkwMjI3
|
|
|
|
MDkyNDIzWhcNNDYwNzE0MDkyNDIzWjAtMRQwEgYDVQQKDAtBZEd1YXJkIEx0ZDEV
|
|
|
|
MBMGA1UEAwwMQWRHdWFyZCBIb21lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
|
|
|
|
gQ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od+wfBESNCP5tbnuw0GbL
|
|
|
|
MuwdLQJGbzeJYpsNysECQQDfFHYoRNfgxHwMbX24GCoNZIgk12uDmGTA9CS5E+72
|
|
|
|
9t3V1y4CfXxSkfhqNbd5RWrUBRLEw9BKofBS7L9NMDKDAkEAytQoIueE1vqEAaRg
|
|
|
|
a3A1YDUekKesU5wKfKfKlXvNgB7Hwh4HuvoQS9RCvVhf/60Dvq8KSu6hSjkFRquj
|
|
|
|
FQ5roQJBAMwKwyiCD5MfJPeZDmzcbVpiocRQ5Z4wPbffl9dRTDnIA5AciZDthlFg
|
|
|
|
An/jMjZSMCxNl6UyFcqt5Et1EGVhuFECQQCZLXxaT+qcyHjlHJTMzuMgkz1QFbEp
|
|
|
|
O5EX70gpeGQMPDK0QSWpaazg956njJSDbNCFM4BccrdQbJu1cW4qOsfBAkAMgZuG
|
|
|
|
O88slmgTRHX4JGFmy3rrLiHNI2BbJSuJ++Yllz8beVzh6NfvuY+HKRCmPqoBPATU
|
|
|
|
kXS9jgARhhiWXJrk
|
|
|
|
-----END PRIVATE KEY-----`
|
2019-02-27 11:11:41 +00:00
|
|
|
data = validateCertificates(CertificateChain, PrivateKey, "")
|
2019-02-27 10:07:29 +00:00
|
|
|
notBefore, _ := time.Parse(time.RFC3339, "2019-02-27T09:24:23Z")
|
|
|
|
notAfter, _ := time.Parse(time.RFC3339, "2046-07-14T09:24:23Z")
|
|
|
|
if !(data.WarningValidation != "" /* self signed */ &&
|
|
|
|
data.ValidCert &&
|
|
|
|
!data.ValidChain &&
|
|
|
|
data.ValidKey &&
|
|
|
|
data.KeyType == "RSA" &&
|
|
|
|
data.Subject == "CN=AdGuard Home,O=AdGuard Ltd" &&
|
|
|
|
data.Issuer == "CN=AdGuard Home,O=AdGuard Ltd" &&
|
2021-01-15 17:30:48 +00:00
|
|
|
data.NotBefore.Equal(notBefore) &&
|
|
|
|
data.NotAfter.Equal(notAfter) &&
|
2019-02-27 10:07:29 +00:00
|
|
|
// data.DNSNames[0] == &&
|
2019-02-27 14:36:02 +00:00
|
|
|
data.ValidPair) {
|
2019-02-27 10:07:29 +00:00
|
|
|
t.Fatalf("valid cert & priv key: validateCertificates(): %v", data)
|
|
|
|
}
|
|
|
|
}
|