我有一个要求,需要在登录身份验证期间从 RSA 令牌输入安全 ID,然后开始运行自动化测试。
是否可以通过任何 api 或任何其他方式以编程方式访问 RSA 令牌值,以便测试流程可以完全自动化?
我们通过执行以下操作,自动登录到使用 rsa secure id 和 Cisco AnyConnect 的 VPN:
1)按照您想要的方式以编程方式打开 rsa secure id
2)运行以下.ps1
#Source http://www.lazywinadmin.com/2010/06/powershell-get-clipboard-set-clipboard.html
function Get-ClipBoard {
Add-Type -AssemblyName System.Windows.Forms
$tb = New-Object System.Windows.Forms.TextBox
$tb.Multiline = $true
$tb.Paste()
$tb.Text
}
# end Source http://www.lazywinadmin.com/2010/06/powershell-get-clipboard-set-clipboard.html
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('the name')#Here you need to write the name that appears on the left top corner of the rsa secure id window
Sleep 1
$wshell.SendKeys('{TAB}')
$wshell.SendKeys('~')
$a = Get-ClipBoard
#Source http://www.cze.cz
#This script is tested with "Cisco AnyConnect Secure Mobility Client version 3.0.5080″
#Please change following variables
[string]$CiscoVPNHost = 'the vpn you are trying to connect'
[string]$Login = 'your user'
[string]$Password = $a
#Please check if file exists on following paths
[string]$vpncliAbsolutePath = 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe'
[string]$vpnuiAbsolutePath = 'C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe'
#****************************************************************************
#**** Please do not modify code below unless you know what you are doing ****
#****************************************************************************
Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop
#Set foreground window function
#This function is called in VPNConnect
Add-Type @'
using System;
using System.Runtime.InteropServices;
public class Win {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
'@ -ErrorAction Stop
#quickly start VPN
#This function is called later in the code
Function VPNConnect()
{
Start-Process -FilePath $vpncliAbsolutePath -ArgumentList "connect $CiscoVPNHost"
$counter = 0; $h = 0;
while($counter++ -lt 1000 -and $h -eq 0)
{
sleep -m 10
$h = (Get-Process vpncli).MainWindowHandle
}
#if it takes more than 10 seconds then display message
if($h -eq 0){echo "Could not start VPNUI it takes too long."}
else{[void] [Win]::SetForegroundWindow($h)}
}
#Terminate all vpnui processes.
Get-Process | ForEach-Object {if($_.ProcessName.ToLower() -eq "vpnui")
{$Id = $_.Id; Stop-Process $Id; echo "Process vpnui with id: $Id was stopped"}}
#Terminate all vpncli processes.
Get-Process | ForEach-Object {if($_.ProcessName.ToLower() -eq "vpncli")
{$Id = $_.Id; Stop-Process $Id; echo "Process vpncli with id: $Id was stopped"}}
#Disconnect from VPN
echo "Trying to terminate remaining vpn connections"
start-Process -FilePath $vpncliAbsolutePath -ArgumentList 'disconnect' -wait
#Connect to VPN
echo "Connecting to VPN address '$CiscoVPNHost' as user '$Login'."
VPNConnect
#Write login and password
[System.Windows.Forms.SendKeys]::SendWait("$Login{Enter}")
[System.Windows.Forms.SendKeys]::SendWait("$Password{Enter}")
#Start vpnui
start-Process -FilePath $vpnuiAbsolutePath
#Wait for keydown
#echo "Press any key to continue …"
#try{$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")}catch{}
#Exit
您现在需要做的就是在上面的脚本中设置您的 VPN 和用户。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)