== Azure isolated integration tests

=== Azurite

By default the integration tests are run against the Azurite test container,
or skipped, if the given service is not supported by Azurite.

Unsupported by Azurite:

* `azure-eventhubs`

=== Real Azure API

Prerequisites:

* A https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&tabs=azure-portal[general-purpose v2 Azure storage account] and
https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal[create a container]
* The https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-change-feed?tabs=azure-portal#enable-and-disable-the-change-feed[change feed] is enabled on your storage account
* View the https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal#view-account-access-keys[account keys] and set the following environment variables:
* An https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-create[Azure Event Hub]
* An https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-get-connection-string[Event Hubs connection string]
* A https://learn.microsoft.com/en-us/azure/key-vault/general/overview[Key Vault] configured in your Azure account

To create all of the above, you can use `azure-resources.sh` script as follows. Ensure that you have installed the https://docs.microsoft.com/en-us/cli/azure/[Azure CLI] beforehand:

[source,shell]
----
$ ./azure-resources.sh create
----

The script outputs a set of export commands that you may want to paste to your shell.

Here are the environment variables you need to set:

[source,shell]
----
export AZURE_STORAGE_ACCOUNT_NAME=<your-azure-storage-account-name>
export AZURE_STORAGE_ACCOUNT_KEY=<your-azure-storage-account-key>

export AZURE_CLIENT_ID=<your-azure-app-client-id>
export AZURE_CLIENT_SECRET=<your-azure-app-client-secret>
export AZURE_TENANT_ID=<your-azure-app-tenant-id>
export AZURE_VAULT_NAME=<your-azure-key-vault-name>

# optional to test alternate authentication methods
export AZURE_CLIENT_CERTIFICATE_PATH=<your-azure-app-certificate-pem-file>

# the container has to exist before you run the test
export AZURE_EVENT_HUBS_BLOB_CONTAINER_NAME=<your-container-name>
export AZURE_EVENT_HUBS_CONNECTION_STRING="Endpoint=sb://<your-namespace>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<your-key>;EntityPath=<your-hub-name>"
----

To clean up, run

[source,shell]
----
$ ./azure-resources.sh delete
----

You may want to `export CAMEL_QUARKUS_START_MOCK_BACKEND=false` to avoid starting the local Azurite container and make sure that you test against the real remote Azure API.

==== Regenerating client certificates

For convenience, a certificate is stored in this project to be used for client certificate authentication. It can be regenerated as follows.

[source,shell]
----
openssl req -nodes -new -x509 -sha256 -days 1825 -out /tmp/azure-cert.pem -keyout /tmp/azure-cert-key.pem
cat /tmp/azure-cert.pem /tmp/azure-cert-key.pem > ${PWD}/certs/azure-cert.pem
----
