Skip to content

Commit

Permalink
Enables OIDC integration tests. Fixes two additional issues in WebCli…
Browse files Browse the repository at this point in the history
…ent: (#7390)

1. In ClientUri, UriQueryWriteable is initialized from a decoded string. If initialized using an encoded string as before, a second encoding will take place internally.
 2. The WebClientCookieManager now correctly handles cookie values, including those that may contain commas (such as expiration values).

There are new or updated tests to cover the changes in (1) and (2).
  • Loading branch information
spericas authored Aug 17, 2023
1 parent 5d6c941 commit 4de96df
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import jakarta.ws.rs.core.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static io.helidon.tests.integration.oidc.TestResource.EXPECTED_POST_LOGOUT_TEST_MESSAGE;
Expand All @@ -31,7 +30,6 @@
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;

@Disabled("https://github.com/helidon-io/helidon/issues/7094")
class CookieBasedLoginIT extends CommonLoginBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
import org.glassfish.jersey.client.ClientProperties;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static io.helidon.tests.integration.oidc.TestResource.EXPECTED_TEST_MESSAGE;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;

@Disabled("https://github.com/helidon-io/helidon/issues/7094")
@AddConfig(key = "security.providers.1.oidc.cookie-use", value = "false")
@AddConfig(key = "security.providers.1.oidc.query-param-use", value = "true")
class QueryBasedLoginIT extends CommonLoginBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientProperties;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -42,7 +41,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

@Disabled("https://github.com/helidon-io/helidon/issues/7094")
@HelidonTest(resetPerTest = true)
@AddBean(TestResource.class)
@AddConfig(key = "security.providers.1.oidc.oidc-metadata-well-known", value = "false")
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/oidc/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#

client:
cookies:
cookie-manager:
automatic-store-enabled: true
send-expect-continue: false
follow-redirects: true

security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ public ClientUri resolve(URI uri) {

uriBuilder.path(resolvePath(uriBuilder.path().path(), uri.getPath()));

if (uri.getRawQuery() != null) {
query.fromQueryString(uri.getRawQuery());
if (uri.getQuery() != null) {
query.fromQueryString(uri.getQuery());
}

if (uri.getRawFragment() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ public void response(ClientUri uri, ClientResponseHeaders headers) {

if (headers.contains(Http.HeaderNames.SET_COOKIE)) {
cookies = new HashMap<>();
cookies.put(SET_COOKIE, headers.values(Http.HeaderNames.SET_COOKIE));
cookies.put(SET_COOKIE, headers.get(Http.HeaderNames.SET_COOKIE).allValues());
}

if (headers.contains(Http.HeaderNames.SET_COOKIE2)) {
cookies = cookies == null ? new HashMap<>() : cookies;
cookies.put(SET_COOKIE2, headers.values(Http.HeaderNames.SET_COOKIE2));
cookies.put(SET_COOKIE2, headers.get(Http.HeaderNames.SET_COOKIE2).allValues());
}

if (cookies != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ void testQueryParams() {
assertThat(helper.path(), is(UriPath.create("/loom/quick")));
assertThat(helper.port(), is(8080));
assertThat(helper.scheme(), is("http"));
assertThat(helper.query(), is(query));
assertThat(helper.query().value("p1"), is("v1"));
assertThat(helper.query().value("p2"), is("v2"));
assertThat(helper.query().value("p3"), is("//v3//"));
assertThat(helper.query().getRaw("p3"), is("%2F%2Fv3%2F%2F"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ void testCookiePut() {
}
}

@Test
@Order(3)
void testCookieGetAfterPut() {
try (Http1ClientResponse response = client.get("/cookie").request()) {
assertThat(response.status(), is(Http.Status.OK_200));
}
}

private static void getHandler(ServerRequest req, ServerResponse res) {
if (req.headers().contains(Http.HeaderNames.COOKIE)) {
Http.Header cookies = req.headers().get(Http.HeaderNames.COOKIE);
Expand All @@ -111,6 +119,10 @@ private static void putHandler(ServerRequest req, ServerResponse res) {
&& cookies.allValues().contains("flavor2=vanilla")
&& cookies.allValues().contains("flavor3=strawberry")
&& cookies.allValues().contains("flavor4=raspberry")) {
// clear flavor1 and flavor2
res.header(Http.HeaderNames.SET_COOKIE,
"flavor1=; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Max-Age=0",
"flavor2=; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Max-Age=0");
res.status(Http.Status.OK_200).send();
} else {
res.status(Http.Status.BAD_REQUEST_400).send();
Expand Down

0 comments on commit 4de96df

Please sign in to comment.