testenv

package
v0.0.0-...-a67a4a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package testenv for creating mosquitto testing environment

Index

Constants

View Source
const (
	MqttPortUnpw = 9883
	MqttPortCert = 9884
	MqttPortWS   = 9885
)

MQTT ports for test environment in the 9xxx range

View Source
const OUDevice = "iotdevice"
View Source
const OUPlugin = "plugin"

FIXME: These OU names must match that in certsetup

View Source
const ServerAddress = "127.0.0.1"

Variables

This section is empty.

Functions

func CreateCA

func CreateCA() (caCert *x509.Certificate, caKey *ecdsa.PrivateKey)

CreateCA generates the CA keys with certificate for testing not intended for production

func CreateMosquittoConf

func CreateMosquittoConf(configFolder string, certFolder string) string

Createa mosquitto.conf file for testing

func CreateTlsCert

func CreateTlsCert(cn string, ou string, isServer bool, clientKey *ecdsa.PrivateKey,
	caCert *x509.Certificate, caKey *ecdsa.PrivateKey) (tlscert *tls.Certificate)

CreateTlsCert generates the certificate with keys, signed by the CA, valid for 127.0.0.1 intended for testing, not for production

cn is the certificate common name, usually the client ID or server hostname
ou the organization
isServer if set allow key usage of ServerAuth instead of ClientAuth
clientKey is the client's private key for this certificate
caCert and caKey is the signing CA

func CreateX509Cert

func CreateX509Cert(cn string, ou string, isServer bool, pubKey *ecdsa.PublicKey,
	caCert *x509.Certificate, caKey *ecdsa.PrivateKey) (cert *x509.Certificate, derBytes []byte, err error)

CreateX509Cert generates a x509 certificate with keys, signed by the CA, valid for 127.0.0.1 intended for testing, not for production

cn is the certificate common name, usually the client ID or server hostname
ou the organization
isServer if set allow key usage of ServerAuth instead of ClientAuth
pubKey is the owner public key for this certificate
caCert and caKey is the signing CA

func SaveCerts

func SaveCerts(testCerts *TestCerts, certFolder string)

SaveCerts saves the given CA and mosquitto server key and certificates as PEM files

func SetLogging

func SetLogging(levelName string, filename string)

SetLogging sets the logging level and output file This sets the timeFormat to ISO8601 YYYY-MM-DDTHH:MM:SS.sss-TZ Intended for standardize logging in the hub and plugins

levelName is the requested logging level: error, warning, info, debug
filename is the output log file full name including path, use "" for stderr

func StartMosquitto

func StartMosquitto(configFolder string, certFolder string, testCerts *TestCerts) (mqCmd *exec.Cmd, err error)

StartMosquitto create a test environment with a mosquitto broker on localhost for the given home folder This:

  1. Saves the CA, server and client certificates in the certFolder
  2. Generates a mosquitto configuration in the config folder
  3. Launches a mosquitto broker for testing.

mqCmd.Process.Kill() to end the mosquitto broker

configFolder is the location to generate mosquitto configuration
certFolder is the location to save the certificates
certsclient are the certificates to use.

Returns the mosquitto process

func StopMosquitto

func StopMosquitto(cmd *exec.Cmd)

StopMosquitto the test environment and stop the mosquitto broker

Types

type TestCerts

type TestCerts struct {
	CaCert    *x509.Certificate
	CaKey     *ecdsa.PrivateKey
	ServerKey *ecdsa.PrivateKey
	DeviceKey *ecdsa.PrivateKey
	PluginKey *ecdsa.PrivateKey

	ServerCert *tls.Certificate
	PluginCert *tls.Certificate
	DeviceCert *tls.Certificate
}

Test certificates for CA, server and plugin (client)

func CreateCertBundle

func CreateCertBundle() TestCerts

CreateCertBundle creates new certificates for CA, Server, Plugin and Thing Device testing The server cert is valid for localhost only

this returns the x509 and tls certificates

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL