0

REST Assured API를 사용하여 REST API를 자동화해야하지만 문제가 발생합니다. REST Assured API를 사용하여 스프링 보안 구성으로 로그인해야합니다.스프링 보안으로 Rest API에 로그인 할 수 없습니다.

@Before 
public void configure() { 
     RestAssured.baseURI = "https://example.com"; 
     RestAssured.basePath = "/my-portal"; 
} 

@Test 
public void apiLogin() { 
    given().auth().form("username", "password", springSecurity().withLoggingEnabled(new LogConfig())).when().get(); 
} 

내가 직면하고 문제는 다음과 같습니다 :

실제 요청 URI : https://example.com/j_spring_security_check
예상 요청 URI :

아래 코드에서 참조하시기 바랍니다 https://example.com/my-portal/j_spring_security_check

다음은 가져온 응답입니다.

Request method: POST 
Request URI: https://example.com/j_spring_security_check 
Proxy:   <none> 
Request params: <none> 
Query params: <none> 
Form params: j_username={username} 
       j_password={password} 
Path params: <none> 
Multiparts:  <none> 
Headers:  Accept=*/* 
       Content-Type=application/x-www-form-urlencoded; charset=ISO-8859-1 
Cookies:  <none> 
Body:   <none> 
HTTP/1.1 404 Not Found 
Date: Mon, 06 Feb 2017 10:51:41 GMT 
Content-Length: 0 
Connection: close 
Content-Type: text/plain 
+0

아무도 답변을 드릴 수 있습니까? https://github.com/rest-assured/rest-assured/issues/815 – kartoos

답변

0

이 작업이 있습니다. 실수가 거의없고 효과가있었습니다.

final StringWriter writer = new StringWriter(); 
     final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true); 
     Response s = given().auth(). 
         form(userName, password, 
         FormAuthConfig.springSecurity().withLoggingEnabled(new LogConfig(captor, true))) 
       .post("/home/myapp.html"); 

     System.out.println(s.getBody().asString()); 

그것은 HTTP 상태 코드를 제공한다 : (302) (즉, 페이지로 리디렉션 /home/myapp.html) 아래

는 작동 코드이다.