Documentation ¶
Overview ¶
Package testenv for creating mosquitto testing environment
Index ¶
- Constants
- func CreateCA() (caCert *x509.Certificate, caKey *ecdsa.PrivateKey)
- func CreateMosquittoConf(configFolder string, certFolder string) string
- func CreateTlsCert(cn string, ou string, isServer bool, clientKey *ecdsa.PrivateKey, ...) (tlscert *tls.Certificate)
- func CreateX509Cert(cn string, ou string, isServer bool, pubKey *ecdsa.PublicKey, ...) (cert *x509.Certificate, derBytes []byte, err error)
- func SaveCerts(testCerts *TestCerts, certFolder string)
- func SetLogging(levelName string, filename string)
- func StartMosquitto(configFolder string, certFolder string, testCerts *TestCerts) (mqCmd *exec.Cmd, err error)
- func StopMosquitto(cmd *exec.Cmd)
- type TestCerts
Constants ¶
const ( MqttPortUnpw = 9883 MqttPortCert = 9884 MqttPortWS = 9885 )
MQTT ports for test environment in the 9xxx range
const OUDevice = "iotdevice"
const OUPlugin = "plugin"
FIXME: These OU names must match that in certsetup
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 ¶
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 ¶
SaveCerts saves the given CA and mosquitto server key and certificates as PEM files
func SetLogging ¶
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:
- Saves the CA, server and client certificates in the certFolder
- Generates a mosquitto configuration in the config folder
- 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 ¶
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