From 1d242ea1524012c9549275d36d46b6da4b50a7f0 Mon Sep 17 00:00:00 2001
From: Pea Nut <peanut2@systemli.org>
Date: Fri, 14 Jun 2024 10:48:18 +0200
Subject: [PATCH] Add tests for IsValidCert

---
 pkg/vpn/utils_test.go | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 pkg/vpn/utils_test.go

diff --git a/pkg/vpn/utils_test.go b/pkg/vpn/utils_test.go
new file mode 100644
index 00000000..a0aba263
--- /dev/null
+++ b/pkg/vpn/utils_test.go
@@ -0,0 +1,35 @@
+package vpn
+
+import (
+	"os"
+	"testing"
+
+	"github.com/rs/zerolog"
+	"github.com/rs/zerolog/log"
+	"github.com/stretchr/testify/require"
+)
+
+func init() {
+	log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
+}
+
+func TestIsValidCertExpired(t *testing.T) {
+	certFile := "testdata/expired.pem"
+	require.False(t, isValidCert(certFile), "The test with the expired pem failed")
+}
+
+func TestIsValidCertEmpty(t *testing.T) {
+	certFile := "testdata/empty.pem"
+	require.False(t, isValidCert(certFile), "The test with the empty pem file failed")
+}
+
+func TestIsValidCertKeyMissing(t *testing.T) {
+	certFile := "testdata/privatekeymissing.pem"
+	require.False(t, isValidCert(certFile), "The test with the missing private key failed")
+}
+
+func TestIsValidCertBroken(t *testing.T) {
+	certFile := "testdata/broken.pem"
+	require.False(t, isValidCert(certFile), "The test with the broken pem file failed")
+}
+
-- 
GitLab