Каратэ делает две просьбы

В моем проекте карате есть одна особенность со следующим сценарием. На свой запрос я получаю ожидаемый ответ, но есть второй идентичный запрос, который не был предназначен.

Я заметил, что второй запрос содержит дополнительное поле заголовка Cookie:

Feature: Get the authorization
 Scenario: Retrieve Login page url     
      Given url 'http://someUri:port'
      And path '/secure/author'
      And param response_type = 'code'
      And param client_id = 'valid_clientID'
      And param scope = 'link_submit'
      And param redirect_uri = 'https://someotherUri'
      When method get
      Then status 302

Ниже моя консоль

20:19:26.955 [main] INFO  com.intuit.karate - karate.env system property was: null 
20:19:27.998 [main] DEBUG com.intuit.karate - request:
1 > GET http://uri:port/security/authorize?correct-Parameters-are-here
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: the host
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_221)

20:19:31.377 [main] DEBUG com.intuit.karate - response time in milliseconds: 3374.29
1 < 302
1 < Connection: Keep-Alive
1 < Date: Mon, 09 Sep 2019 21:40:38 GMT
1 < Location: http:wantedurl.com
1 < Set-Cookie: linkCookie="/V455555555555rhuaUFYc3pkwQ="; Version=1; Path=/
1 < Transfer-Encoding: chunked
1 < X-Content-Type-Options: nosniff
1 < X-Frame-Options: DENY
1 < X-XSS-Protection: 1; mode=block
1 < activityID: 222222222444424

20:19:31.398 [main] DEBUG com.intuit.karate - request:
2 > GET http://uri:port/security/authorize?correct-Parameters-are-here
2 > Accept-Encoding: gzip,deflate
2 > Connection: Keep-Alive
2 > Cookie: $Version=1; linkCookie="/VvfdfdlV3ZRawnoIY83QrhuaUFYc3pkwQ="; $Path="/"
2 > Host: the host
2 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_221)

20:19:31.755 [main] DEBUG com.intuit.karate - response time in milliseconds: 352.96
2 < 200
2 < Accept-Ranges: bytes
2 < Access-Control-Allow-Headers: Content-Type,x-openui
2 < Access-Control-Allow-Methods: GET
2 < Access-Control-Allow-Origin: *
2 < Cache-control: private
2 < Connection: Keep-Alive
2 < Content-Type: text/html
2 < Date: Mon, 09 Sep 2019 21:40:38 GMT
2 < ETag: "288-59152f593c040"
2 < Last-Modified: Fri, 30 Aug 2019 10:19:37 GMT
2 < Set-Cookie: 34c188e0698035e66376b276a0a05cd4=f2a878936046ce053dcdc55f78d1e7ca; path=/; HttpOnly; Secure
2 < Transfer-Encoding: chunked
2 < activityID: 31910620180969978101601944
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>some titile</title><base href="."><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.ea03e93ac5f3a194d43b.bundle.css" rel="stylesheet"/></head><body><app-root></app-root><div id="test"></div><script type="text/javascript" src="inline.318b50c57b4eba3d437b.bundle.js"></script><script type="text/javascript" src="polyfills.9e6fb2e22bb7bf8ba831.bundle.js"></script><script type="text/javascript" src="main.7aff2d014e2a36462a25.bundle.js"></script></body></html>

[Fatal Error] :1:3: The markup in the document preceding the root element must be well-formed.
20:19:31.820 [main] WARN  com.intuit.karate - xml parsing failed, response data type set to string: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 3; The markup in the document preceding the root element must be well-formed.
20:19:31.823 [main] ERROR com.intuit.karate - status code was: 200, expected: 302, response time: 353, url: http://uri:port/security/authorize?correct-Parameters-are-here, response: <!doctype html><html lang="en"><head><meta charset="utf-8"><title>title goes here</title><base href="."><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.ea03e93ac5f3a194d43b.bundle.css" rel="stylesheet"/></head><body><app-root></app-root><div id="test"></div><script type="text/javascript" src="inline.318b50c57b4eba3d437b.bundle.js"></script><script type="text/javascript" src="polyfills.9e6fb2e22bb7bf8ba831.bundle.js"></script><script type="text/javascript" src="main.7aff2d014e2a36462a25.bundle.js"></script></body></html>

person Niron Rasanjana Perera    schedule 09.09.2019    source источник


Ответы (1)


Да, это правильное поведение - обратите внимание, что код ответа HTTP был 302 для первого запроса. . В этом случае ответ дал вам файл cookie с именем linkCookie.

Похоже, с вами все в порядке, поскольку ваш запрос - GET. В некоторых редких случаях вам нужно справиться POST самостоятельно.

Также ищите followRedirects в документации.

person Peter Thomas    schedule 09.09.2019
comment
Огромное спасибо за это. Честно говоря, я не знал о перенаправлении URL-адресов и файлах cookie. Я отключу followRedirects. Моя конечная цель - извлечь значение из Location в первом ответе. - person Niron Rasanjana Perera; 09.09.2019