diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7d22d93..1a27a63 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -63,6 +63,8 @@ jobs: runs-on: ubuntu-latest environment: Azure needs: preview + outputs: + appServiceDefaultHostName: ${{ steps.deploy.outputs.appServiceDefaultHostName }} 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: main.bicep parameters: main.parameters.json + 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.appServiceDefaultHostName}}' } + Invoke-Pester ` + -Container $container ` + -CI + name: Run smoke tests + shell: pwsh diff --git a/Website.Tests.ps1 b/Website.Tests.ps1 new file mode 100644 index 0000000..1472869 --- /dev/null +++ b/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