fix: ensure Invoke-WebRequest headers can be configured (#6484)

* fix: ensure Invoke-WebRequest headers can be configured

Signed-off-by: Adrian Mlodzianowski <amlodzianowski@logicworks.net>

* fix: use array for custom headers

Signed-off-by: Adrian Mlodzianowski <amlodzianowski@logicworks.net>

* test: add unit test for Windows simple HTTP request with headers

Signed-off-by: Adrian Mlodzianowski <amlodzianowski@logicworks.net>

---------

Signed-off-by: Adrian Mlodzianowski <amlodzianowski@logicworks.net>
Co-authored-by: Adrian Mlodzianowski <amlodzianowski@logicworks.net>
This commit is contained in:
amlodzianowski 2023-05-15 18:28:48 -07:00 committed by GitHub
parent 4ca2058db4
commit 4c2aa78789
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 467 additions and 3 deletions

View file

@ -304,11 +304,11 @@ module Inspec::Resources
# Insecure not supported simply https://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-https-error
cmd << "-MaximumRedirection #{max_redirects}" unless max_redirects.nil?
request_headers["Authorization"] = """ '\"Basic ' + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(\"#{username}:#{password}\")) +'\"' """ unless username.nil? || password.nil?
request_header_string = nil
request_header_array = []
request_headers.each do |k, v|
request_header_string << " #{k} = #{v}"
request_header_array << " '#{k}' = '#{v}'"
end
cmd << "-Headers @{#{request_header_string.join(";")}}" unless request_header_string.nil?
cmd << "-Headers @{#{request_header_array.join(";")}}" unless request_header_array.empty?
if params.nil?
cmd << "'#{url}'"
else

View file

@ -0,0 +1,442 @@
{
"Content": "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
"ParsedHtml": {
"Script": {},
"all": [
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject"
],
"body": {},
"activeElement": null,
"images": [],
"applets": [],
"links": [
"System.__ComObject"
],
"forms": [],
"anchors": [],
"title": "Example Domain",
"scripts": [],
"designMode": "Inherit",
"selection": {},
"readyState": "complete",
"frames": {},
"embeds": [],
"plugins": [],
"alinkColor": "#0000ff",
"bgColor": "#f0f0f2",
"fgColor": "#000000",
"linkColor": "#0000ff",
"vlinkColor": "#800080",
"referrer": null,
"location": {},
"lastModified": "03/07/2021 23:17:45",
"url": "about:blank",
"domain": null,
"cookie": null,
"expando": true,
"charset": "unicode",
"defaultCharset": "windows-1252",
"mimeType": "Chrome HTML Document",
"fileSize": null,
"fileCreatedDate": null,
"fileModifiedDate": null,
"fileUpdatedDate": null,
"security": "This type of document does not have a security certificate.",
"protocol": "Unknown Protocol",
"nameProp": "Example Domain",
"onhelp": null,
"onclick": null,
"ondblclick": null,
"onkeyup": null,
"onkeydown": null,
"onkeypress": null,
"onmouseup": null,
"onmousedown": null,
"onmousemove": null,
"onmouseout": null,
"onmouseover": null,
"onreadystatechange": null,
"onafterupdate": null,
"onrowexit": null,
"onrowenter": null,
"ondragstart": null,
"onselectstart": null,
"parentWindow": {},
"styleSheets": [
"System.__ComObject"
],
"onbeforeupdate": null,
"onerrorupdate": null,
"documentElement": {},
"uniqueID": "ms__id1",
"onrowsdelete": null,
"onrowsinserted": null,
"oncellchange": null,
"ondatasetchanged": null,
"ondataavailable": null,
"ondatasetcomplete": null,
"onpropertychange": null,
"dir": null,
"oncontextmenu": null,
"onstop": null,
"parentDocument": null,
"enableDownload": null,
"baseUrl": null,
"inheritStyleSheets": null,
"onbeforeeditfocus": null,
"onselectionchange": null,
"namespaces": {},
"media": null,
"oncontrolselect": null,
"URLUnencoded": "about:blank",
"onmousewheel": null,
"doctype": null,
"implementation": {},
"onfocusin": null,
"onfocusout": null,
"onactivate": null,
"ondeactivate": null,
"onbeforeactivate": null,
"onbeforedeactivate": null,
"compatMode": "CSS1Compat",
"nodeType": 9,
"parentNode": null,
"childNodes": [
"System.__ComObject",
"System.__ComObject"
],
"attributes": null,
"nodeName": "#document",
"nodeValue": null,
"firstChild": {},
"lastChild": {},
"previousSibling": null,
"nextSibling": null,
"ownerDocument": null,
"IHTMLDocument2_Script": {},
"IHTMLDocument2_all": [
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject",
"System.__ComObject"
],
"IHTMLDocument2_body": {},
"IHTMLDocument2_activeElement": null,
"IHTMLDocument2_images": [],
"IHTMLDocument2_applets": [],
"IHTMLDocument2_links": [
"System.__ComObject"
],
"IHTMLDocument2_forms": [],
"IHTMLDocument2_anchors": [],
"IHTMLDocument2_title": "Example Domain",
"IHTMLDocument2_scripts": [],
"IHTMLDocument2_designMode": "Inherit",
"IHTMLDocument2_selection": {},
"IHTMLDocument2_readyState": "complete",
"IHTMLDocument2_frames": {},
"IHTMLDocument2_embeds": [],
"IHTMLDocument2_plugins": [],
"IHTMLDocument2_alinkColor": "#0000ff",
"IHTMLDocument2_bgColor": "#f0f0f2",
"IHTMLDocument2_fgColor": "#000000",
"IHTMLDocument2_linkColor": "#0000ff",
"IHTMLDocument2_vlinkColor": "#800080",
"IHTMLDocument2_referrer": null,
"IHTMLDocument2_location": null,
"IHTMLDocument2_lastModified": "03/07/2021 23:17:45",
"IHTMLDocument2_url": "about:blank",
"IHTMLDocument2_domain": null,
"IHTMLDocument2_cookie": null,
"IHTMLDocument2_expando": true,
"IHTMLDocument2_charset": "unicode",
"IHTMLDocument2_defaultCharset": "windows-1252",
"IHTMLDocument2_mimeType": "Chrome HTML Document",
"IHTMLDocument2_fileSize": null,
"IHTMLDocument2_fileCreatedDate": null,
"IHTMLDocument2_fileModifiedDate": null,
"IHTMLDocument2_fileUpdatedDate": null,
"IHTMLDocument2_security": "This type of document does not have a security certificate.",
"IHTMLDocument2_protocol": "Unknown Protocol",
"IHTMLDocument2_nameProp": "Example Domain",
"IHTMLDocument2_onhelp": null,
"IHTMLDocument2_onclick": null,
"IHTMLDocument2_ondblclick": null,
"IHTMLDocument2_onkeyup": null,
"IHTMLDocument2_onkeydown": null,
"IHTMLDocument2_onkeypress": null,
"IHTMLDocument2_onmouseup": null,
"IHTMLDocument2_onmousedown": null,
"IHTMLDocument2_onmousemove": null,
"IHTMLDocument2_onmouseout": null,
"IHTMLDocument2_onmouseover": null,
"IHTMLDocument2_onreadystatechange": null,
"IHTMLDocument2_onafterupdate": null,
"IHTMLDocument2_onrowexit": null,
"IHTMLDocument2_onrowenter": null,
"IHTMLDocument2_ondragstart": null,
"IHTMLDocument2_onselectstart": null,
"IHTMLDocument2_parentWindow": {},
"IHTMLDocument2_styleSheets": [
"System.__ComObject"
],
"IHTMLDocument2_onbeforeupdate": null,
"IHTMLDocument2_onerrorupdate": null,
"IHTMLDocument3_documentElement": {},
"IHTMLDocument3_uniqueID": "ms__id2",
"IHTMLDocument3_onrowsdelete": null,
"IHTMLDocument3_onrowsinserted": null,
"IHTMLDocument3_oncellchange": null,
"IHTMLDocument3_ondatasetchanged": null,
"IHTMLDocument3_ondataavailable": null,
"IHTMLDocument3_ondatasetcomplete": null,
"IHTMLDocument3_onpropertychange": null,
"IHTMLDocument3_dir": null,
"IHTMLDocument3_oncontextmenu": null,
"IHTMLDocument3_onstop": null,
"IHTMLDocument3_parentDocument": null,
"IHTMLDocument3_enableDownload": null,
"IHTMLDocument3_baseUrl": null,
"IHTMLDocument3_childNodes": [
"System.__ComObject",
"System.__ComObject"
],
"IHTMLDocument3_inheritStyleSheets": null,
"IHTMLDocument3_onbeforeeditfocus": null,
"IHTMLDocument4_onselectionchange": null,
"IHTMLDocument4_namespaces": {},
"IHTMLDocument4_media": null,
"IHTMLDocument4_oncontrolselect": null,
"IHTMLDocument4_URLUnencoded": "about:blank",
"IHTMLDocument5_onmousewheel": null,
"IHTMLDocument5_doctype": null,
"IHTMLDocument5_implementation": {},
"IHTMLDocument5_onfocusin": null,
"IHTMLDocument5_onfocusout": null,
"IHTMLDocument5_onactivate": null,
"IHTMLDocument5_ondeactivate": null,
"IHTMLDocument5_onbeforeactivate": null,
"IHTMLDocument5_onbeforedeactivate": null,
"IHTMLDocument5_compatMode": "CSS1Compat",
"IHTMLDOMNode_nodeType": null,
"IHTMLDOMNode_parentNode": null,
"IHTMLDOMNode_childNodes": null,
"IHTMLDOMNode_attributes": null,
"IHTMLDOMNode_nodeName": null,
"IHTMLDOMNode_nodeValue": null,
"IHTMLDOMNode_firstChild": null,
"IHTMLDOMNode_lastChild": null,
"IHTMLDOMNode_previousSibling": null,
"IHTMLDOMNode_nextSibling": null,
"IHTMLDOMNode2_ownerDocument": null
},
"Forms": [],
"InputFields": [],
"Links": [
{
"innerHTML": "More information...",
"innerText": "More information...",
"outerHTML": "<A href=\"https://www.iana.org/domains/example\">More information...</A>",
"outerText": "More information...",
"tagName": "A",
"href": "https://www.iana.org/domains/example"
}
],
"Images": [],
"Scripts": [],
"AllElements": [
{
"innerHTML": null,
"innerText": null,
"outerHTML": null,
"outerText": null,
"tagName": "!"
},
{
"innerHTML": "<HEAD><TITLE>Example Domain</TITLE>\r\n<META charset=utf-8>\r\n<META name=viewport content=\"width=device-width, initial-scale=1\">\r\n<STYLE type=text/css>\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </STYLE>\r\n</HEAD>\r\n<BODY>\r\n<DIV>\r\n<H1>Example Domain</H1>\r\n<P>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</P>\r\n<P><A href=\"https://www.iana.org/domains/example\">More information...</A></P></DIV></BODY>",
"innerText": "Example DomainExample Domain\r\nThis domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.\r\nMore information...",
"outerHTML": "<HTML><HEAD><TITLE>Example Domain</TITLE>\r\n<META charset=utf-8>\r\n<META name=viewport content=\"width=device-width, initial-scale=1\">\r\n<STYLE type=text/css>\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </STYLE>\r\n</HEAD>\r\n<BODY>\r\n<DIV>\r\n<H1>Example Domain</H1>\r\n<P>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</P>\r\n<P><A href=\"https://www.iana.org/domains/example\">More information...</A></P></DIV></BODY></HTML>",
"outerText": "Example DomainExample Domain\r\nThis domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.\r\nMore information...",
"tagName": "HTML"
},
{
"innerHTML": "<TITLE>Example Domain</TITLE>\r\n<META charset=utf-8>\r\n<META name=viewport content=\"width=device-width, initial-scale=1\">\r\n<STYLE type=text/css>\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </STYLE>",
"innerText": "Example Domain",
"outerHTML": "<HEAD><TITLE>Example Domain</TITLE>\r\n<META charset=utf-8>\r\n<META name=viewport content=\"width=device-width, initial-scale=1\">\r\n<STYLE type=text/css>\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </STYLE>\r\n</HEAD>",
"outerText": "Example Domain",
"tagName": "HEAD"
},
{
"innerHTML": "Example Domain",
"innerText": "Example Domain",
"outerHTML": "<TITLE>Example Domain</TITLE>",
"outerText": "Example Domain",
"tagName": "TITLE"
},
{
"innerHTML": null,
"innerText": null,
"outerHTML": "\r\n<META charset=utf-8>",
"outerText": null,
"tagName": "META",
"charset": "utf-8"
},
{
"innerHTML": null,
"innerText": null,
"outerHTML": null,
"outerText": null,
"tagName": "META"
},
{
"innerHTML": null,
"innerText": null,
"outerHTML": "\r\n<META name=viewport content=\"width=device-width, initial-scale=1\">",
"outerText": null,
"tagName": "META",
"name": "viewport",
"content": "width=device-width, initial-scale=1"
},
{
"innerHTML": "\r\n\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n ",
"innerText": null,
"outerHTML": "\r\n<STYLE type=text/css>\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </STYLE>",
"outerText": null,
"tagName": "STYLE",
"type": "text/css"
},
{
"innerHTML": "<DIV>\r\n<H1>Example Domain</H1>\r\n<P>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</P>\r\n<P><A href=\"https://www.iana.org/domains/example\">More information...</A></P></DIV>",
"innerText": "Example Domain\r\nThis domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.\r\nMore information...",
"outerHTML": "\r\n<BODY><DIV>\r\n<H1>Example Domain</H1>\r\n<P>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</P>\r\n<P><A href=\"https://www.iana.org/domains/example\">More information...</A></P></DIV></BODY>",
"outerText": "Example Domain\r\nThis domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.\r\nMore information...",
"tagName": "BODY"
},
{
"innerHTML": "<H1>Example Domain</H1>\r\n<P>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</P>\r\n<P><A href=\"https://www.iana.org/domains/example\">More information...</A></P>",
"innerText": "Example Domain\r\nThis domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.\r\nMore information...",
"outerHTML": "\r\n<DIV><H1>Example Domain</H1>\r\n<P>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</P>\r\n<P><A href=\"https://www.iana.org/domains/example\">More information...</A></P></DIV>",
"outerText": "Example Domain\r\nThis domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.\r\nMore information...",
"tagName": "DIV"
},
{
"innerHTML": "Example Domain",
"innerText": "Example Domain",
"outerHTML": "\r\n<H1>Example Domain</H1>",
"outerText": "Example Domain",
"tagName": "H1"
},
{
"innerHTML": "This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.",
"innerText": "This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.",
"outerHTML": "\r\n<P>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</P>",
"outerText": "This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.",
"tagName": "P"
},
{
"innerHTML": "<A href=\"https://www.iana.org/domains/example\">More information...</A>",
"innerText": "More information...",
"outerHTML": "\r\n<P><A href=\"https://www.iana.org/domains/example\">More information...</A></P>",
"outerText": "More information...",
"tagName": "P"
},
{
"innerHTML": "More information...",
"innerText": "More information...",
"outerHTML": "<A href=\"https://www.iana.org/domains/example\">More information...</A>",
"outerText": "More information...",
"tagName": "A",
"href": "https://www.iana.org/domains/example"
}
],
"StatusCode": 200,
"StatusDescription": "OK",
"RawContentStream": {
"CanRead": true,
"CanSeek": true,
"CanTimeout": false,
"CanWrite": true,
"Length": 1256,
"Capacity": 10000,
"Position": 0,
"ReadTimeout": null,
"WriteTimeout": null
},
"RawContentLength": 1256,
"RawContent": "HTTP/1.1 200 OK\r\nAge: 156043\r\nVary: Accept-Encoding\r\nX-Cache: HIT\r\nAccept-Ranges: bytes\r\nContent-Length: 1256\r\nCache-Control: max-age=604800\r\nContent-Type: text/html; charset=UTF-8\r\nDate: Mon, 08 Mar 2021 07:17:44 GMT\r\nExpires: Mon, 15 Mar 2021 07:17:44 GMT\r\nETag: \"3147526947\"\r\nLast-Modified: Thu, 17 Oct 2019 07:18:26 GMT\r\nServer: ECS (oxr/836D)\r\n\r\n<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
"BaseResponse": {
"IsMutuallyAuthenticated": false,
"Cookies": [],
"Headers": [
"Age",
"Vary",
"X-Cache",
"Accept-Ranges",
"Content-Length",
"Cache-Control",
"Content-Type",
"Date",
"Expires",
"ETag",
"Last-Modified",
"Server"
],
"SupportsHeaders": true,
"ContentLength": 1256,
"ContentEncoding": "",
"ContentType": "text/html; charset=UTF-8",
"CharacterSet": "UTF-8",
"Server": "ECS (oxr/836D)",
"LastModified": "/Date(1571296706000)/",
"StatusCode": 200,
"StatusDescription": "OK",
"ProtocolVersion": {
"Major": 1,
"Minor": 1,
"Build": -1,
"Revision": -1,
"MajorRevision": -1,
"MinorRevision": -1
},
"ResponseUri": "https://www.example.com/",
"Method": "GET",
"IsFromCache": false
},
"Headers": {
"Age": "156043",
"Vary": "Accept-Encoding",
"X-Cache": "HIT",
"Accept-Ranges": "bytes",
"Content-Length": "1256",
"Cache-Control": "max-age=604800",
"Content-Type": "text/html; charset=UTF-8",
"Date": "Mon, 08 Mar 2021 07:17:44 GMT",
"Expires": "Mon, 15 Mar 2021 07:17:44 GMT",
"ETag": "\"3147526947\"",
"Last-Modified": "Thu, 17 Oct 2019 07:18:26 GMT",
"Server": "ECS (oxr/836D)"
}
}

View file

@ -649,6 +649,7 @@ class MockLoader
# http resource - windows
"\n$body = \n $Body = $body | ConvertFrom-Json\n #convert to hashtable\n $HashTable = @{}\n foreach ($property in $Body.PSObject.Properties) {\n $HashTable[$property.Name] = $property.Value\n }\n $response = Invoke-WebRequest -Method HEAD -TimeoutSec 120 'https://www.example.com' -Body $HashTable -UseBasicParsing\n $response | Select-Object -Property * | ConvertTo-json # We use `Select-Object -Property * ` to get around an odd PowerShell error" => cmd.call("http-windows-remote-no-options"),
"\n$body = \n $Body = $body | ConvertFrom-Json\n #convert to hashtable\n $HashTable = @{}\n foreach ($property in $Body.PSObject.Properties) {\n $HashTable[$property.Name] = $property.Value\n }\n $response = Invoke-WebRequest -Method GET -TimeoutSec 120 'https://www.example.com' -Body $HashTable -UseBasicParsing\n $response | Select-Object -Property * | ConvertTo-json # We use `Select-Object -Property * ` to get around an odd PowerShell error" => cmd.call("http-windows-remote-head"),
"\n$body = \n $Body = $body | ConvertFrom-Json\n #convert to hashtable\n $HashTable = @{}\n foreach ($property in $Body.PSObject.Properties) {\n $HashTable[$property.Name] = $property.Value\n }\n $response = Invoke-WebRequest -Method GET -TimeoutSec 120 -Headers @{ 'X-Test-Header' = 'test/value'; 'foo' = 'bar'} 'https://www.example.com' -Body $HashTable -UseBasicParsing\n $response | Select-Object -Property * | ConvertTo-json # We use `Select-Object -Property * ` to get around an odd PowerShell error" => cmd.call("http-windows-remote-get-headers"),
"\n$body = '{ \"a\" : \"1\", \"b\" : \"five\" }'\n $Body = $body | ConvertFrom-Json\n #convert to hashtable\n $HashTable = @{}\n foreach ($property in $Body.PSObject.Properties) {\n $HashTable[$property.Name] = $property.Value\n }\n $response = Invoke-WebRequest -Method POST -TimeoutSec 120 'https://www.example.com' -Body $HashTable -UseBasicParsing\n $response | Select-Object -Property * | ConvertTo-json # We use `Select-Object -Property * ` to get around an odd PowerShell error" => cmd.call("http-windows-remote-head"),
# elasticsearch resource
"curl -H 'Content-Type: application/json' http://localhost:9200/_nodes" => cmd.call("elasticsearch-cluster-nodes-default"),

View file

@ -314,4 +314,25 @@ describe "Inspec::Resources::Http" do
_(worker.resource_id).must_equal "https://www.example.com"
end
end
describe "Windows-Get-With-Headers" do
let(:backend) { MockLoader.new(:windows).backend }
let(:http_method) { "GET" }
let(:url) { "https://www.example.com" }
let(:opts) { { headers: { "X-Test-Header" => "test/value", "foo" => "bar" } } }
let(:worker) { Inspec::Resources::Http::Worker::Remote.new(backend, http_method, url, opts) }
describe "simple HTTP request with headers" do
it "returns correct data" do
Inspec::Resources::Cmd.any_instance
.stubs(:exist?)
.returns(true)
_(worker.status).must_equal 200
_(worker.response_headers["Content-Type"]).must_equal "text/html; charset=UTF-8"
_(worker.resource_id).must_equal "https://www.example.com"
expected_cmd = "Invoke-WebRequest -Method GET -TimeoutSec 120 -Headers @{ 'X-Test-Header' = 'test/value'; 'foo' = 'bar'} 'https://www.example.com' -Body $HashTable -UseBasicParsing"
_(worker.send(:load_powershell_command)).must_include expected_cmd
end
end
end
end