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 36a6630
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 43 deletions.
1 change: 1 addition & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
./gradlew runFunctionalTest
javac -cp api/build/libs/minio-${DEV_VERSION}-all.jar functional/TestUserAgent.java
java -Dversion=${DEV_VERSION} -cp api/build/libs/minio-${DEV_VERSION}-all.jar:functional TestUserAgent
./gradlew clean
./gradlew build -Prelease
javac -cp api/build/libs/minio-${RELEASE_VERSION}-all.jar functional/TestUserAgent.java
java -Dversion=${RELEASE_VERSION} -cp api/build/libs/minio-${RELEASE_VERSION}-all.jar:functional TestUserAgent
Expand Down
183 changes: 140 additions & 43 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,12 +3836,112 @@ 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;
}

public static void runAutomatedEndpointTests() throws Exception {
// Run non-TLS tests on plain HTTP endpoint
client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
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(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 TLS tests:");
FunctionalTest.runTests();

isSecureEndpoint = false;

if (!mintEnv) {
System.out.println();
System.out.println(">>> Running tests for region:");
isQuickTest = true;
// Get new bucket name to avoid minio azure gateway failure.
bucketName = getRandomName();
bucketNameWithLock = getRandomName();
client =
MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.region(region)
.build();
adminClient =
MinioAdminClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.region(region)
.build();
adminClientTests = new TestMinioAdminClient(adminClient, mintEnv);
FunctionalTest.runTests();
}
}

public static void runCustomEndpointTests() throws Exception {
isSecureEndpoint = endpoint.toLowerCase(Locale.US).contains("https://");
client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
client.ignoreCertCheck();
MinioAdminClient adminClient =
MinioAdminClient.builder()
.endpoint(endpoint)
.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 custom endpoint tests:");
FunctionalTest.runTests();

if (!mintEnv) {
System.out.println();
System.out.println(">>> Running custom endpoint tests for region:");
isQuickTest = true;
// Get new bucket name to avoid minio azure gateway failure.
bucketName = getRandomName();
bucketNameWithLock = getRandomName();
client =
MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.region(region)
.build();
client.ignoreCertCheck();
adminClient =
MinioAdminClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.httpClient(getUnsafeOkHttpClient())
.region(region)
.build();
adminClientTests = new TestMinioAdminClient(adminClient, mintEnv);
FunctionalTest.runTests();
}
}

/** main(). */
public static void main(String[] args) throws Exception {
String mintMode = System.getenv("MINT_MODE");
Expand All @@ -3846,10 +3959,13 @@ public static void main(String[] args) throws Exception {
replicationBucketArn = System.getenv("MINIO_JAVA_TEST_REPLICATION_BUCKET_ARN");

Process minioProcess = null;
Process minioProcessTLS = null;

boolean automated = true;
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 +3975,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 +3984,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 @@ -3878,9 +4004,9 @@ public static void main(String[] args) throws Exception {
accessKey = args[1];
secretKey = args[2];
region = args[3];
automated = false;
}

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

int exitValue = 0;
try {
client = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
client.ignoreCertCheck();
MinioAdminClient adminClient =
MinioAdminClient.builder()
.endpoint(endpoint)
.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:");
FunctionalTest.runTests();
if (!mintEnv) {
System.out.println();
System.out.println(">>> Running tests for region:");
isQuickTest = true;
// Get new bucket name to avoid minio azure gateway failure.
bucketName = getRandomName();
bucketNameWithLock = getRandomName();
client =
MinioClient.builder()
.endpoint(endpoint)
.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();
if (automated) {
runAutomatedEndpointTests();
} else {
runCustomEndpointTests();
}
} catch (Exception e) {
if (!mintEnv) {
Expand All @@ -3935,6 +4029,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 36a6630

Please sign in to comment.