Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ui/open-api-ui/src/main/resources/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@

window.onload = function() {

// If Url is relative, append the host and port
var oar = "${oauth2RedirectUrl}";
if(oar.startsWith("/")){
oar = window.location.protocol + "//" + window.location.host + oar;
// Resolve against the page URL ("-" means not configured, see IndexHtmlCreator)
if (oar !== "-") {
Comment thread
arnabnandy7 marked this conversation as resolved.
Resolved
try {
oar = new URL(oar, window.location.href).href;
} catch (e) {
// Keep the configured value when it cannot be parsed
}
}

var ui = SwaggerUIBundle({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,24 @@ void testCreateWithPreauthorizeBoth() throws IOException {

@Test
void testOauth2RedirectReplacement() throws IOException {
String title = "Test Title";
Map<Option, String> options = new HashMap<>();
options.put(Option.title, title);
options.put(Option.oauth2RedirectUrl, "oauth2-redirect.html");
byte[] indexHtml = IndexHtmlCreator.createIndexHtml(options);

String html = new String(indexHtml);

assertTrue(html.contains("var oar"), "Missing declaration of 'oar'");
assertTrue(html.contains("var oar = \"oauth2-redirect.html\";"));
assertTrue(html.contains("oar = new URL(oar, window.location.href).href;"));
Comment thread
arnabnandy7 marked this conversation as resolved.
Resolved
}

@Test
void testDefaultOauth2RedirectReplacement() throws IOException {
byte[] indexHtml = IndexHtmlCreator.createIndexHtml();

String html = new String(indexHtml);

assertTrue(html.contains("var oar = \"-\";"));
assertTrue(html.contains("if (oar !== \"-\")"));
}

@Test
Expand Down
Loading