zeebe_test

package
v0.0.0-...-16fef41 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

Run the tests on the command line

Command bindings

cd tests/certification/bindings/zeebe/command
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore go test -v --count=1 .

or a single command binding

cd tests/certification/bindings/zeebe/command
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore go test -v --count=1 ./deploy_resource_test.go ./command_test.go

Jobworker bindings

cd tests/certification/bindings/zeebe/jobworker
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=ignore go test -v --count=1 .

TLS

Zeebe supports TLS connection between the client and Zeebe itself: https://docs.camunda.io/docs/self-managed/zeebe-deployment/security/secure-client-communication/

The tests will test TLS and non-TLS connections. Therefore a cert and a private key needs to be created.

Generate cert

For the test there is a predefined cert and key with a validity of 10 years. The cert was generated with the following command:

cd tests/certification/bindings/zeebe/certs
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 --nodes --addext 'subjectAltName=IP:127.0.0.1, DNS:localhost'
Automatic cert generation

There was also an attempt to generate the cert for each test automatically. The problem is that when using the automatic generated cert, the connection could not be established because of the following error:

transport: authentication handshake failed: EOF

The code that was used:

func CreateKeyAndCert(ctx flow.Context) error {
	keyFile, err := os.Create(TlsKeyFile)
	if err != nil {
		return err
	}
	defer keyFile.Close()

	certFile, err := os.Create(TlsCertFile)
	if err != nil {
		return err
	}
	defer certFile.Close()

	// This helper function with modifications comes from https://github.com/madflojo/testcerts/blob/main/testcerts.go
	// Copyright 2019 Benjamin Cane, MIT License

	// Create a Certificate Authority Cert
	ca := &x509.Certificate{
		Subject: pkix.Name{
			Organization: []string{"Dapr Development Only Organization"},
			CommonName:   "localhost",
		},
		SerialNumber:          big.NewInt(123),
		NotBefore:             time.Now(),
		NotAfter:              time.Now().Add(1 * time.Hour),
		IsCA:                  true,
		BasicConstraintsValid: true,
		IPAddresses:           []net.IP{net.IPv4(127, 0, 0, 1)},
		DNSNames:              []string{"localhost"},
	}

	// Create a Private and Public Key
	keypair, err := rsa.GenerateKey(rand.Reader, 4096)
	if err != nil {
		return fmt.Errorf("could not generate rsa key - %s", err)
	}

	// Use CA Cert to sign a CSR and create a Public Certificate
	cert, err := x509.CreateCertificate(rand.Reader, ca, ca, &keypair.PublicKey, keypair)
	if err != nil {
		return fmt.Errorf("could not generate certificate - %s", err)
	}

	// Convert keys into pem.Block
	publiccert := &pem.Block{Type: "CERTIFICATE", Bytes: cert}
	privatekey := &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(keypair)}
	err = pem.Encode(certFile, publiccert)
	if err != nil {
		return err
	}
	err = pem.Encode(keyFile, privatekey)
	if err != nil {
		return err
	}

	return nil
}

BPMN process files

The test suite uses two BPMN processes which are located in the processes folder. These processes can be edited with the Camunda Modeler

Missing tests

Currently it's not possible to get an incident key which is needed to resolve an incident.

Documentation

Index

Constants

View Source
const (
	SidecarName           = "zeebeSidecar"
	CommandName           = "zeebe-command"
	JobworkerTestName     = "zeebe-jobworker-test"
	JobworkerCalcExecName = "zeebe-jobworker-calc-exec"
	JobworkerCalcAckName  = "zeebe-jobworker-calc-ack"
	DockerComposeYaml     = "../docker-compose.yml"
	DockerComposeTlsYaml  = "../docker-compose-tls.yml"
	TlsKeyFile            = "/tmp/dapr-cert-test-zeebe-key.pem"
	TlsCertFile           = "/tmp/dapr-cert-test-zeebe-cert.pem"
	// TestProcessFile contains the basic test process file name.
	TestProcessFile string = "test.bpmn"
	// CalcProcessFile contains the calculation process file name.
	CalcProcessFile string = "calc.bpmn"
	TestDmnFile     string = "test.dmn"
)

Variables

This section is empty.

Functions

func ActicateJob

func ActicateJob(
	client dapr_client.Client,
	context context.Context,
	payload map[string]interface{},
) (*[]pb.ActivatedJob, error)

func CheckZeebeConnection

func CheckZeebeConnection(ctx flow.Context) error

func CheckZeebeConnectionTls

func CheckZeebeConnectionTls(relativeCertPath string) func(ctx flow.Context) error

func CreateProcessInstance

func CreateProcessInstance(
	client dapr_client.Client,
	context context.Context,
	payload map[string]interface{},
) (*pb.CreateProcessInstanceWithResultResponse, error)

CreateProcessInstance creates a process instance and returns the process instance data.

func ExecCommandOperation

func ExecCommandOperation(
	context context.Context,
	client dapr_client.Client,
	operation bindings.OperationKind,
	data []byte, metadata map[string]string,
) (out *dapr_client.BindingEvent, err error)

ExecCommandOperation abstracts the command binding request for the different operations

func GetDaprClient

func GetDaprClient(grpcPort int) dapr_client.Client

func GetTestFile

func GetTestFile(fileName string, modifiers ...func(string) string) ([]byte, error)

GetTestFile loads the content of a test file. The function also accepts a list of modifier functions which allows to manipulate the content of the returned file.

func IDModifier

func IDModifier(id string) func(string) string

IDModifier modifies an ID of a resource.

func NameModifier

func NameModifier(name string) func(string) string

NameModifier modifies the name of a resource.

func ProvideKeyAndCert

func ProvideKeyAndCert(relativeCertPath string) func(ctx flow.Context) error

ProvideKeyAndCert copies the key and the cert to the temp directory so that it can be referenced in the config files

func RetryModifier

func RetryModifier(jobType string, retries int) func(string) string

RetryModifier modifies the job retries for a specific job type.

func TestID

func TestID() string

TestID creates a valid test ID for the isolation of resources during test. This ID is optimized for the usage inside a BPMN file because some values inside a BPMN must always start with a character. This function will ensure that this is always the case.

Types

type DeployResourceResponseJson

type DeployResourceResponseJson struct {
	Key         int64             `json:"key,omitempty"`
	Deployments []*DeploymentJson `json:"deployments,omitempty"`
}

func DeployResource

func DeployResource(
	client dapr_client.Client,
	context context.Context,
	fileName string,
	expectedDeployments int,
	modifiers ...func(string) string,
) (*DeployResourceResponseJson, error)

DeployResource deploys a test resource. The function also accepts a list of modifier functions which allows to manipulate the content of the deployed resource. On success the function returns a JSON with the deployment information.

type DeploymentJson

type DeploymentJson struct {
	Metadata DeploymentMetadataJson `json:"metadata,omitempty"`
}

type DeploymentMetadataJson

type DeploymentMetadataJson struct {
	Process              *pb.ProcessMetadata              `json:"process,omitempty"`
	Decision             *pb.DecisionMetadata             `json:"decision,omitempty"`
	DecisionRequirements *pb.DecisionRequirementsMetadata `json:"decisionRequirements,omitempty"`
}

type EnvVars

type EnvVars struct {
	ZeebeVersion                 string
	ZeebeBrokerHost              string
	ZeebeBrokerGatewayPort       string
	ZeebeBrokerClusterSize       string
	ZeebeBrokerReplicationFactor string
	ZeebeBrokerPartitionsCount   string
}

func GetEnvVars

func GetEnvVars(relativePath string) EnvVars

GetEnvVars returns the Zeebe environment vars.

Jump to

Keyboard shortcuts

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