Skip to content
Snippets Groups Projects
Verified Commit 0d3d6253 authored by Pea Nut's avatar Pea Nut
Browse files

Add tests for IsValidCert

parent c9c4f665
Branches main
No related tags found
No related merge requests found
Pipeline #225899 passed
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")
}
// TODO: make this backend agnostic, currently only works with menshen https://0xacab.org/leap/bitmask-vpn/-/issues/825
//func TestIsValidCertFromMenshenValid(t *testing.T) {
// // needs API_URL="http://localhost:8443" via env
// m, err := menshen.New()
// require.NoError(t, err, "Could not create menshen instance")
//
// tmpFile, err := ioutil.TempFile(os.TempDir(), "leap-client-cert.pem")
// require.NoError(t, err, "Could not create tmp file for OpenVPN client credentials")
// defer os.Remove(tmpFile.Name())
//
// cert, err := m.GetPemCertificate()
// require.NoError(t, err, "Could not get PEM certificate from menshen")
//
// _, err = tmpFile.Write(cert)
// require.NoError(t, err, "Could not write to tmp OpenVPN client credentials file")
//
// assert.True(t, isValidCert(tmpFile.Name()), "PEM file from Menshen is not a valid certificate")
//}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment