Skip to content

Commit 4ecdeb2

Browse files
committed
Issue #820
1 parent 7a24067 commit 4ecdeb2

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

Cognifide.PowerShell/Data/serialization/master/sitecore/system/Modules/PowerShell/Script Library/Platform/Functions/Invoke-ApiScript.item

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ templatekey: PowerShell Script
1313
field: {B1A94FF0-6897-47C0-9C51-AA6ACB80B1F0}
1414
name: Script
1515
key: script
16-
content-length: 5164
16+
content-length: 5209
1717

1818
<#
1919
.SYNOPSIS
@@ -97,7 +97,7 @@ function Invoke-ApiScript {
9797
[Parameter()]
9898
[hashtable]$Arguments
9999
)
100-
100+
Set-HostProperty -HostWidth ([int]::MaxValue)
101101
$status = "Success"
102102
$message = "The request completed successfully."
103103
$error = $null
@@ -169,7 +169,7 @@ content-length: 3
169169
----version----
170170
language: en
171171
version: 1
172-
revision: 681d02fe-b12a-43e2-a91c-1d9c085966b7
172+
revision: a51d2080-2b63-425a-9835-d0861d2da353
173173

174174
----field----
175175
field: {25BED78C-4957-4165-998A-CA1B52F67497}
@@ -184,14 +184,14 @@ name: __Revision
184184
key: __revision
185185
content-length: 36
186186

187-
681d02fe-b12a-43e2-a91c-1d9c085966b7
187+
a51d2080-2b63-425a-9835-d0861d2da353
188188
----field----
189189
field: {D9CF14B1-FA16-4BA6-9288-E8A174D4D522}
190190
name: __Updated
191191
key: __updated
192192
content-length: 15
193193

194-
20151231T165452
194+
20170207T093020
195195
----field----
196196
field: {BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}
197197
name: __Updated by

Modules/Remoting Tests - Web Api.ps1

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $protocolHost = "http://sitecore81"
33
Import-Module -Name Pester -Force
44

55
#$script = "HomeAndDescendants"
6-
#$url = "$host/-/script/v2/master/$script?user=admin&password=b&offset=0&limit=2&fields=(Name,ItemPath,Id)"
6+
#$url = "$host/-/script/v2/master/HomeAndDescendants?user=admin&password=b&offset=0&limit=2&fields=(Name,ItemPath,Id)"
77
#Invoke-RestMethod -Uri $url
88

99
Describe "WebAPi POST Response" {
@@ -18,7 +18,17 @@ Describe "WebAPi POST Response" {
1818
It "Should return XML Document Object" {
1919
$postParams = @{user="admin"; password="b"}
2020
$html = Invoke-RestMethod -Uri "$protocolHost/-/script/v2/master/ChildrenAsHtml" -method Post -Body $postParams
21-
$html.GetType().Name | Should Be "XmlDocument"
21+
$html | Should BeOfType System.Xml.XmlDocument
22+
}
23+
}
24+
Context "HomeAndDescendants Script" {
25+
It "Should return JSON object with Success" {
26+
$postParams = @{user="admin"; password="b"}
27+
$result = Invoke-RestMethod -Uri "$protocolHost/-/script/v2/master/HomeAndDescendants?offset=0&limit=2&fields=(Name,ItemPath,Id)" -method Post -Body $postParams
28+
$result | Should BeOfType System.Management.Automation.PSCustomObject
29+
$result.Status | Should Be Success
30+
$result.Results.Count | Should Be 2
31+
$result.Results[0].Name | Should Be Home
2232
}
2333
}
2434
}
@@ -33,7 +43,28 @@ Describe "WebAPi GET Response" {
3343
Context "ChildrenAsHtml Script" {
3444
It "Should return XML Document Object" {
3545
$html = Invoke-RestMethod -Uri "$protocolHost/-/script/v2/master/ChildrenAsHtml?user=admin&password=b"
36-
$html.GetType().Name | Should Be "XmlDocument"
46+
$html | Should BeOfType System.Xml.XmlDocument
47+
}
48+
}
49+
}
50+
51+
Describe "WebAPi invalid calls" {
52+
Context "Non existing Script" {
53+
It "Should throw exception" {
54+
$execution = { Invoke-RestMethod -Uri "$protocolHost/-/script/v2/master/NonExistingScript?user=admin&password=b" }
55+
$execution | Should Throw "(404) Not Found."
56+
}
57+
}
58+
Context "Wrong password" {
59+
It "Should throw exception" {
60+
$execution = { Invoke-RestMethod -Uri "$protocolHost/-/script/v2/master/ChildrenAsHtml?user=admin&password=invalid" }
61+
$execution | Should Throw "(404) Not Found"
62+
}
63+
}
64+
Context "Non existing user" {
65+
It "Should throw exception" {
66+
$execution = { Invoke-RestMethod -Uri "$protocolHost/-/script/v2/master/ChildrenAsHtml?user=non_existing&password=invalid" }
67+
$execution | Should Throw "(401) Unauthorized"
3768
}
3869
}
3970
}

0 commit comments

Comments
 (0)