-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPA-102: Error pages are not rendered correctly in the ehealthID Rely…
…ing Party (#68)
- Loading branch information
1 parent
c1ffe77
commit d168f3f
Showing
5 changed files
with
179 additions
and
54 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
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