diff --git a/.github/workflows/call_integration_test.yml b/.github/workflows/call_integration_test.yml new file mode 100644 index 000000000..58b2e66df --- /dev/null +++ b/.github/workflows/call_integration_test.yml @@ -0,0 +1,69 @@ +on: + workflow_call: + inputs: + environment: + type: string + required: true + short_env: + type: string + required: true + description: add '-pnpg' if workflow is related to pnpg + +variables: + postmanEnvFile: integration_environment + + # ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/uat') }}: + # # selfHostedAgentPool: $(UAT_AGENT_POOL) + + + # ${{ else }}: + # # selfHostedAgentPool: $(DEV_AGENT_POOL) + # postmanEnvFile: integration_environment.json + +stages: + - stage: stage_postman_test + environment: ${{ inputs.environment }}-ci + displayName: 'Test_e2e_on_${{ variables.environment }}' + dependsOn: [ stage_deploy ] + condition: and(succeeded(),or(eq(variables.environment, 'DEV'), eq(variables.environment, 'UAT'))) + jobs: + - job: 'Run_Postman_collection_on_${{ variables.environment }}' + displayName: 'Run Postman collection on ${{ variables.environment }}' + # pool: + # name: $(selfHostedAgentPool) + steps: + - task: NodeTool@0 + inputs: + versionSpec: '16.x' + - task: Npm@1 + displayName: Install newman + inputs: + command: custom + customCommand: install -g newman + - task: DownloadSecureFile@1 + displayName: 'download postman environment' + name: postman_env + inputs: + secureFile: $(postmanEnvFile) + - task: CmdLine@2 + displayName: Run newman + continueOnError: true # Useful to avoid the skipping of result publishing task + inputs: + script: newman run selfcare-onboarding/test/newman/Selfcare-Integration.postman_collection.json -e $(postman_env.secureFilePath) --reporters cli,junit --reporter-junit-export result/test-result.xml + - task: PublishTestResults@2 + inputs: + testResultsFormat: 'JUnit' + testResultsFiles: '**/test-*.xml' + searchFolder: '$(System.DefaultWorkingDirectory)/result/' + testRunTitle: 'Publish Newman Test Results' + # - task: 'Bash@3' + # displayName: 'Send message on Slack' + # condition: in(variables['Agent.JobStatus'], 'SucceededWithIssues', 'Failed') + # inputs: + # targetType: 'inline' + # script: > + # curl -X POST \ + # -H "Content-type: application/json" \ + # --data '{"text": "*Attention: There is an error in pipeline $(System.DefinitionName) in step _postman test_!*\nCheck the logs for more details $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId) to view the build results."}' \ + # $(SLACK_WEBHOOK_URL) + diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml new file mode 100644 index 000000000..482ff1b76 --- /dev/null +++ b/.github/workflows/integration_test.yml @@ -0,0 +1,29 @@ +name: Integration test + +on: + push: + branches: + - main + - releases/* + + workflow_dispatch: + inputs: + env: + type: choice + description: Environment + options: + - dev + - uat + +jobs: + + test_dev: + uses: ./.github/workflows/call_integration_test.yml + name: '[Dev] Integration test' + if: ${{ (startsWith(github.ref_name, 'releases/') != true && inputs.env == null) || inputs.env == 'dev' }} + secrets: inherit + with: + environment: dev + short_env: d + + diff --git a/infra/test/.terraform.lock.hcl b/infra/test/.terraform.lock.hcl new file mode 100644 index 000000000..8539e241d --- /dev/null +++ b/infra/test/.terraform.lock.hcl @@ -0,0 +1,64 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/azuread" { + version = "2.30.0" + constraints = "2.30.0" + hashes = [ + "h1:Uw4TcmJBEJ71h+oCwwidlkk5jFpyFRDPAFCMs/bT/cw=", + "zh:1c3e89cf19118fc07d7b04257251fc9897e722c16e0a0df7b07fcd261f8c12e7", + "zh:2e62c193030e04ebb10cc0526119cf69824bf2d7e4ea5a2f45bd5d5fb7221d36", + "zh:2f3c7a35257332d68b778cefc5201a5f044e4914dd03794a4da662ddfe756483", + "zh:35d0d3a1b58fdb8b8c4462d6b7e7016042da43ea9cc734ce897f52a73407d9b0", + "zh:47ede0cd0206ec953d40bf4a80aa6e59af64e26cbbd877614ac424533dbb693b", + "zh:48c190307d4d42ea67c9b8cc544025024753f46cef6ea64db84735e7055a72da", + "zh:6fff9b2c6a962252a70a15b400147789ab369b35a781e9d21cce3804b04d29af", + "zh:7646980cf3438bff29c91ffedb74458febbb00a996638751fbd204ab1c628c9b", + "zh:77aa2fa7ca6d5446afa71d4ff83cb87b70a2f3b72110fc442c339e8e710b2928", + "zh:e20b2b2c37175b89dd0db058a096544d448032e28e3b56e2db368343533a9684", + "zh:eab175b1dfe9865ad9404dccb6d5542899f8c435095aa7c679314b811c717ce7", + "zh:efc862bd78c55d2ff089729e2a34c1831ab4b0644fc11b36ee4ebed00a4797ba", + ] +} + +provider "registry.terraform.io/hashicorp/azurerm" { + version = "3.86.0" + constraints = "<= 3.86.0" + hashes = [ + "h1:rMBvc1zYiiv/wHc0D8ry8SPxqMiqqwUEt8zndCVPZx4=", + "zh:10473870b663b3becca1127687ed0d002d61f417c279e7daac546d265ff1f3db", + "zh:1dfe2446d7530cd082f817a8d37ec9fb0260b275085978bd81ba0e8167aa6f7c", + "zh:31712a4d9727a5970354eb3c26b4d6dc45b5103c6599cb97c2bd3f9915062baf", + "zh:51dcb102e17e49d675d6865f1ca9eaa8a2aa566ba56a93bb77aab703112d1de5", + "zh:54d5053cd88ed99e804c7b4d72f91ec1bab5fe8b6769db5c120d60b5e6a653dc", + "zh:58388274d406a55c84199d1a22b8143b47321b7b508a18ddeed9e824a864cb5d", + "zh:7b8afa8d62431512197aa5aed4e902b06bce3f8362d6ddf2c841e03c2658f4a7", + "zh:b7d3c1e8bfdd4e099e174724be41cdbc916868a7ca637bcf8682a57ef3453f7f", + "zh:ea0cc2751ef9a15b48e42d6ae62f4329c567335e348f57e577ce727d8167c29f", + "zh:f3a48fdf58a34deae9221923f30112b18ce1ab6cabb46d6c38e1a3234340cfd0", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + "zh:fbd1d24b6bc67d5c370f2a3934da70ea3b93d612fe83b71e0dae592b48d030ce", + ] +} + +provider "registry.terraform.io/integrations/github" { + version = "5.18.3" + constraints = "5.18.3" + hashes = [ + "h1:WbZvLB2qXKVoh4BvOOwFfEds+SZQrkINfSAWPnWFxGo=", + "zh:050b37d96628cb7451137755929ca8d21ea546bc46d11a715652584070e83ff2", + "zh:053051061f1b7f7673b0ceffac1f239ba28b0e5b375999206fd39976e85d9f2b", + "zh:0c300a977ca66d0347ed62bb116fd8fc9abb376a554d4c192d14f3ea71c83500", + "zh:1d5a1a5243eba78819d2f92ff2d504ebf9a9008a6670fb5f5660f44eb6a156d8", + "zh:a13ac15d251ebf4e7dc40acb0e40df066f443f4c7799186a29e2e44addc7d8e7", + "zh:a316d94b885953c036ebc9fba64a23da93974746bc3ac9d207462a6f02d44540", + "zh:a658a00373bff5979cc227052c693cbde8ca4c8f9fef1bc8094a3516f2e2a96d", + "zh:a7bfc6ad8465d5dc11b6f19d6805364de87fffe27622bb4f37da2319bb1c4956", + "zh:d7379a76861f1a6bfc36eca7a20f1f477711247563b105744d69d7bd1f365fad", + "zh:de1cd959fd4821248e8d21570601193408648474e74f49597f1d0c43185a4ab7", + "zh:e0b281240dd6f2aa405b2d6fe329bc15ab877161affe163fb150d1efca2fccdb", + "zh:e372c171358757a983d7aa878abfd05a84484fb4d22167e45c9c1267e78ed060", + "zh:f6d3116526030b3f6905f530cd6c04b23d42890d973fa2abe10ce9c89cb1db80", + "zh:f99eec731e03cc6a28996c875bd435887cd7ea75ec07cc77b9e768bb12da2227", + ] +} diff --git a/infra/test/integration_test.tf b/infra/test/integration_test.tf index 387c08864..d237d0170 100644 --- a/infra/test/integration_test.tf +++ b/infra/test/integration_test.tf @@ -1,17 +1,10 @@ -resource "azurerm_resource_group" "onboarding_fn_rg" { - name = "${local.app_name}-rg" - location = var.location - - tags = var.tags -} - data "azurerm_key_vault" "key_vault" { resource_group_name = var.key_vault.resource_group_name name = var.key_vault.name } -data "azurerm_key_vault_secret" "apim_product_pn" { - name = "anac-ftp-known-host" +data "azurerm_key_vault_secret" "apim_product_pn_sk" { + name = "apim-product-pn-sk" key_vault_id = data.azurerm_key_vault.key_vault.id } @@ -55,14 +48,14 @@ resource "github_actions_environment_secret" "integration_environment" { repository = data.github_repository.repo.name environment = github_repository_environment.repo_environment.environment secret_name = "integration_environment" - encrypted_value = templatefile("Selfcare-Integration.postman_environment.json", + plaintext_value = base64encode(templatefile("Selfcare-Integration.postman_environment.json", { env = "${local.env_url}" - apimKeyPN = "ciao" //data.azurerm_key_vault_secret.apim_product_pn.value - }) + apimKeyPN = data.azurerm_key_vault_secret.apim_product_pn_sk.value + })) } - +/* data "azurerm_api_management" "apim" { name = format("%s-apim-v2", local.project) resource_group_name = format("%s-api-v2-rg", local.project) @@ -80,10 +73,10 @@ data "azurerm_api_management_user" "admin" { resource_group_name = data.azurerm_api_management.apim.resource_group_name } -resource "azurerm_api_management_subscription" "example" { +resource "azurerm_api_management_subscription" "admin_product_pn" { api_management_name = data.azurerm_api_management.apim.name resource_group_name = data.azurerm_api_management.apim.resource_group_name user_id = data.azurerm_api_management_user.admin.id product_id = data.azurerm_api_management_product.product_pn.id display_name = "Parser API" -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/infra/test/locals.tf b/infra/test/locals.tf index a6375eb16..5f4224d62 100644 --- a/infra/test/locals.tf +++ b/infra/test/locals.tf @@ -3,8 +3,7 @@ locals { pnpg_domain_suffix = var.is_pnpg == true ? "-weu-pnpg" : "" pnpg_domain_vnet_suffix = var.is_pnpg == true ? "-weu" : "" project = "${var.prefix}-${var.env_short}" - env_url = var.env_short == "p" ? "https://api.selfcare.pagopa.it" : - "https://api.${var.env}.selfcare.pagopa.it" + env_url = var.env_short == "p" ? "" : ".${var.env}" app_name = "${local.project}${local.pnpg_suffix}-onboarding-fn" base_domain_name = "${local.project}${local.pnpg_domain_suffix}" diff --git a/infra/test/variables.tf b/infra/test/variables.tf index 5bef19b9f..e147d9665 100644 --- a/infra/test/variables.tf +++ b/infra/test/variables.tf @@ -37,7 +37,7 @@ variable "env" { type = string validation { condition = ( - length(var.env_short) <= 4 + length(var.env) <= 4 ) error_message = "Max length is 4 chars." }