diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index c6115b9..3a75382 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -63,6 +63,8 @@ jobs: runs-on: ubuntu-latest environment: Website needs: preview + outputs: + appServiceAppHostName: ${{ steps.deploy.outputs.appServiceAppHostName }} steps: - uses: actions/checkout@v3 - uses: azure/login@v1 @@ -72,6 +74,7 @@ jobs: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - uses: azure/arm-deploy@v1 + id: deploy name: Deploy website with: failOnStdErr: false @@ -79,3 +82,17 @@ jobs: resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }} template: ./deploy/main.bicep parameters: environmentType=${{ env.ENVIRONMENT_TYPE }} + smoke-test: + runs-on: ubuntu-latest + needs: deploy + steps: + - uses: actions/checkout@v3 + - run: | + $container = New-PesterContainer ` + -Path 'deploy/Website.Tests.ps1' ` + -Data @{ HostName = '${{needs.deploy.outputs.appServiceAppHostName}}' } + Invoke-Pester ` + -Container $container ` + -CI + name: Run smoke tests + shell: pwsh diff --git a/deploy/Website.Tests.ps1 b/deploy/Website.Tests.ps1 new file mode 100644 index 0000000..74e7d31 --- /dev/null +++ b/deploy/Website.Tests.ps1 @@ -0,0 +1,23 @@ +param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $HostName +) + +Describe 'Toy Website' { + + It 'Serves pages over HTTPS' { + $request = [System.Net.WebRequest]::Create("https://$HostName/") + $request.AllowAutoRedirect = $false + $request.GetResponse().StatusCode | + Should -Be 200 -Because "the website requires HTTPS" + } + + It 'Does not serves pages over HTTP' { + $request = [System.Net.WebRequest]::Create("http://$HostName/") + $request.AllowAutoRedirect = $false + $request.GetResponse().StatusCode | + Should -BeGreaterOrEqual 300 -Because "HTTP is not secure" + } + +} \ No newline at end of file