1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Test the Copy as PowerShell command
9 add_task(async
function () {
10 const { tab
, monitor
} = await
initNetMonitor(HTTPS_CURL_URL
, {
14 info("Starting test... ");
15 info("Test powershell command for GET request without any cookies");
16 await
performRequest("GET");
17 await
testClipboardContentForRecentRequest(`Invoke-WebRequest -UseBasicParsing -Uri "https://example.com/browser/devtools/client/netmonitor/test/sjs_simple-test-server.sjs" \`
18 -UserAgent
"${navigator.userAgent}" \`
21 "Accept-Language" = "en-US"
22 "Accept-Encoding" = "gzip, deflate, br, zstd"
23 "X-Custom-Header-1" = "Custom value"
24 "X-Custom-Header-2" = "8.8.8.8"
25 "X-Custom-Header-3" = "Mon, 3 Mar 2014 11:11:11 GMT"
26 "Referer" = "https://example.com/browser/devtools/client/netmonitor/test/html_copy-as-curl.html"
27 "Sec-Fetch-Dest" = "empty"
28 "Sec-Fetch-Mode" = "cors"
29 "Sec-Fetch-Site" = "same-origin"
31 "Cache-Control" = "no-cache"
34 info("Test powershell command for GET request with cookies");
35 await
performRequest("GET");
36 await
testClipboardContentForRecentRequest(`$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
37 $session.Cookies.Add((New-Object System.Net.Cookie("bob", "true", "/", "example.com")))
38 $session.Cookies.Add((New-Object System.Net.Cookie("tom", "cool", "/", "example.com")))
39 Invoke-WebRequest -UseBasicParsing -Uri "https://example.com/browser/devtools/client/netmonitor/test/sjs_simple-test-server.sjs" \`
40 -WebSession
$session
\`
41 -UserAgent "${navigator.userAgent}" \`
44 "Accept-Language" = "en-US"
45 "Accept-Encoding" = "gzip, deflate, br, zstd"
46 "X-Custom-Header-1" = "Custom value"
47 "X-Custom-Header-2" = "8.8.8.8"
48 "X-Custom-Header-3" = "Mon, 3 Mar 2014 11:11:11 GMT"
49 "Referer" = "https://example.com/browser/devtools/client/netmonitor/test/html_copy-as-curl.html"
50 "Sec-Fetch-Dest" = "empty"
51 "Sec-Fetch-Mode" = "cors"
52 "Sec-Fetch-Site" = "same-origin"
54 "Cache-Control" = "no-cache"
57 // disable sending idempotency header for POST request
58 Services.prefs.setBoolPref("network.http.idempotencyKey.enabled", false);
59 info("Test powershell command for POST request with post body");
60 await performRequest("POST", "Plaintext value as a payload");
61 await testClipboardContentForRecentRequest(`$session
= New
-Object Microsoft
.PowerShell
.Commands
.WebRequestSession
62 $session
.Cookies
.Add((New
-Object System
.Net
.Cookie("bob", "true", "/", "example.com")))
63 $session
.Cookies
.Add((New
-Object System
.Net
.Cookie("tom", "cool", "/", "example.com")))
64 Invoke
-WebRequest
-UseBasicParsing
-Uri
"https://example.com/browser/devtools/client/netmonitor/test/sjs_simple-test-server.sjs" \`
66 -WebSession
$session
\`
67 -UserAgent "${navigator.userAgent}" \`
70 "Accept-Language" = "en-US"
71 "Accept-Encoding" = "gzip, deflate, br, zstd"
72 "X-Custom-Header-1" = "Custom value"
73 "X-Custom-Header-2" = "8.8.8.8"
74 "X-Custom-Header-3" = "Mon, 3 Mar 2014 11:11:11 GMT"
75 "Origin" = "https://example.com"
76 "Referer" = "https://example.com/browser/devtools/client/netmonitor/test/html_copy-as-curl.html"
77 "Sec-Fetch-Dest" = "empty"
78 "Sec-Fetch-Mode" = "cors"
79 "Sec-Fetch-Site" = "same-origin"
81 "Cache-Control" = "no-cache"
83 -ContentType "text/plain;charset=UTF-8" \`
84 -Body
"Plaintext value as a payload"`);
87 "Test powershell command for POST request with post body which contains ASCII non printing characters"
89 await performRequest("POST", `TAB character included
in payload
\t`);
90 await testClipboardContentForRecentRequest(`$session
= New
-Object Microsoft
.PowerShell
.Commands
.WebRequestSession
91 $session
.Cookies
.Add((New
-Object System
.Net
.Cookie("bob", "true", "/", "example.com")))
92 $session
.Cookies
.Add((New
-Object System
.Net
.Cookie("tom", "cool", "/", "example.com")))
93 Invoke
-WebRequest
-UseBasicParsing
-Uri
"https://example.com/browser/devtools/client/netmonitor/test/sjs_simple-test-server.sjs" \`
95 -WebSession
$session
\`
96 -UserAgent "${navigator.userAgent}" \`
99 "Accept-Language" = "en-US"
100 "Accept-Encoding" = "gzip, deflate, br, zstd"
101 "X-Custom-Header-1" = "Custom value"
102 "X-Custom-Header-2" = "8.8.8.8"
103 "X-Custom-Header-3" = "Mon, 3 Mar 2014 11:11:11 GMT"
104 "Origin" = "https://example.com"
105 "Referer" = "https://example.com/browser/devtools/client/netmonitor/test/html_copy-as-curl.html"
106 "Sec-Fetch-Dest" = "empty"
107 "Sec-Fetch-Mode" = "cors"
108 "Sec-Fetch-Site" = "same-origin"
109 "Pragma" = "no-cache"
110 "Cache-Control" = "no-cache"
112 -ContentType "text/plain;charset=UTF-8" \`
113 -Body ([System
.Text
.Encoding
]::UTF8
.GetBytes("TAB character included in payload $([char]9)"))`);
115 async function performRequest(method, payload) {
116 const waitRequest = waitForNetworkEvents(monitor, 1);
117 await SpecialPowers.spawn(
121 url: HTTPS_SIMPLE_SJS,
126 async function ({ url, method_, payload_ }) {
127 content.wrappedJSObject.performRequest(url, method_, payload_);
133 async function testClipboardContentForRecentRequest(expectedClipboardText) {
134 const { document } = monitor.panelWin;
136 const items = document.querySelectorAll(".request-list-item");
137 EventUtils.sendMouseEvent({ type: "mousedown" }, items[items.length - 1]);
138 EventUtils.sendMouseEvent(
139 { type: "contextmenu" },
140 document.querySelectorAll(".request-list-item")[0]
143 /* Ensure that the copy as fetch option is always visible */
145 !!getContextMenuItem(monitor, "request-list-context-copy-as-powershell"),
147 'The "Copy as PowerShell" context menu item should not be hidden on windows'
150 await waitForClipboardPromise(
151 async function setup() {
152 await selectContextMenuItem(
154 "request-list-context-copy-as-powershell"
157 function validate(result) {
158 if (typeof result !== "string") {
161 return expectedClipboardText == result;
166 "Clipboard contains a powershell command for item " + (items.length - 1)