diff --git a/.github/integration_test.yml b/.github/integration_test.yml new file mode 100644 index 0000000..8604c40 --- /dev/null +++ b/.github/integration_test.yml @@ -0,0 +1,67 @@ +name: Integration Tests + +on: + schedule: + - cron: '00 08 * * 2' + + workflow_dispatch: + inputs: + environment: + required: true + type: choice + description: Select the Environment + options: + - dev + - uat + default: uat + canary: + description: 'run the tests on canary version' + required: false + type: boolean + default: false + +permissions: + id-token: write + contents: read + deployments: write + + +jobs: + integration_test: + name: Test + runs-on: ubuntu-latest + environment: ${{(github.event.inputs == null && 'uat') || inputs.environment }} + steps: + - name: Checkout + id: checkout + uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707 + + - name: Run Integration Tests + shell: bash + run: | + export CANARY=${{ inputs.canary }} + export REPORTING_BATCH_QUEUE=${{ vars.REPORTING_BATCH_QUEUE }} + export FLOW_SA_CONNECTION_STRING="${{ secrets.FLOW_SA_CONNECTION_STRING }}" + + cd ./integration-test + chmod +x ./run_integration_test.sh + ./run_integration_test.sh ${{( github.event.inputs == null && 'uat') || inputs.environment }} ${{ secrets.API_SUBSCRIPTION_KEY }} + + notify: + needs: [ integration_test ] + runs-on: ubuntu-latest + name: Notify + if: always() + steps: + - name: Report Status + if: always() + uses: ravsamhq/notify-slack-action@v2 + with: + status: ${{ needs.integration_test.result }} + token: ${{ secrets.GITHUB_TOKEN }} + notify_when: 'failure,skipped' + notification_title: '{workflow} has {status_message}' + message_format: '{emoji} <{workflow_url}|{workflow}> {status_message} in <{repo_url}|{repo}>' + footer: 'Linked to Repo <{repo_url}|{repo}>' + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1a255bd..5d515fb 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,13 @@ hs_err_pid* local.settings.json bin/ obj/ + + +# Project files +/target/ +**/node_modules + +# Terraform +**/.terraform/ +/.identity/.terraform.lock.hcl +*.lock \ No newline at end of file diff --git a/.identity/00_data.tf b/.identity/00_data.tf new file mode 100644 index 0000000..06c0ac9 --- /dev/null +++ b/.identity/00_data.tf @@ -0,0 +1,48 @@ +data "azurerm_resource_group" "dashboards" { + name = "dashboards" +} + +data "azurerm_kubernetes_cluster" "aks" { + name = local.aks_cluster.name + resource_group_name = local.aks_cluster.resource_group_name +} + +data "github_organization_teams" "all" { + root_teams_only = true + summary_only = true +} + +data "azurerm_key_vault" "key_vault" { + name = "pagopa-${var.env_short}-kv" + resource_group_name = "pagopa-${var.env_short}-sec-rg" +} + +data "azurerm_key_vault" "domain_key_vault" { + name = "pagopa-${var.env_short}-${local.domain}-kv" + resource_group_name = "pagopa-${var.env_short}-${local.domain}-sec-rg" +} + +data "azurerm_key_vault_secret" "key_vault_sonar" { + name = "sonar-token" + key_vault_id = data.azurerm_key_vault.key_vault.id +} + +data "azurerm_key_vault_secret" "key_vault_bot_token" { + name = "bot-token-github" + key_vault_id = data.azurerm_key_vault.key_vault.id +} + +data "azurerm_key_vault_secret" "key_vault_cucumber_token" { + name = "cucumber-token" + key_vault_id = data.azurerm_key_vault.key_vault.id +} + +data "azurerm_key_vault_secret" "key_vault_integration_test_subkey" { + name = "integration-test-subkey" + key_vault_id = data.azurerm_key_vault.key_vault.id +} + +data "azurerm_key_vault_secret" "flow_sa_connection_string" { + name = "flows-sa-${var.env_short}-connection-string" + key_vault_id = data.azurerm_key_vault.domain_key_vault.id +} \ No newline at end of file diff --git a/.identity/02_application_action.tf b/.identity/02_application_action.tf new file mode 100644 index 0000000..c4018b6 --- /dev/null +++ b/.identity/02_application_action.tf @@ -0,0 +1,84 @@ +#module "github_runner_app" { +# source = "git::https://github.com/pagopa/github-actions-tf-modules.git//app-github-runner-creator?ref=main" +# +# app_name = local.app_name +# +# subscription_id = data.azurerm_subscription.current.id +# +# github_org = local.github.org +# github_repository = local.github.repository +# github_environment_name = var.env +# +# container_app_github_runner_env_rg = local.container_app_environment.resource_group +#} +# +#resource "null_resource" "github_runner_app_permissions_to_namespace" { +# triggers = { +# aks_id = data.azurerm_kubernetes_cluster.aks.id +# service_principal_id = module.github_runner_app.client_id +# namespace = local.domain +# version = "v2" +# } +# +# provisioner "local-exec" { +# command = < /dev/null; then + if [ "$ACTION" = "init" ]; then + echo "[INFO] init tf on ENV: ${ENV}" + terraform "$ACTION" -backend-config="${BACKEND_CONFIG_PATH}" $other + elif [ "$ACTION" = "output" ] || [ "$ACTION" = "state" ] || [ "$ACTION" = "taint" ]; then + # init terraform backend + terraform init -reconfigure -backend-config="${BACKEND_CONFIG_PATH}" + terraform "$ACTION" $other + else + # init terraform backend + echo "[INFO] init tf on ENV: ${ENV}" + terraform init -reconfigure -backend-config="${BACKEND_CONFIG_PATH}" + + echo "[INFO] run tf with: ${ACTION} on ENV: ${ENV} and other: >${other}<" + terraform "${ACTION}" -var-file="./env/${ENV}/terraform.tfvars" -compact-warnings $other + fi +else + echo "[ERROR] ACTION not allowed." + exit 1 +fi diff --git a/integration-test/README.MD b/integration-test/README.MD index 8242d71..1670b22 100644 --- a/integration-test/README.MD +++ b/integration-test/README.MD @@ -1,18 +1,12 @@ # Integration Tests -👀 Integration tests are in `integration-test/src/` folder. See there for more information. +👀 Integration tests are in `integration-test/src/` folder. See there for more information. ## How run in local environment To run the integration test from local environment, simply execute this commands: ``` -export API_CONFIG_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \ -export GPD_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \ -export PAYMENTS_REST_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \ -export PAYMENTS_SOAP_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \ -export REPORTING_SUBSCRIPTION_KEY=##SUBSCRIPTION_KEY## \ -export REPORTING_BATCH_CONNECTION_STRING=##QUEUE_CONNECTION_STRING## \ yarn install && \ -yarn test:${{ parameters.ENV }} +yarn test:${{ parameters.ENV }} ${{ secrets.API_SUBSCRIPTION_KEY }} ``` ## How run on Docker 🐳 @@ -21,7 +15,7 @@ To run the integration tests on docker, you can run from this directory the scri ``` shell -sh ./run_integration_test.sh +sh ./run_integration_test.sh ``` @@ -32,6 +26,5 @@ If you use dev, uat or prod **you test the images on Azure ACR** --- 💻 If you want to test your local branch, ``` shell -sh ./run_integration_test.sh local -``` - +sh ./run_integration_test.sh local +``` \ No newline at end of file diff --git a/integration-test/run_integration_test.sh b/integration-test/run_integration_test.sh index f217f53..4dff7a7 100644 --- a/integration-test/run_integration_test.sh +++ b/integration-test/run_integration_test.sh @@ -1,25 +1,11 @@ -# example: sh ./run_integration_test.sh -environment=$1 -containerName="node-container" +# example: sh ./run_integration_test.sh +set -e -docker stop node-container || true -docker rm node-container || true +export ENV=$1 +export API_SUBSCRIPTION_KEY=$2 -# please see https://github.com/andrea-deri/prebuilt-img-yarn-base for yarn-testing-base image content -docker pull ${CONTAINER_REGISTRY}/yarn-testing-base:latest -docker run -dit --name ${containerName} ${CONTAINER_REGISTRY}/yarn-testing-base:latest +# run integration tests (application must be running) -# run integration tests with yarn -docker cp -a ./src/. ${containerName}:/test -docker exec -i ${containerName} /bin/bash -c " \ -cd ./test -export API_CONFIG_SUBSCRIPTION_KEY=${API_CONFIG_SUBSCRIPTION_KEY} \ -export GPD_SUBSCRIPTION_KEY=${GPD_SUBSCRIPTION_KEY} \ -export PAYMENTS_REST_SUBSCRIPTION_KEY=${PAYMENTS_REST_SUBSCRIPTION_KEY} \ -export PAYMENTS_SOAP_SUBSCRIPTION_KEY=${PAYMENTS_SOAP_SUBSCRIPTION_KEY} \ -export REPORTING_SUBSCRIPTION_KEY=${REPORTING_SUBSCRIPTION_KEY} \ -export REPORTING_BATCH_CONNECTION_STRING=${REPORTING_BATCH_CONNECTION_STRING} -yarn test:${environment}" - -# clean up container -docker stop ${containerName} && docker rm ${containerName} \ No newline at end of file +cd ../integration-test/src || exit +yarn install +yarn test:$ENV \ No newline at end of file diff --git a/integration-test/src/README.md b/integration-test/src/README.md index af1c347..809ffe7 100644 --- a/integration-test/src/README.md +++ b/integration-test/src/README.md @@ -11,7 +11,7 @@ - run tests: `yarn test:ENV` in `src` folder ### Note -Before run the test, set a variable `SUBCRIPTION_KEY` in your environment. +Before run the test, set a variable `API_SUBCRIPTION_KEY` in your environment. You can configure the endpoints with `./config/env.ENV` file. diff --git a/integration-test/src/config/.env.uat b/integration-test/src/config/.env.uat index d01b865..e83a9ac 100644 --- a/integration-test/src/config/.env.uat +++ b/integration-test/src/config/.env.uat @@ -11,7 +11,7 @@ nodo_host=https://api.uat.platform.pagopa.it/nodo creditor_institution_id=77777777777 broker_id=15376371009 station_id=15376371009_01 -psp_id=60000000001 -channel_id=60000000001_01 +psp_id=AGID_01 +channel_id=97735020584_03 reporting_batch_wait_execution_sec=120 -include_debug_logs=true +include_debug_logs=false \ No newline at end of file diff --git a/integration-test/src/step_definitions/support/clients/api_config_client.js b/integration-test/src/step_definitions/support/clients/api_config_client.js index 6760c42..0127441 100644 --- a/integration-test/src/step_definitions/support/clients/api_config_client.js +++ b/integration-test/src/step_definitions/support/clients/api_config_client.js @@ -9,7 +9,7 @@ function apiConfigHealthCheck() { return get(host, { headers: { "Host": process.env.host_header, - "Ocp-Apim-Subscription-Key": process.env.API_CONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -19,7 +19,7 @@ function readCreditorInstitution(organizationFiscalCode) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.API_CONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -29,7 +29,7 @@ function readCreditorInstitutionIbans(organizationFiscalCode) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.API_CONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -39,7 +39,7 @@ function readCreditorInstitutionBroker(brokerId) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.APICONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -49,7 +49,7 @@ function readStation(stationId) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.APICONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -59,7 +59,7 @@ function readCIStationAssociation(stationId, organizationFiscalCode) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.APICONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -69,7 +69,7 @@ function readPSP(pspId) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.APICONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -79,7 +79,7 @@ function readChannel(channelId) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.APICONFIG_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } diff --git a/integration-test/src/step_definitions/support/clients/gpd_client.js b/integration-test/src/step_definitions/support/clients/gpd_client.js index 4e4f35a..ba8c81e 100644 --- a/integration-test/src/step_definitions/support/clients/gpd_client.js +++ b/integration-test/src/step_definitions/support/clients/gpd_client.js @@ -9,7 +9,7 @@ function gpdHealthCheck() { return get(host, { headers: { "Host": process.env.host_header, - "Ocp-Apim-Subscription-Key": process.env.GPD_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -20,7 +20,7 @@ function createDebtPosition(organizationFiscalCode, body) { return post(host, body, { timeout: 10000, headers: { - "Ocp-Apim-Subscription-Key": process.env.GPD_SUBSCRIPTION_KEY, + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY, "Content-Type": "application/json" } }) @@ -32,7 +32,7 @@ function getPaymentOptionDetail(organizationFiscalCode, iuv) { return get(host, { timeout: 10000, headers: { - "Ocp-Apim-Subscription-Key": process.env.GPD_SUBSCRIPTION_KEY, + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY, "Content-Type": "application/json" } }); @@ -44,7 +44,7 @@ function payDebtPosition(organizationFiscalCode, iupd, body) { return post(host, body, { timeout: 10000, headers: { - "Ocp-Apim-Subscription-Key": process.env.GPD_SUBSCRIPTION_KEY, + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY, "Content-Type": "application/json" } }) @@ -56,7 +56,7 @@ function publishDebtPosition(organizationFiscalCode, iupd) { return post(host, "", { timeout: 10000, headers: { - "Ocp-Apim-Subscription-Key": process.env.GPD_SUBSCRIPTION_KEY, + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY, "Content-Type": "application/json" } }) diff --git a/integration-test/src/step_definitions/support/clients/payments_client.js b/integration-test/src/step_definitions/support/clients/payments_client.js index 51c104d..5051f00 100644 --- a/integration-test/src/step_definitions/support/clients/payments_client.js +++ b/integration-test/src/step_definitions/support/clients/payments_client.js @@ -13,7 +13,7 @@ function paymentsHealthCheck() { headers: { "Host": process.env.host_header, "X-Forwarded-For": ipAddress, - "Ocp-Apim-Subscription-Key": process.env.PAYMENTS_REST_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -26,7 +26,7 @@ function demandPaymentNotice(body) { headers: { 'Content-Type': 'text/xml', 'SOAPAction': 'paDemandPaymentNotice', - "Ocp-Apim-Subscription-Key": process.env.PAYMENTS_SOAP_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -39,7 +39,7 @@ function verifyPaymentNotice(body) { headers: { 'Content-Type': 'text/xml', 'SOAPAction': 'paVerifyPaymentNotice', - "Ocp-Apim-Subscription-Key": process.env.PAYMENTS_SOAP_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } @@ -52,7 +52,7 @@ function getPayment(body) { headers: { 'Content-Type': 'text/xml', 'SOAPAction': 'paGetPayment', - "Ocp-Apim-Subscription-Key": process.env.PAYMENTS_SOAP_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }) } diff --git a/integration-test/src/step_definitions/support/clients/reporting_client.js b/integration-test/src/step_definitions/support/clients/reporting_client.js index 3a8600d..aa9f345 100644 --- a/integration-test/src/step_definitions/support/clients/reporting_client.js +++ b/integration-test/src/step_definitions/support/clients/reporting_client.js @@ -8,7 +8,7 @@ async function getFlow(organizationFiscalCode, flowId, date) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.REPORTING_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }); } @@ -18,7 +18,7 @@ async function getFlowList(organizationFiscalCode) { debugLog(`Calling endpoint: [${host}]`); return get(host, { headers: { - "Ocp-Apim-Subscription-Key": process.env.REPORTING_SUBSCRIPTION_KEY + "Ocp-Apim-Subscription-Key": process.env.API_SUBSCRIPTION_KEY } }); } diff --git a/integration-test/src/step_definitions/support/utility/helpers.js b/integration-test/src/step_definitions/support/utility/helpers.js index 7db052e..c7fdd2d 100644 --- a/integration-test/src/step_definitions/support/utility/helpers.js +++ b/integration-test/src/step_definitions/support/utility/helpers.js @@ -11,7 +11,7 @@ function buildStringFromDate(rawDate) { } function debugLog(message) { - if (process.env.include_debug_logs) { + if (process.env.include_debug_logs === "true") { console.log(`\t[DEBUG] | ${new Date().toISOString()} | ${message}`); } }