123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <#
- .SYNOPSIS
- Create and run test suite
- .DESCRIPTION
- Submit a multi-case test suite to v3 of the test-center API and execute it
- .PARAMETER UserID
- ID of the user executing the test. Must be the same as that used in your hostname creation previously
- .EXAMPLE
- > .\New-AkaUTests.ps1 -UserID example
- #>
-
- Param(
- [Parameter(Mandatory)]
- [string]
- $UserID,
-
- [Parameter()]
- [string]
- $EdgeRCFile,
-
- [Parameter()]
- [string]
- $Section,
-
- [Parameter()]
- [string]
- $AccountSwitchKey
- )
-
- $CommonParams = @{
- EdgeRCFile = $EdgeRCFile
- Section = $Section
- AccountSwitchKey = $AccountSwitchKey
- }
-
- # 1. Create test suite with child objects
-
- $TestSuiteJSON = @"
- {
- "testSuiteName": "AkaULab-$UserID-TestSuite",
- "isLocked": false,
- "isStateful": false,
- "testCases": [
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response code is one of \"302\""
- },
- "testRequest": {
- "requestMethod": "GET",
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com"
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response header \"X-Akamai-Staging\" has a value that equals \"ESSL\""
- },
- "testRequest": {
- "requestMethod": "GET",
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com"
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Caching option is cache with max-age of \"30\" days"
- },
- "testRequest": {
- "requestMethod": "GET",
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com/assets/public/images/JuiceShop_Logo.png"
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response code is one of \"302\""
- },
- "testRequest": {
- "requestMethod": "GET",
- "testRequestUrl": "https://{{userId}}mastertflab-test.akaudevops.com"
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response header \"X-Test-Environment\" has a value that equals \"true\""
- },
- "testRequest": {
- "requestMethod": "GET",
- "testRequestUrl": "https://{{userId}}mastertflab-test.akaudevops.com"
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response header \"cache-control\" has a value that contains \"no-store\""
- },
- "testRequest": {
- "requestMethod": "GET",
- "testRequestUrl": "https://{{userId}}mastertflab-test.akaudevops.com/style.css"
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response code is one of \"403\""
- },
-
- "testRequest": {
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com/?pasword='OR%201=1",
- "requestMethod": "GET"
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response code is one of \"403\""
- },
-
- "testRequest": {
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com/",
- "requestMethod": "GET",
- "requestHeaders": [
- {
- "headerName": "blockme",
- "headerValue": "true",
- "headerAction": "ADD"
- }
- ]
- }
- },
-
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response code is one of \"403\""
- },
-
- "testRequest": {
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com/rest/user/login",
- "requestMethod": "GET"
- }
- },
-
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response code is one of \"403\""
- },
-
- "testRequest": {
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com/",
- "requestMethod": "GET",
- "requestHeaders": [
- {
- "headerName": "X-Forwarded-For",
- "headerValue": "101.110.112.0",
- "headerAction": "ADD"
- }
- ]
- }
- },
- {
- "clientProfile": {
- "client": "CURL",
- "ipVersion": "IPV4"
- },
- "condition": {
- "conditionExpression": "Response header \"set-cookie\" has a value that contains \"language=ko_KR\""
- },
-
- "testRequest": {
- "testRequestUrl": "https://{{userId}}mastertflab.akaudevops.com/",
- "requestMethod": "GET",
- "requestHeaders": [
- {
- "headerName": "X-Forwarded-For",
- "headerValue": "168.126.63.1",
- "headerAction": "ADD"
- }
- ]
- }
- }
- ],
- "variables": [
- {
- "variableName": "userId",
- "variableValue": "$UserID"
- }
- ]
- }
- "@
-
- try {
- $TestSuite = Invoke-AkamaiRestMethod -Method POST -Path '/test-management/v3/functional/test-suites/with-child-objects' -Body $TestSuiteJSON @CommonParams
- }
- catch {
- Write-Error "Error creating test suite. Cannot continue"
- Write-Error $_
- return
- }
-
- # 2. Execute Test Suite
-
- $TestExecutionJSON = @"
- {
- "functional": {
- "testSuiteExecutions": [
- {
- "testSuiteId": $($TestSuite.success.testSuiteId)
- }
- ]
- },
- "targetEnvironment": "STAGING",
- "note": "Executing test suite for user $UserID",
- "sendEmailOnCompletion": false
- }
- "@
-
- try {
- $Run = Invoke-AkamaiRestMethod -Method POST -Path '/test-management/v3/test-runs' -Body $TestExecutionJSON @CommonParams
- }
- catch {
- Write-Error "Error executing test suite $($TestSuite.success.testSuiteId). Cannot continue"
- Write-Error $_
- return
- }
-
- Write-Host -ForegroundColor Green "Test suite $($TestSuite.success.testSuiteId) created. Wait a few minutes before retrieving test run results with ID: $($Run.testRunId)"
|