Skip to content

Commit

Permalink
Merge pull request #207 from lipkau/fix/#206-FixEmptyHeader
Browse files Browse the repository at this point in the history
Extract captcha test and fix empty headers #206
  • Loading branch information
lipkau authored Dec 1, 2017
2 parents d480b19 + 7eef905 commit c70e854
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 21 deletions.
30 changes: 30 additions & 0 deletions JiraPS/Internal/Test-Captcha.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Test-Captcha {
[CmdletBinding()]
param(
# Response of Invoke-WebRequest
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[PSObject]$InputObject
)

begin {
$tokenRequiresCaptcha = "AUTHENTICATION_DENIED"
$headerRequiresCaptcha = "X-Seraph-LoginReason"
}

process {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Status code: $($InputObject.StatusCode)"
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Status code: $($InputObject.StatusCode)"

if ($InputObject.Headers -and $InputObject.Headers[$headerRequiresCaptcha]) {
if ( ($InputObject.Headers[$headerRequiresCaptcha] -split ",") -contains $tokenRequiresCaptcha ) {
Write-Warning "Confluence requires you to log on to the website before continuing for security reasons."
}
}
}

end {
}
}
11 changes: 2 additions & 9 deletions JiraPS/Public/New-JiraSession.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,8 @@ function New-JiraSession {
$webResponse = $err.Exception.Response
Write-Debug "[New-JiraSession] Encountered an exception from the Jira server: $err"

# Test HEADERS if Jira requires a CAPTCHA
$tokenRequiresCaptcha = "AUTHENTICATION_DENIED"
$headerRequiresCaptcha = "X-Seraph-LoginReason"
if (
$webResponse.Headers[$headerRequiresCaptcha] -and
($webResponse.Headers[$headerRequiresCaptcha] -split ",") -contains $tokenRequiresCaptcha
) {
Write-Warning "JIRA requires you to log on to the website before continuing for security reasons."
}
# Test response Headers if Jira requires a CAPTCHA
Test-Captcha -InputObject $webResponse

Write-Warning "JIRA returned HTTP error $($webResponse.StatusCode.value__) - $($webResponse.StatusCode)"

Expand Down
4 changes: 2 additions & 2 deletions Tests/Add-JiraIssueAttachment.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ InModuleScope JiraPS {
Assert-MockCalled 'Invoke-JiraMethod' -ModuleName JiraPS -ParameterFilter { $Method -eq 'Put' } -Exactly -Times 0 -Scope It
Assert-MockCalled 'Invoke-JiraMethod' -ModuleName JiraPS -ParameterFilter { $Method -eq 'Delete' } -Exactly -Times 0 -Scope It
}
It "assert VerifiableMocks" {
Assert-VerifiableMocks
It "assert VerifiableMock" {
Assert-VerifiableMock
}
}
#endregion Tests
Expand Down
4 changes: 2 additions & 2 deletions Tests/Get-JiraVersion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ InModuleScope JiraPS {
Assert-MockCalled 'Get-JiraProject' -Times 1 -Scope It -ModuleName JiraPS
Assert-MockCalled 'ConvertTo-JiraVersion' -Times 1 -Scope It -ModuleName JiraPS -Exactly
}
It "assert VerifiableMocks" {
Assert-VerifiableMocks
It "assert VerifiableMock" {
Assert-VerifiableMock
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/New-JiraVersion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ InModuleScope JiraPS {
Assert-MockCalled 'ConvertTo-JiraVersion' -Times 1 -Scope It -ModuleName JiraPS -Exactly
}

It "assert VerifiableMocks" {
Assert-VerifiableMocks
It "assert VerifiableMock" {
Assert-VerifiableMock
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Remove-JiraIssueAttachment.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ InModuleScope JiraPS {
Assert-MockCalled 'Invoke-JiraMethod' -ModuleName JiraPS -ParameterFilter { $Method -eq 'Put' } -Exactly -Times 0 -Scope It
Assert-MockCalled 'Invoke-JiraMethod' -ModuleName JiraPS -ParameterFilter { $Method -eq 'Delete' } -Exactly -Times 2 -Scope It
}
It "assert VerifiableMocks" {
Assert-VerifiableMocks
It "assert VerifiableMock" {
Assert-VerifiableMock
}
}
#endregion Tests
Expand Down
4 changes: 2 additions & 2 deletions Tests/Remove-JiraVersion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ InModuleScope JiraPS {
Assert-MockCalled 'Invoke-JiraMethod' -Times 1 -Scope It -ModuleName JiraPS -Exactly -ParameterFilter { $Method -eq 'Delete' -and $URI -like "$jiraServer/rest/api/latest/version/$versionID1" }
Assert-MockCalled 'Invoke-JiraMethod' -Times 1 -Scope It -ModuleName JiraPS -Exactly -ParameterFilter { $Method -eq 'Delete' -and $URI -like "$jiraServer/rest/api/latest/version/$versionID2" }
}
It "assert VerifiableMocks" {
Assert-VerifiableMocks
It "assert VerifiableMock" {
Assert-VerifiableMock
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Set-JiraVersion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ InModuleScope JiraPS {
Assert-MockCalled 'ConvertTo-JiraVersion' -Times 2 -Scope It -ModuleName JiraPS -Exactly
Assert-MockCalled 'Invoke-JiraMethod' -Times 1 -Scope It -ModuleName JiraPS -Exactly -ParameterFilter { $Method -eq 'Put' -and $URI -like "$jiraServer/rest/api/latest/version/$versionID" }
}
It "assert VerifiableMocks" {
Assert-VerifiableMocks
It "assert VerifiableMock" {
Assert-VerifiableMock
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Shared.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#Requires -Modules Pester

# Dot source this script in any Pester test script that requires the module to be imported.

Expand Down

0 comments on commit c70e854

Please sign in to comment.