49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package cm509
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"sigs.k8s.io/yaml"
|
|
)
|
|
|
|
func TestCertChainCheckerErr(t *testing.T) {
|
|
var err error
|
|
|
|
certBytes, err := os.ReadFile("testchain_a01.crt")
|
|
require.NoError(t, err)
|
|
require.NotZero(t, len(certBytes))
|
|
certObj, err := ParseEncodedCerificate(string(certBytes))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, certObj)
|
|
|
|
certStrings := make([]string, 0)
|
|
for i := 1; i < 4; i++ {
|
|
certBytes, err := os.ReadFile(fmt.Sprintf("testchain_a%02d.crt", i))
|
|
require.NoError(t, err)
|
|
require.NotZero(t, len(certBytes))
|
|
certString := base64.StdEncoding.EncodeToString(certBytes)
|
|
certStrings = append(certStrings, certString)
|
|
}
|
|
topIssuerCN := certObj.Issuer.String()
|
|
|
|
_, err = CheckDoubleEncodedCertificateChain(topIssuerCN, certStrings)
|
|
require.Error(t, err)
|
|
//require.NotNil(t, resString)
|
|
//require.NotZero(t, len(resString))
|
|
}
|
|
|
|
func printObj(label string, obj any) {
|
|
objBytes, _ := yaml.Marshal(obj)
|
|
objString := string(objBytes)
|
|
if strings.Count(objString, "\n") < 2 {
|
|
fmt.Printf("==== %s: %s\n", label, objString)
|
|
} else {
|
|
fmt.Printf("==== %s ::\n%s\n", label, objString)
|
|
}
|
|
}
|