0

我正在开发一个用于 IBM Worklight 适配器集成测试的 POC。在这样做时,我正在使用RESTAssured framework。我有一个应用了安全测试的适配器。XML 片段:

 <procedure name="getCatalog"
 securityTest="SingleStepAuthAdapter-securityTest" />

对于身份验证,我有另一个适配器:

<procedure name="submitAuthentication" />

在我的测试中,我调用了 SubmitAuthentication 适配器,然后调用了 getCatalog 适配器。这将返回我以下错误响应:

运行时:资源 'proc:SampleHttpAdapter.getCatalog' 只能在领域 'SingleStepAuthRealm' 中进行身份验证时访问。

下面是我正在执行的测试用例:

public void testGetCatalog() {

    Response response =   RestAssured.given().get(BASE_URL.concat("SampleHttpAdapter&
    procedure=submitAuthentication&parameters=[\"worklight\",\"worklight\"]"));
    String sessionid = response.getSessionId();
    Cookie cookie1 = new Cookie.Builder("JSESSIONID", sessionid).build();
    System.out.println("cookie value" + cookie1.getValue());
    RequestSpecification spec_two = new RequestSpecBuilder().addCookie(cookie1)
    .setSessionId(sessionid).build();
    Response catalog_response = RestAssured.given()
    .spec(spec_two)
    .get(BASE_URL.concat("SampleHttpAdapter&procedure=getCatalog&parameters=[]"));
    String catalog_json = catalog_response.asString();
    System.out.println(catalog_json);
}

根据响应,我的 getCatalog 请求中似乎没有持续进行身份验证。我该怎么做?

4

1 回答 1

1

在不知道您的适配器程序是如何编写的情况下,很难调查上述问题。您能否包括 submitAuthentication 和 getCatalog 的适配器程序?

我可以向您提供 Worklight 提供的关于基于适配器的身份验证的示例和教程,其中将详细描述身份验证过程的工作原理。您甚至可以将此项目作为基础,因为它完成了单步适配器身份验证。使用它为身份验证提供的机制,并添加您的 getCatalog 方法进行测试。

基于适配器的身份验证演示: http ://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/08_03_Adapter_based_authentication.pdf

基于适配器的身份验证项目: http ://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/AdapterBasedAuthenticationProject.zip

于 2014-02-27T14:41:11.457 回答