我有一个名为Siteminder的安全应用程序。它为每个身份验证创建唯一的URL。 HTTPS://SITE/idp/**RANDOMURLSTRING**/resumeSAML20/idp/startSSO.ping
如何捕获唯一网址并让测试继续登录。
webtest假定流程中的下一个URL。它不支持[或我不知道如何]对随机URL的唯一重定向。有谁知道处理这种情况的方法?
编辑: 我的解决方案 - 在所有URL中用{{SessionID}}替换SessionID并使用此提取规则
public class ExtractSiteMinderCustomUrl : ExtractionRule
{
public string SiteMinderSessionID { get; private set; }
// The Extract method. The parameter e contains the web performance test context.
//---------------------------------------------------------------------
public override void Extract(object sender, ExtractionEventArgs e)
{
//look for anchor tags with URLS
Regex regex = new Regex("<a\\s+(?:[^>]*?\\s+)?href=\"([^\"]+\\?[^\"]+)\"");
MatchCollection match = regex.Matches(e.Response.BodyString);
if (match.Count > 0)
{
foreach (Match ItemMatch in match)
{
if (ItemMatch.ToString().Contains("/idp/"))
{
//start and ends string from the sitemindersession is in the link on the page
e.WebTest.Context.Add(this.ContextParameterName, GetStringBetween(ItemMatch.ToString(), "/idp/", "/resume"));
e.Success = true;
return;
}
}
e.Success = false;
e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found in Link : /idp/");
}
else
{
e.Success = false;
e.Message = String.Format(CultureInfo.CurrentCulture, "No href tags found");
}
}
public static string GetStringBetween(string token, string first, string second)
{
if (!token.Contains(first)) return "";
var afterFirst = token.Split(new[] { first }, StringSplitOptions.None)[1];
if (!afterFirst.Contains(second)) return "";
var result = afterFirst.Split(new[] { second }, StringSplitOptions.None)[0];
return result;
}
}
答案 0 :(得分:1)
简单的答案是使用获取**RANDOMURLSTRING**
的使用提取规则然后更改请求中的URL,例如HTTPS://SITE/idp/{{TheRandomString}}/resumeSAML20/idp/startSSO.ping
其中TheRandomString
是保留的上下文参数提取的值。请注意上下文参数周围的加粗花括号({{
和}}
)。
假设需要捕获第一个重定向返回的值,但是正常的Web测试会再次重定向,因此提取规则不会看到响应。在这种情况下需要显式处理重定向。将初始请求的Follow redirects
属性设置为false,然后添加提取规则以收集所需的值。在初始请求之后添加新请求,并根据需要使用其中提取的值。可以提取整个重定向的网址,并将Url
字段设置为提取的值。