-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for changing admin password.
Make /password.txt writable so that it can be changed when admin password changes.
- Loading branch information
Showing
7 changed files
with
185 additions
and
63 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
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
106 changes: 106 additions & 0 deletions
106
src/test/java/org/glassfish/main/distributions/docker/ChangePasswordsIT.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,106 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package org.glassfish.main.distributions.docker; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.SecureRandom; | ||
import java.util.Base64; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import static org.glassfish.main.distributions.docker.CommonIntegrationTests.assertDefaultServerRoot; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* | ||
* @author Ondro Mihalyi | ||
*/ | ||
@Testcontainers | ||
public class ChangePasswordsIT { | ||
|
||
@SuppressWarnings({"rawtypes", "resource"}) | ||
@Container | ||
private final GenericContainer server = new GenericContainer<>(System.getProperty("docker.glassfish.image")) | ||
.withExposedPorts(8080, 4848) | ||
.withEnv("AS_ADMIN_MASTERPASSWORD", "mymasterpassword") | ||
.withEnv("AS_ADMIN_PASSWORD", "myadminpassword") | ||
.withLogConsumer(o -> System.err.print("GF: " + o.getUtf8String())); | ||
|
||
@Test | ||
void getRoot() throws Exception { | ||
assertDefaultServerRoot(server); | ||
} | ||
|
||
@Test | ||
void customAdminPassword() throws Exception { | ||
URI uri = URI.create("https://localhost:" + server.getMappedPort(4848) + "/management/domain.json"); | ||
|
||
try (HttpClient client = newInsecureHttpClient()) { | ||
String basicAuthValue = basicAuthValue("admin", "myadminpassword"); | ||
final HttpResponse<Void> response = client.send(HttpRequest.newBuilder(uri) | ||
.setHeader("Authorization", basicAuthValue) | ||
.build(), HttpResponse.BodyHandlers.discarding()); | ||
assertEquals(200, response.statusCode(), "Response code"); | ||
} | ||
} | ||
|
||
private static HttpClient newInsecureHttpClient() throws KeyManagementException, NoSuchAlgorithmException { | ||
SSLContext sslContext = SSLContext.getInstance("TLS"); | ||
sslContext.init(null, trustAllCerts, new SecureRandom()); | ||
HttpClient client = HttpClient.newBuilder() | ||
.sslContext(sslContext) | ||
.build(); | ||
return client; | ||
} | ||
|
||
private static String basicAuthValue(String user, String password) { | ||
String userCredentials = user + ":" + password; | ||
String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userCredentials.getBytes())); | ||
return basicAuth; | ||
} | ||
|
||
private static final TrustManager[] trustAllCerts = new TrustManager[]{ | ||
new X509TrustManager() { | ||
@Override | ||
public java.security.cert.X509Certificate[] getAcceptedIssuers() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void checkClientTrusted( | ||
java.security.cert.X509Certificate[] certs, String authType) { | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted( | ||
java.security.cert.X509Certificate[] certs, String authType) { | ||
} | ||
} | ||
}; | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/org/glassfish/main/distributions/docker/CommonIntegrationTests.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,65 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package org.glassfish.main.distributions.docker; | ||
|
||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.stringContainsInOrder; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* | ||
* @author Ondro Mihalyi | ||
*/ | ||
public final class CommonIntegrationTests { | ||
|
||
private CommonIntegrationTests() { | ||
} | ||
|
||
static void assertDefaultServerRoot(GenericContainer server) throws Exception { | ||
URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL(); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
String content; | ||
try { | ||
connection.setRequestMethod("GET"); | ||
assertEquals(200, connection.getResponseCode(), "Response code"); | ||
try (InputStream in = connection.getInputStream()) { | ||
content = new String(in.readAllBytes(), StandardCharsets.UTF_8); | ||
} | ||
} finally { | ||
connection.disconnect(); | ||
} | ||
assertThat(content, stringContainsInOrder("Eclipse GlassFish", "index.html", "production-quality")); | ||
} | ||
|
||
static void assertEmbeddedDefaultRoot(GenericContainer server) throws Exception { | ||
URL url = URI.create("http://localhost:" + server.getMappedPort(8080) + "/").toURL(); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
try { | ||
connection.setRequestMethod("GET"); | ||
assertEquals(404, connection.getResponseCode(), "Response code"); | ||
} finally { | ||
connection.disconnect(); | ||
} | ||
} | ||
} |
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