Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import io.swagger.models.refs.RefFormat;
import io.swagger.models.refs.RefType;
import io.swagger.parser.ResolverCache;
import io.swagger.parser.util.RefUtils;
import jdk.nashorn.internal.ir.ObjectNode;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ public static String urlToString(String url, List<AuthorizationValue> auths) thr
final List<AuthorizationValue> header = new ArrayList<>();
if (auths != null) {
for (AuthorizationValue auth : auths) {
if ("query".equals(auth.getType())) {
appendValue(inUrl, auth, query);
} else if ("header".equals(auth.getType())) {
appendValue(inUrl, auth, header);
if (auth.getUrlMatcher() == null || auth.getUrlMatcher().test(inUrl)) {
if ("query".equals(auth.getType())) {
appendValue(inUrl, auth, query);
} else if ("header".equals(auth.getType())) {
appendValue(inUrl, auth, header);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
import io.swagger.models.auth.AuthorizationValue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.List;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
Expand All @@ -17,6 +19,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.Assert.assertFalse;
import static org.testng.Assert.assertEquals;

public class RemoteUrlTest {
Expand Down Expand Up @@ -77,6 +80,45 @@ public void testAuthorizationHeader() throws Exception {
);
}

@Test
public void testAuthorizationHeaderWithMatchingUrl() throws Exception {

final String expectedBody = setupStub();

final String headerName = "Authorization";
final String headerValue = "foobar";
final AuthorizationValue authorizationValue = new AuthorizationValue(headerName, headerValue, "header",
url -> url.toString().startsWith("http://localhost"));
final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue));

assertEquals(actualBody, expectedBody);

verify(getRequestedFor(urlEqualTo("/v2/pet/1"))
.withHeader("Accept", equalTo(EXPECTED_ACCEPTS_HEADER))
.withHeader(headerName, equalTo(headerValue))
);
}

@Test
public void testAuthorizationHeaderWithNonMatchingUrl() throws Exception {

final String expectedBody = setupStub();

final String headerValue = "foobar";
String authorization = "Authorization";
final AuthorizationValue authorizationValue = new AuthorizationValue(authorization,
headerValue, "header", u -> false);
final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue));



assertEquals(actualBody, expectedBody);

List<LoggedRequest> requests = WireMock.findAll(getRequestedFor(urlEqualTo("/v2/pet/1")));
assertEquals(1, requests.size());
assertFalse(requests.get(0).containsHeader(authorization));
}

@Test
public void testHostHeader() throws Exception {

Expand Down