-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EPA-102: Error pages are not rendered correctly in the ehealthID Relying Party #68
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
94 changes: 94 additions & 0 deletions
94
ehealthid-rp/src/test/java/com/oviva/ehealthid/relyingparty/test/EmbeddedRelyingParty.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,94 @@ | ||
package com.oviva.ehealthid.relyingparty.test; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
import com.github.tomakehurst.wiremock.junit.Stubbing; | ||
import com.oviva.ehealthid.relyingparty.Main; | ||
import com.oviva.ehealthid.relyingparty.cfg.ConfigProvider; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.net.URI; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Properties; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class EmbeddedRelyingParty implements AutoCloseable { | ||
|
||
private static final String DISCOVERY_PATH = "/.well-known/openid-configuration"; | ||
private Main application; | ||
private WireMockServer wireMockServer; | ||
|
||
public URI start() throws ExecutionException, InterruptedException { | ||
|
||
var options = WireMockConfiguration.options().dynamicPort(); | ||
this.wireMockServer = new WireMockServer(options); | ||
wireMockServer.start(); | ||
|
||
var discoveryUri = URI.create(wireMockServer.baseUrl()).resolve(DISCOVERY_PATH); | ||
|
||
var redirectUri = URI.create("https://myapp.example.com"); | ||
|
||
var config = | ||
StaticConfig.fromRawProperties( | ||
""" | ||
federation_enc_jwks_path=src/test/resources/fixtures/example_enc_jwks.json | ||
federation_sig_jwks_path=src/test/resources/fixtures/example_sig_jwks.json | ||
base_uri=%s | ||
idp_discovery_uri=%s | ||
redirect_uris=%s | ||
app_name=Awesome DiGA | ||
port=0 | ||
""" | ||
.formatted(wireMockServer.baseUrl(), discoveryUri, redirectUri)); | ||
|
||
this.application = new Main(config); | ||
|
||
application.start(); | ||
|
||
return application.baseUri(); | ||
} | ||
|
||
public URI baseUri() { | ||
return application.baseUri(); | ||
} | ||
|
||
public Stubbing wireMockStubbing() { | ||
return wireMockServer; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
|
||
Exception cause = null; | ||
|
||
try { | ||
this.application.close(); | ||
} catch (Exception e) { | ||
cause = e; | ||
} | ||
|
||
this.wireMockServer.stop(); | ||
if (cause != null) { | ||
throw cause; | ||
} | ||
} | ||
|
||
record StaticConfig(Map<Object, Object> values) implements ConfigProvider { | ||
|
||
@Override | ||
public Optional<String> get(String name) { | ||
return Optional.ofNullable(values.get(name)).map(Object::toString); | ||
} | ||
|
||
public static ConfigProvider fromRawProperties(String s) { | ||
var props = new Properties(); | ||
try { | ||
props.load(new StringReader(s)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return new StaticConfig(props); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
.../test/java/com/oviva/ehealthid/relyingparty/ws/ThrowableExceptionMapperComponentTest.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,41 @@ | ||
package com.oviva.ehealthid.relyingparty.ws; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.hamcrest.Matchers.startsWith; | ||
|
||
import com.oviva.ehealthid.relyingparty.test.EmbeddedRelyingParty; | ||
import io.restassured.RestAssured; | ||
import java.util.concurrent.ExecutionException; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ThrowableExceptionMapperComponentTest { | ||
|
||
private static EmbeddedRelyingParty app; | ||
|
||
@BeforeAll | ||
static void beforeAll() throws ExecutionException, InterruptedException { | ||
app = new EmbeddedRelyingParty(); | ||
app.start(); | ||
RestAssured.baseURI = app.baseUri().toString(); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() throws Exception { | ||
app.close(); | ||
} | ||
|
||
/** Regression test for: oviva-ag/ehealthid-relying-party #58 / EPA-102 */ | ||
@Test | ||
void toResponse_htmlUnescaped() { | ||
|
||
given() | ||
.accept("text/html,*/*") | ||
.get("/auth") | ||
.then() | ||
.header("content-type", startsWith("text/html")) | ||
.body(startsWith("<!DOCTYPE html>")); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting from spotless/intellij 🤷