forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3.x] OIDC original uri resolving leaving out query params (helidon-i…
…o#6342) OIDC original uri resolving query fix Signed-off-by: David Kral <david.k.kral@oracle.com>
- Loading branch information
Showing
3 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...idc/src/test/java/io/helidon/security/providers/oidc/TenantAuthenticationHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.security.providers.oidc; | ||
|
||
import java.net.URI; | ||
|
||
import io.helidon.security.ProviderRequest; | ||
import io.helidon.security.Security; | ||
import io.helidon.security.SecurityEnvironment; | ||
import io.helidon.security.providers.oidc.common.OidcConfig; | ||
import io.helidon.security.providers.oidc.common.Tenant; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Unit test for {@link TenantAuthenticationHandler}. | ||
*/ | ||
public class TenantAuthenticationHandlerTest { | ||
|
||
@Test | ||
public void testOriginalUri() { | ||
OidcConfig oidcConfig = OidcConfig.builder() | ||
.clientId("test") | ||
.clientSecret("123") | ||
.identityUri(URI.create("http://localhost:1234")) | ||
.build(); | ||
|
||
Tenant tenant = mock(Tenant.class); | ||
when(tenant.tenantConfig()).thenReturn(oidcConfig); | ||
|
||
TenantAuthenticationHandler authenticationHandler = new TenantAuthenticationHandler(oidcConfig, tenant, false, true); | ||
ProviderRequest providerRequest = mock(ProviderRequest.class); | ||
SecurityEnvironment securityEnvironment = SecurityEnvironment.builder() | ||
.header(Security.HEADER_ORIG_URI, "/test?someUri=value") | ||
.targetUri(URI.create("http://localhost:1234/incorrect")) | ||
.build(); | ||
when(providerRequest.env()).thenReturn(securityEnvironment); | ||
|
||
assertThat(authenticationHandler.origUri(providerRequest), is("/test?someUri=value")); | ||
|
||
securityEnvironment = SecurityEnvironment.builder() | ||
.header(Security.HEADER_ORIG_URI, "/noQuery") | ||
.targetUri(URI.create("http://localhost:1234/incorrect")) | ||
.build(); | ||
when(providerRequest.env()).thenReturn(securityEnvironment); | ||
|
||
assertThat(authenticationHandler.origUri(providerRequest), is("/noQuery")); | ||
} | ||
|
||
@Test | ||
public void testOriginalUriMissingHeader() { | ||
OidcConfig oidcConfig = OidcConfig.builder() | ||
.clientId("test") | ||
.clientSecret("123") | ||
.identityUri(URI.create("http://localhost:1234")) | ||
.build(); | ||
|
||
Tenant tenant = mock(Tenant.class); | ||
when(tenant.tenantConfig()).thenReturn(oidcConfig); | ||
|
||
TenantAuthenticationHandler authenticationHandler = new TenantAuthenticationHandler(oidcConfig, tenant, false, true); | ||
ProviderRequest providerRequest = mock(ProviderRequest.class); | ||
SecurityEnvironment securityEnvironment = SecurityEnvironment.builder() | ||
.targetUri(URI.create("http://localhost:1234/test?someUri=value")) | ||
.build(); | ||
when(providerRequest.env()).thenReturn(securityEnvironment); | ||
|
||
assertThat(authenticationHandler.origUri(providerRequest), is("/test?someUri=value")); | ||
|
||
securityEnvironment = SecurityEnvironment.builder() | ||
.targetUri(URI.create("http://localhost:1234/noQuery")) | ||
.build(); | ||
when(providerRequest.env()).thenReturn(securityEnvironment); | ||
|
||
assertThat(authenticationHandler.origUri(providerRequest), is("/noQuery")); | ||
} | ||
|
||
} |