43 lines
1.3 KiB
PowerShell
43 lines
1.3 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
||
$scriptPath = Join-Path $PSScriptRoot '../../scripts/hxb-bank/read-dingtalk-otp.ps1'
|
||
|
||
function Invoke-Reader {
|
||
param([string[]]$Arguments)
|
||
|
||
$output = & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $scriptPath @Arguments 2>&1
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw ($output -join "`n")
|
||
}
|
||
|
||
return ($output | Select-Object -Last 1 | ConvertFrom-Json)
|
||
}
|
||
|
||
$latest = Invoke-Reader @(
|
||
'-OcrText', "16:23`n123456`n16:25`n654321",
|
||
'-SkipGroupMarker'
|
||
)
|
||
if ($latest.code -ne '654321') {
|
||
throw "应读取最新验证码 654321,实际为 $($latest.code)"
|
||
}
|
||
|
||
$ignored = Invoke-Reader @(
|
||
'-OcrText', "16:23`n123456`n16:25`n654321",
|
||
'-IgnoreCode', '654321',
|
||
'-SkipGroupMarker'
|
||
)
|
||
if ($ignored.code -ne '123456') {
|
||
throw "排除最新验证码后应返回 123456,实际为 $($ignored.code)"
|
||
}
|
||
|
||
$previousErrorAction = $ErrorActionPreference
|
||
$ErrorActionPreference = 'Continue'
|
||
$null = & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $scriptPath `
|
||
-OcrText '没有六位验证码' -SkipGroupMarker 2>$null
|
||
$failedExitCode = $LASTEXITCODE
|
||
$ErrorActionPreference = $previousErrorAction
|
||
if ($failedExitCode -eq 0) {
|
||
throw '无验证码时脚本不应返回成功'
|
||
}
|
||
|
||
Write-Host 'HXB DingTalk OTP reader tests passed.'
|