package tls

import (
	"crypto/x509"
	"encoding/hex"
	"encoding/pem"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestCalculateCertHash(t *testing.T) {
	const Single = `-----BEGIN CERTIFICATE-----
[encoded data, 4615 characters]
7ykUutQNUALq8dQwoTnK
-----END CERTIFICATE-----

`
	t.Run("singlepublickey", func(t *testing.T) {
		block, _ := pem.Decode([]byte(Single))
		cert, err := x509.ParseCertificate(block.Bytes)
		assert.Equal(t, err, nil)
		hash := GenerateCertHash(cert)
		fingerprint, _ := hex.DecodeString("ae243d668ec9c7f74a0dcd1ad21c6676b4efe30c39728934b362093af886bf77")
		assert.Equal(t, fingerprint, hash)
	})
}
