Display SSL expiry warnings (#2925)

This commit is contained in:
Mateusz Gajewski
2016-10-14 13:48:08 +02:00
committed by Harshavardhana
parent 0320a77dc0
commit c03ce0f74a
11 changed files with 752 additions and 6 deletions

View File

@@ -17,8 +17,12 @@
package cmd
import (
"crypto/x509"
"crypto/x509/pkix"
"fmt"
"strings"
"testing"
"time"
)
// Tests if we generate storage info.
@@ -39,3 +43,52 @@ func TestStorageInfoMsg(t *testing.T) {
t.Fatal("Empty message string is not implemented", msg)
}
}
// Tests if certificate expiry warning will be printed
func TestCertificateExpiryInfo(t *testing.T) {
// given
var expiredDate = time.Now().Add(time.Hour * 24 * (globalMinioCertExpireWarnDays - 1))
var fakeCerts = []*x509.Certificate{
&x509.Certificate{
NotAfter: expiredDate,
Subject: pkix.Name{
CommonName: "Test cert",
},
},
}
expectedMsg := colorBlue("\nCertificate expiry info:\n") +
colorBold(fmt.Sprintf("#1 Test cert will expire on %s\n", expiredDate))
// when
msg := getCertificateChainMsg(fakeCerts)
// then
if msg != expectedMsg {
t.Fatalf("Expected message was: %s, got: %s", expectedMsg, msg)
}
}
// Tests if certificate expiry warning will not be printed if certificate not expired
func TestCertificateNotExpired(t *testing.T) {
// given
var expiredDate = time.Now().Add(time.Hour * 24 * (globalMinioCertExpireWarnDays + 1))
var fakeCerts = []*x509.Certificate{
&x509.Certificate{
NotAfter: expiredDate,
Subject: pkix.Name{
CommonName: "Test cert",
},
},
}
// when
msg := getCertificateChainMsg(fakeCerts)
// then
if msg != "" {
t.Fatalf("Expected empty message was: %s", msg)
}
}