Skip to content

Commit

Permalink
fixes #315 replacd deprecated getRequestCcookies to requestCookies (#316
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stevehu authored Sep 6, 2023
1 parent af6d450 commit c188653
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@
import io.undertow.Handlers;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.Cookie;
import io.undertow.util.AttachmentKey;
import io.undertow.util.HeaderMap;
import io.undertow.util.HeaderValues;
import io.undertow.util.HttpString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.*;

/**
* This is the handler that parses the OpenApi object based on uri and method
Expand Down Expand Up @@ -389,9 +387,10 @@ protected static Map<String, Object> nonNullMap(Map<String, Object> map) {

public static Map<String, ?> getCookieParameters(final HttpServerExchange exchange, final boolean deserializedValueOnly) {
Map<String, Object> deserializedCookieParamters = exchange.getAttachment(DESERIALIZED_COOKIE_PARAMETERS);

Map<String, Cookie> cookieMap = new HashMap<>();
exchange.requestCookies().forEach(s -> cookieMap.put(s.getName(), s));
return deserializedValueOnly ? nonNullMap(deserializedCookieParamters)
: mergeMaps(deserializedCookieParamters, exchange.getRequestCookies());
: mergeMaps(deserializedCookieParamters, cookieMap);
}

// this is used to get the basePath from the OpenApiHandler regardless single specification or multiple specifications.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.networknt.openapi.parameter;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import com.networknt.oas.model.Parameter;
import com.networknt.openapi.OpenApiOperation;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.Cookie;
import io.undertow.util.AttachmentKey;
import io.undertow.util.Cookies;

public interface ParameterDeserializer {
static Set<String> getCandidateQueryParams(HttpServerExchange exchange){
Expand All @@ -30,7 +29,9 @@ static void deserialize(HttpServerExchange exchange, OpenApiOperation openApiOpe
Set<String> candidateQueryParams = getCandidateQueryParams(exchange);
Set<String> candidatePathParams = exchange.getPathParameters().keySet();
Set<String> candidateHeaderParams = exchange.getRequestHeaders().getHeaderNames().stream().map(name->name.toString()).collect(Collectors.toSet());
Set<String> candidateCookieParams = exchange.getRequestCookies().keySet();
List<String> cookieNames = new ArrayList<>();
exchange.requestCookies().forEach(s -> cookieNames.add(s.getName()));
Set<String> candidateCookieParams = new HashSet<String>(cookieNames);

openApiOperation.getOperation().getParameters().forEach(p->{
ParameterType type = ParameterType.of(p.getIn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static RoutingHandler getTestHandler() {

@Test
public void testWithCorrectScopeInIdToken() throws Exception {
logger.trace("testWithCorrectScopeInIdToken starts");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -124,6 +125,7 @@ public void testWithCorrectScopeInIdToken() throws Exception {
*/
@Test
public void testWithCorrectCommaSeperatedScpClaimScopeInIdToken() throws Exception {
logger.trace("testWithCorrectCommaSeperatedScpClaimScopeInIdToken starts");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -157,6 +159,7 @@ public void testWithCorrectCommaSeperatedScpClaimScopeInIdToken() throws Excepti
*/
@Test
public void testWithCorrectSpaceSeperatedScpClaimScopeInIdToken() throws Exception {
logger.trace("testWithCorrectSpaceSeperatedScpClaimScopeInIdToken starts");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -190,6 +193,7 @@ public void testWithCorrectSpaceSeperatedScpClaimScopeInIdToken() throws Excepti
*/
@Test
public void testWithCorrectSpaceSeperatedScopeClaimScopeInIdToken() throws Exception {
logger.trace("testWithCorrectSpaceSeperatedScopeClaimScopeInIdToken starts");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -220,6 +224,7 @@ public void testWithCorrectSpaceSeperatedScopeClaimScopeInIdToken() throws Excep

@Test
public void testUnmatchedScopeInIdToken() throws Exception {
logger.trace("testUnmatchedScopeInIdToken starts");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -252,6 +257,7 @@ public void testUnmatchedScopeInIdToken() throws Exception {

@Test
public void testWithCorrectScopeInScopeToken() throws Exception {
logger.trace("testWithCorrectScopeInScopeToken starts");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -283,6 +289,7 @@ public void testWithCorrectScopeInScopeToken() throws Exception {

@Test
public void testUnmatchedScopeInScopeToken() throws Exception {
logger.trace("testUnmatchedScopeInScopeToken starts");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ static RoutingHandler getTestHandler() {

@Test
public void testWithCorrectScopeInIdToken() throws Exception {
logger.trace("Start testWithCorrectScopeInIdToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -137,6 +138,7 @@ public void testWithCorrectScopeInIdToken() throws Exception {
*/
@Test
public void testWithCorrectCommaSeperatedScpClaimScopeInIdToken() throws Exception {
logger.trace("Start testWithCorrectCommaSeperatedScpClaimScopeInIdToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -170,6 +172,7 @@ public void testWithCorrectCommaSeperatedScpClaimScopeInIdToken() throws Excepti
*/
@Test
public void testWithCorrectSpaceSeperatedScpClaimScopeInIdToken() throws Exception {
logger.trace("Start testWithCorrectSpaceSeperatedScpClaimScopeInIdToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -203,6 +206,7 @@ public void testWithCorrectSpaceSeperatedScpClaimScopeInIdToken() throws Excepti
*/
@Test
public void testWithCorrectSpaceSeperatedScopeClaimScopeInIdToken() throws Exception {
logger.trace("Start testWithCorrectSpaceSeperatedScopeClaimScopeInIdToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -233,6 +237,7 @@ public void testWithCorrectSpaceSeperatedScopeClaimScopeInIdToken() throws Excep

@Test
public void testUnmatchedScopeInIdToken() throws Exception {
logger.trace("Start testUnmatchedScopeInIdToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -265,6 +270,7 @@ public void testUnmatchedScopeInIdToken() throws Exception {

@Test
public void testWithCorrectScopeInScopeToken() throws Exception {
logger.trace("Start testWithCorrectScopeInScopeToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -296,6 +302,7 @@ public void testWithCorrectScopeInScopeToken() throws Exception {

@Test
public void testUnmatchedScopeInScopeToken() throws Exception {
logger.trace("Start testUnmatchedScopeInScopeToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -329,6 +336,7 @@ public void testUnmatchedScopeInScopeToken() throws Exception {

@Test
public void testH2CDisabledRequest() throws Exception {
logger.trace("Start testH2CDisabledRequest");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -364,6 +372,7 @@ public void testH2CDisabledRequest() throws Exception {

@Test
public void testEmptyAuthorizationHeader() throws Exception {
logger.trace("Start testEmptyAuthorizationHeader");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static RoutingHandler getTestHandler() {

@Test
public void testWithCorrectScopeInIdToken() throws Exception {
logger.trace("starting testWithCorrectScopeInIdToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -152,6 +153,7 @@ public void testWithCorrectScopeInIdToken() throws Exception {

@Test
public void testWithCorrectScopeInIdTokenAndClientIdSecretInHeader() throws Exception {
logger.trace("starting testWithCorrectScopeInIdTokenAndClientIdSecretInHeader");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -184,6 +186,7 @@ public void testWithCorrectScopeInIdTokenAndClientIdSecretInHeader() throws Exce

@Test
public void testUnmatchedScopeInIdToken() throws Exception {
logger.trace("starting testUnmatchedScopeInIdToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -221,6 +224,7 @@ public void testUnmatchedScopeInIdToken() throws Exception {
@Test
@Ignore
public void testWithCorrectScopeInScopeToken() throws Exception {
logger.trace("starting testWithCorrectScopeInScopeToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -252,6 +256,7 @@ public void testWithCorrectScopeInScopeToken() throws Exception {

@Test
public void testUnmatchedScopeInScopeToken() throws Exception {
logger.trace("starting testUnmatchedScopeInScopeToken");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -285,6 +290,7 @@ public void testUnmatchedScopeInScopeToken() throws Exception {

@Test
public void testH2CDisabledRequest() throws Exception {
logger.trace("starting testH2CDisabledRequest");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down Expand Up @@ -320,6 +326,7 @@ public void testH2CDisabledRequest() throws Exception {

@Test
public void testEmptyAuthorizationHeader() throws Exception {
logger.trace("starting testEmptyAuthorizationHeader");
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
Expand Down
2 changes: 1 addition & 1 deletion openapi-security/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<appender-ref ref="stdout" />
</root>

<logger name="com.networknt.config" level="trace">
<logger name="com.networknt" level="trace">
<appender-ref ref="stdout"/>
</logger>

Expand Down

0 comments on commit c188653

Please sign in to comment.