Skip to content

Commit

Permalink
add TLS and non-TLS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored and minio-trusted committed Sep 16, 2021
1 parent c21b24c commit 25d715c
Showing 1 changed file with 58 additions and 12 deletions.
70 changes: 58 additions & 12 deletions functional/FunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public class FunctionalTest {
private static Path dataFile1Kb;
private static Path dataFile6Mb;
private static String endpoint;
private static String endpointTLS;
private static String accessKey;
private static String secretKey;
private static String region;
Expand Down Expand Up @@ -3804,10 +3805,22 @@ public static boolean downloadMinio() throws IOException {
return true;
}

public static Process runMinio() throws Exception {
public static Process runMinio(boolean tls) throws Exception {
File binaryPath = new File(new File(System.getProperty("user.dir")), MINIO_BINARY);
ProcessBuilder pb =
new ProcessBuilder(binaryPath.getPath(), "server", "--config-dir", ".cfg", ".d{1...4}");
ProcessBuilder pb;
if (tls) {
pb =
new ProcessBuilder(
binaryPath.getPath(),
"server",
"--address",
":9001",
"--config-dir",
".cfg",
".d{1...4}");
} else {
pb = new ProcessBuilder(binaryPath.getPath(), "server", ".d{1...4}");
}

Map<String, String> env = pb.environment();
env.put("MINIO_ROOT_USER", "minio");
Expand All @@ -3823,7 +3836,11 @@ public static Process runMinio() throws Exception {
pb.redirectErrorStream(true);
pb.redirectOutput(ProcessBuilder.Redirect.to(new File(MINIO_BINARY + ".log")));

System.out.println("starting minio server");
if (tls) {
System.out.println("starting minio server in TLS");
} else {
System.out.println("starting minio server");
}
Process p = pb.start();
Thread.sleep(10 * 1000); // wait for 10 seconds to do real start.
return p;
Expand All @@ -3846,10 +3863,12 @@ public static void main(String[] args) throws Exception {
replicationBucketArn = System.getenv("MINIO_JAVA_TEST_REPLICATION_BUCKET_ARN");

Process minioProcess = null;
Process minioProcessTLS = null;

String kmsKeyName = "my-minio-key";
if (args.length != 4) {
endpoint = "https://localhost:9000";
endpoint = "http://localhost:9000";
endpointTLS = "https://localhost:9001";
accessKey = "minio";
secretKey = "minio123";
region = "us-east-1";
Expand All @@ -3859,7 +3878,7 @@ public static void main(String[] args) throws Exception {
System.exit(-1);
}

minioProcess = runMinio();
minioProcess = runMinio(false);
try {
int exitValue = minioProcess.exitValue();
System.out.println("minio server process exited with " + exitValue);
Expand All @@ -3868,6 +3887,16 @@ public static void main(String[] args) throws Exception {
} catch (IllegalThreadStateException e) {
ignore();
}

minioProcessTLS = runMinio(true);
try {
int exitValue = minioProcessTLS.exitValue();
System.out.println("minio server process exited with " + exitValue);
System.out.println("usage: FunctionalTest <ENDPOINT> <ACCESSKEY> <SECRETKEY> <REGION>");
System.exit(-1);
} catch (IllegalThreadStateException e) {
ignore();
}
} else {
kmsKeyName = System.getenv("MINIO_JAVA_TEST_KMS_KEY_NAME");
if (kmsKeyName == null) {
Expand All @@ -3880,7 +3909,6 @@ public static void main(String[] args) throws Exception {
region = args[3];
}

isSecureEndpoint = endpoint.toLowerCase(Locale.US).contains("https://");
if (kmsKeyName != null) {
Map<String, String> myContext = new HashMap<>();
myContext.put("key1", "value1");
Expand All @@ -3889,19 +3917,36 @@ public static void main(String[] args) throws Exception {

int exitValue = 0;
try {
// Run non-TLS tests on plain HTTP endpoint
client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
client.ignoreCertCheck();
MinioAdminClient adminClient =
MinioAdminClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
adminClientTests = new TestMinioAdminClient(adminClient, mintEnv);
// Enable trace for debugging.
// client.traceOn(System.out);
if (!mintEnv) System.out.println(">>> Running tests:");
FunctionalTest.runTests();

isSecureEndpoint = true;

// Run TLS tests on TLS endpoint
client =
MinioClient.builder().endpoint(endpointTLS).credentials(accessKey, secretKey).build();
client.ignoreCertCheck();
adminClient =
MinioAdminClient.builder()
.endpoint(endpoint)
.endpoint(endpointTLS)
.credentials(accessKey, secretKey)
.httpClient(getUnsafeOkHttpClient())
.build();
adminClientTests = new TestMinioAdminClient(adminClient, mintEnv);
// Enable trace for debugging.
// client.traceOn(System.out);
if (!mintEnv) System.out.println(">>> Running tests:");
if (!mintEnv) System.out.println(">>> Running TLS tests:");
FunctionalTest.runTests();

isSecureEndpoint = false;

if (!mintEnv) {
System.out.println();
System.out.println(">>> Running tests for region:");
Expand All @@ -3915,13 +3960,11 @@ public static void main(String[] args) throws Exception {
.credentials(accessKey, secretKey)
.region(region)
.build();
client.ignoreCertCheck();
adminClient =
MinioAdminClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.region(region)
.httpClient(getUnsafeOkHttpClient())
.build();
adminClientTests = new TestMinioAdminClient(adminClient, mintEnv);
FunctionalTest.runTests();
Expand All @@ -3935,6 +3978,9 @@ public static void main(String[] args) throws Exception {
if (minioProcess != null) {
minioProcess.destroy();
}
if (minioProcessTLS != null) {
minioProcessTLS.destroy();
}
}

System.exit(exitValue);
Expand Down

0 comments on commit 25d715c

Please sign in to comment.