繁体   English   中英

CAS认证使用放心

[英]CAS authentication using rest assured

我们在应用程序中使用CAS(中央身份验证服务)进行身份验证。

我们有很多REST API,我们需要测试其余的调用。 我们计划建立一个测试套件,以测试所有REST api。 因此,我们考虑为您的套房使用“保证放心”。

问题是身份验证。 由于我们已经安装了CAS,因此对于每个呼叫,它都会重定向到登录页面,询问用户名和密码。 是否可以一口气通过用户名和密码并通过身份验证并获取Cookie?

任何帮助将不胜感激!!

您可以使用auth方法通过Rest-Assured进行身份验证。

例如:

RestAssured.given ().auth ().basic (username, password);

编辑:

您也可以尝试以下操作:

RestAssured.given ().auth ().form (username, password);

试试这个,让我们知道是否可行。

尝试以下操作:

Response response = given().contentType(ContentType.JSON)
        .relaxedHTTPSValidation().when().get("<URL>");

String html = response.asString();



String sessionid = response.getCookie("JSESSIONID");
 org.jsoup.nodes.Document loginDoc = Jsoup.parse(html);
 String ltTagValue = loginDoc.select("input[name=lt]").val();
 String executionTagValue = loginDoc.select("input[name=execution]").val();

HashMap<String, Object> head = new HashMap();

 head.put("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
 head.put("Accept","text/html");
 head.put("Accept-Language" ,"en-US,en;q=0.9");


 Response response2=   given().headers(head).

 contentType(ContentType.URLENC).cookie("CASTGC","").cookie("JSESSIONID", sessionid).
 cookie("CASPRIVACY","")
 .cookie("Path","/em-cas").
 relaxedHTTPSValidation().    
 formParam("username", "<abc>").
 formParam("password", "<xyz>").
 formParam("lt", ltTagValue).
 formParam("execution", executionTagValue).
 formParam("_eventId", "submit").
 formParam("submit", "LOGIN").

 when().
 post(<URL>)
 ; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM