Source:
<code>public void iamTokenAndCookieSuccessful() throws Exception { mockWebServer.enqueue(OK_IAM_COOKIE); <START> mockWebServer.enqueue(new MockResponse().setResponseCode(200).addHeader("Set-Cookie", <END> setCookie(iamSession(EXPECTED_OK_COOKIE))) .setBody(hello)); mockIamServer.enqueue(new MockResponse().setResponseCode(200).setBody(IAM_TOKEN)); CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer) .iamApiKey(iamApiKey) .build(); String response = c.executeRequest(Http.GET(c.getBaseUri())).responseAsString(); assertEquals("The expected response should be received", hello, response); RecordedRequest[] recordedRequests = takeN(mockWebServer, 2); assertEquals("The request should have been for /_iam_session", "/_iam_session", recordedRequests[0].getPath()); assertThat("The request body should contain the IAM token", recordedRequests[0].getBody().readString(Charset.forName("UTF-8")), containsString(IAM_TOKEN)); assertEquals("The request should have been for /", "/", recordedRequests[1].getPath()); assertThat("The Cookie header should contain the expected session value", recordedRequests[1].getHeader("Cookie"), anyOf(containsString(iamSession(EXPECTED_OK_COOKIE)), containsString(iamSessionUnquoted(EXPECTED_OK_COOKIE)))); RecordedRequest[] recordedIamRequests = takeN(mockIamServer, 1); assertEquals("The request should have been for /oidc/token", iamTokenEndpoint, recordedIamRequests[0].getPath()); assertThat("The request body should contain the IAM API key", recordedIamRequests[0].getBody().readString(Charset.forName("UTF-8")), containsString("apikey="+iamApiKey)); }</code><technical_language>I a Set-Cookie here, I this a a normal response, Set-Cookie happened previous _iam_session response</technical_language>

Target:
public void iamTokenAndCookieSuccessful() throws Exception { mockWebServer.enqueue(OK_IAM_COOKIE); mockWebServer.enqueue(new MockResponse().setResponseCode(200) .setBody(hello)); mockIamServer.enqueue(new MockResponse().setResponseCode(200).setBody(IAM_TOKEN)); CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer) .iamApiKey(iamApiKey) .build(); String response = c.executeRequest(Http.GET(c.getBaseUri())).responseAsString(); assertEquals("The expected response should be received", hello, response); RecordedRequest[] recordedRequests = takeN(mockWebServer, 2); assertEquals("The request should have been for /_iam_session", "/_iam_session", recordedRequests[0].getPath()); assertThat("The request body should contain the IAM token", recordedRequests[0].getBody().readString(Charset.forName("UTF-8")), containsString(IAM_TOKEN)); assertEquals("The request should have been for /", "/", recordedRequests[1].getPath()); assertThat("The Cookie header should contain the expected session value", recordedRequests[1].getHeader("Cookie"), anyOf(containsString(iamSession(EXPECTED_OK_COOKIE)), containsString(iamSessionUnquoted(EXPECTED_OK_COOKIE)))); RecordedRequest[] recordedIamRequests = takeN(mockIamServer, 1); assertEquals("The request should have been for /oidc/token", iamTokenEndpoint, recordedIamRequests[0].getPath()); assertThat("The request body should contain the IAM API key", recordedIamRequests[0].getBody().readString(Charset.forName("UTF-8")), containsString("apikey="+iamApiKey)); }