-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle path prefix when serving web interface assets. (#21104)
* Handle path prefix when serving web interface assets. * Adding tests for frontend asset consistency. * Adding changelog snippet.
- Loading branch information
1 parent
5d333f6
commit ab65275
Showing
7 changed files
with
213 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type = "f" | ||
message = "Handle path prefix when serving web interface assets." | ||
|
||
issues = ["21015"] | ||
pulls = ["21104"] |
59 changes: 59 additions & 0 deletions
59
...ackend-tests/src/test/java/org/graylog2/web/resources/WebInterfaceAssetsResourceBase.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,59 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.web.resources; | ||
|
||
import io.restassured.http.ContentType; | ||
import io.restassured.specification.RequestSpecification; | ||
import org.apache.http.HttpStatus; | ||
import org.graylog.testing.completebackend.apis.GraylogApis; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
public abstract class WebInterfaceAssetsResourceBase { | ||
private final GraylogApis apis; | ||
|
||
protected WebInterfaceAssetsResourceBase(GraylogApis apis) { | ||
this.apis = apis; | ||
} | ||
|
||
private RequestSpecification backend() { | ||
return given() | ||
.baseUri(apis.backend().uri()) | ||
.port(apis.backend().apiPort()); | ||
} | ||
|
||
protected void testFrontend(String prefix) { | ||
final var scriptSrcs = backend() | ||
.get(prefix) | ||
.then() | ||
.assertThat() | ||
.statusCode(HttpStatus.SC_OK) | ||
.contentType(ContentType.HTML) | ||
.extract() | ||
.htmlPath() | ||
.<String>getList("html.body.script*.@src"); | ||
|
||
scriptSrcs.forEach(src -> { | ||
backend() | ||
.get(src) | ||
.then() | ||
.assertThat() | ||
.statusCode(HttpStatus.SC_OK) | ||
.contentType(ContentType.JSON); | ||
}); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...-backend-tests/src/test/java/org/graylog2/web/resources/WebInterfaceAssetsResourceIT.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,36 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.web.resources; | ||
|
||
import org.graylog.testing.completebackend.MavenProjectDirProviderWithFrontend; | ||
import org.graylog.testing.completebackend.apis.GraylogApis; | ||
import org.graylog.testing.containermatrix.SearchServer; | ||
import org.graylog.testing.containermatrix.annotations.ContainerMatrixTest; | ||
import org.graylog.testing.containermatrix.annotations.ContainerMatrixTestsConfiguration; | ||
|
||
@ContainerMatrixTestsConfiguration(mavenProjectDirProvider = MavenProjectDirProviderWithFrontend.class, | ||
searchVersions = {SearchServer.DATANODE_DEV}) | ||
public class WebInterfaceAssetsResourceIT extends WebInterfaceAssetsResourceBase { | ||
public WebInterfaceAssetsResourceIT(GraylogApis graylogApis) { | ||
super(graylogApis); | ||
} | ||
|
||
@ContainerMatrixTest | ||
void testIndexHtml() { | ||
testFrontend("/"); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ests/src/test/java/org/graylog2/web/resources/WebInterfaceAssetsResourceWithPrefixIT.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,39 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.web.resources; | ||
|
||
import org.graylog.testing.completebackend.MavenProjectDirProviderWithFrontend; | ||
import org.graylog.testing.completebackend.apis.GraylogApis; | ||
import org.graylog.testing.containermatrix.SearchServer; | ||
import org.graylog.testing.containermatrix.annotations.ContainerMatrixTest; | ||
import org.graylog.testing.containermatrix.annotations.ContainerMatrixTestsConfiguration; | ||
|
||
@ContainerMatrixTestsConfiguration(mavenProjectDirProvider = MavenProjectDirProviderWithFrontend.class, | ||
searchVersions = {SearchServer.DATANODE_DEV}, | ||
additionalConfigurationParameters = { | ||
@ContainerMatrixTestsConfiguration.ConfigurationParameter(key = "GRAYLOG_HTTP_PUBLISH_URI", value = "http://localhost:9000/graylog") | ||
}) | ||
public class WebInterfaceAssetsResourceWithPrefixIT extends WebInterfaceAssetsResourceBase { | ||
public WebInterfaceAssetsResourceWithPrefixIT(GraylogApis graylogApis) { | ||
super(graylogApis); | ||
} | ||
|
||
@ContainerMatrixTest | ||
void testIndexHtml() { | ||
testFrontend("/graylog/"); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...rc/test/java/org/graylog/testing/completebackend/MavenProjectDirProviderWithFrontend.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,24 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog.testing.completebackend; | ||
|
||
public class MavenProjectDirProviderWithFrontend extends DefaultMavenProjectDirProvider { | ||
@Override | ||
public boolean includeFrontend() { | ||
return true; | ||
} | ||
} |
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