-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new LanguageOption for PowerShell Updated TemplateUtil to support PowerShell Strings and Dictionaries Created a new template file for generating PowerShell scripts Created a new CodeTemplateBuilderTest to validate proper code generation
- Loading branch information
1 parent
fb2559d
commit 37cdbbb
Showing
4 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
scriptgen-core/src/main/resources/com/h3xstream/scriptgen/templates/psh_webrequest.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
$uri = "${req.url}" | ||
$method = "${req.method}" | ||
|
||
<#if req.headers??> | ||
$headers = ${util.powershellDict(req.headers)} | ||
$headers.Remove("Proxy-Connection") | ||
</#if> | ||
|
||
<#if req.cookies??> | ||
$cc = New-Object System.Net.CookieContainer | ||
<#list req.cookies?keys as c> | ||
$cc.Add( $(New-Object Uri( $uri )), $(New-Object System.Net.Cookie("${util.powershellStr(c)}", "${util.powershellStr(req.cookies[c])}")) ) | ||
</#list> | ||
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession | ||
$session.Cookies = $cc | ||
</#if> | ||
|
||
<#if req.parametersGet??> | ||
$paramsGet = ${util.powershellDict(req.parametersGet)} | ||
</#if> | ||
|
||
<#if req.parametersPost??> | ||
$paramsPost = ${util.powershellDict(req.parametersPost)} | ||
</#if> | ||
|
||
$response = Invoke-WebRequest -Method $method -Uri $uri<#if req.headers??> -Headers $headers</#if><#if req.cookies??> -WebSession $session</#if><#if req.parametersPost??> -Body $paramsPost</#if><#if req.parametersGet??> -Body $paramsGet</#if> | ||
|
||
Write-Host "Status code: $($response.StatusCode)" | ||
Write-host "Response body: $($response.Content)" |
24 changes: 24 additions & 0 deletions
24
...ore/src/test/java/com/h3xstream/scriptgen/template/CodeTemplateBuilderPowershellTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.h3xstream.scriptgen.template; | ||
|
||
import com.h3xstream.scriptgen.model.HttpRequestInfo; | ||
import com.h3xstream.scriptgen.HttpRequestInfoFixtures; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
|
||
public class CodeTemplateBuilderPowershellTest extends CodeTemplateBuilderBaseTest { | ||
|
||
|
||
HttpRequestInfo reqGet = HttpRequestInfoFixtures.getGetRequest(); | ||
HttpRequestInfo reqPost = HttpRequestInfoFixtures.getPostRequest(); | ||
|
||
@Test | ||
public void testGetTemplate() throws Exception { | ||
testTemplateContains("com/h3xstream/scriptgen/templates/psh_webrequest.tpl","-Body $paramsGet",reqGet); | ||
} | ||
|
||
@Test | ||
public void testPostTemplate() throws Exception { | ||
testTemplateContains("com/h3xstream/scriptgen/templates/psh_webrequest.tpl","-Body $paramsPost",reqPost); | ||
} | ||
} |