Skip to content

Commit

Permalink
[ELY-2496] Add integrity command test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicarod7 committed Apr 19, 2023
1 parent 531b17c commit 95b1004
Show file tree
Hide file tree
Showing 45 changed files with 1,176 additions and 14 deletions.
2 changes: 0 additions & 2 deletions tool/mycredstore.cs

This file was deleted.

3 changes: 3 additions & 0 deletions tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
<log4j.defaultInitOverride>true</log4j.defaultInitOverride>
<test.level>${test.level}</test.level>
</systemPropertyVariables>
<environmentVariables>
<FS_INTEGRITY_PASSWORD_TEST_VAR>Guk]i%Aua4-wB</FS_INTEGRITY_PASSWORD_TEST_VAR> <!-- gitleaks:allow -->
</environmentVariables>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<enableAssertions>true</enableAssertions>
<trimStackTrace>false</trimStackTrace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

import javax.crypto.SecretKey;

import org.apache.commons.cli.MissingArgumentException;
import org.junit.Test;
import org.wildfly.security.auth.principal.NamePrincipal;
Expand All @@ -44,6 +46,7 @@
public class FileSystemEncryptRealmCommandTest extends AbstractCommandTest {

private static final String RELATIVE_BASE_DIR = "./target/test-classes/filesystem-encrypt/";
private static final String CREDENTIAL_STORE_PATH = RELATIVE_BASE_DIR + "mycredstore.cs";

private void run(String inputLocation, String outputLocation, String fileSystemRealmName, int expectedStatus) {
runCommandSilent(inputLocation, outputLocation, fileSystemRealmName, expectedStatus);
Expand All @@ -55,19 +58,29 @@ private void run(String bulkConvertFile, int expectedStatus) {

private void runCommand(String inputLocation, String outputLocation, String fileSystemRealmName, String encoded, boolean create, int expectedStatus) {
String[] requiredArgs;
requiredArgs = new String[]{"--input-location", inputLocation, "--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--encoded", encoded, "--create", String.valueOf(create), "--credential-store", "mycredstore.cs"};
requiredArgs = new String[]{"--input-location", inputLocation, "--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--encoded", encoded, "--create", String.valueOf(create), "--credential-store", CREDENTIAL_STORE_PATH};
executeCommandAndCheckStatus(requiredArgs, expectedStatus);
}

private void runCommand(String inputLocation, String outputLocation, String fileSystemRealmName, int levels, String encoded, boolean create, int expectedStatus) {
String[] requiredArgs;
requiredArgs = new String[]{"--input-location", inputLocation, "--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--levels", String.valueOf(levels), "--encoded", encoded, "--create", String.valueOf(create), "--credential-store", "mycredstore.cs"};
requiredArgs = new String[]{"--input-location", inputLocation, "--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--levels", String.valueOf(levels), "--encoded", encoded, "--create", String.valueOf(create), "--credential-store", CREDENTIAL_STORE_PATH};
executeCommandAndCheckStatus(requiredArgs, expectedStatus);
}

private void runCommand(String inputLocation, String outputLocation, String fileSystemRealmName, String keyStoreLocation,
String keyPairAlias, String keyStorePassword, int levels, boolean create, int expectedStatus) {
String[] requiredArgs;
requiredArgs = new String[]{"--input-location", inputLocation, "--output-location", outputLocation, "--realm-name", fileSystemRealmName,
"--keystore", keyStoreLocation, "--key-pair", keyPairAlias, "--password", keyStorePassword,
"--levels", String.valueOf(levels), "--create", String.valueOf(create),
"--credential-store", CREDENTIAL_STORE_PATH};
executeCommandAndCheckStatus(requiredArgs, expectedStatus);
}

private void runCommand(String inputLocation, String outputLocation, String fileSystemRealmName, String credentialStore, String secretKey, String encoded, boolean create, int expectedStatus) {
String[] requiredArgs;
requiredArgs = new String[]{"--input-location", inputLocation, "--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--credential-store", credentialStore, "--secret-key", secretKey, "--encoded", encoded, "--create", String.valueOf(create), "--credential-store", "mycredstore.cs"};
requiredArgs = new String[]{"--input-location", inputLocation, "--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--credential-store", credentialStore, "--secret-key", secretKey, "--encoded", encoded, "--create", String.valueOf(create)};
executeCommandAndCheckStatus(requiredArgs, expectedStatus);
}

Expand All @@ -79,7 +92,7 @@ private void runCommand(String bulkConvertFile, int expectedStatus) {

private void runCommandInvalid(String outputLocation, String fileSystemRealmName, String encoded, boolean create, int expectedStatus) {
String[] requiredArgs;
requiredArgs = new String[]{"--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--encoded", encoded, "--create", String.valueOf(create), "--credential-store", "mycredstore.cs"};
requiredArgs = new String[]{"--output-location", outputLocation, "--realm-name", fileSystemRealmName, "--encoded", encoded, "--create", String.valueOf(create), "--credential-store", CREDENTIAL_STORE_PATH};
executeCommandAndCheckStatus(requiredArgs, expectedStatus);
}

Expand Down Expand Up @@ -158,14 +171,24 @@ public void testSingleUserWithRoles() throws Exception {
}
}

@Test
public void testSingleUserWithRolesAndIntegrity() throws Exception {
String inputLocation = RELATIVE_BASE_DIR + "fs-unencrypted-realms/single-user-with-roles-and-integrity";
String outputLocation = RELATIVE_BASE_DIR + "fs-encrypted-realms";
String fileSystemRealmName = "single-user-with-roles-and-integrity";
String keyStoreLocation = RELATIVE_BASE_DIR + "mykeystore.pfx";
String keyPairAlias = "integrity-key";
String keyStorePassword = "Guk]i%Aua4-wB";
runCommand(inputLocation, outputLocation, fileSystemRealmName, keyStoreLocation, keyPairAlias, keyStorePassword, 2, true, 0);
}

@Test
public void testSingleUserWithRolesAndKey() throws Exception {
String inputLocation = RELATIVE_BASE_DIR + "fs-unencrypted-realms/single-user-with-key/";
String outputLocation = RELATIVE_BASE_DIR + "fs-encrypted-realms";
String fileSystemRealmName = "single-user-with-key";
String credentialStore = RELATIVE_BASE_DIR + "mycredstore.cs";
String key = "key";
runCommand(inputLocation, outputLocation, fileSystemRealmName, credentialStore, key, "false", false, 0);
runCommand(inputLocation, outputLocation, fileSystemRealmName, CREDENTIAL_STORE_PATH, key, "false", false, 0);
String file = "target/test-classes/filesystem-encrypt/fs-encrypted-realms/single-user-with-key/O/N/ONSWG4TFORYGK4TTN5XA.xml";
if(!fileExists(file)){
throw new FileNotFoundException("Encrypted Identity/Identities Missing: " + file);
Expand All @@ -177,7 +200,7 @@ public void testSingleUserAndVerify() throws Exception {
String inputLocation = RELATIVE_BASE_DIR + "fs-unencrypted-realms/single-user/";
String outputLocation = RELATIVE_BASE_DIR + "fs-encrypted-realms";
String fileSystemRealmName = "verify";
String credentialStoreLocation = RELATIVE_BASE_DIR + "mycredstore.cs";
String credentialStoreLocation = CREDENTIAL_STORE_PATH;
String keyAlias = "key";
runCommand(inputLocation, outputLocation, fileSystemRealmName, credentialStoreLocation, keyAlias, "false", false, 0);

Expand All @@ -204,4 +227,4 @@ private boolean fileExists(String path) {
File tempFile = new File(path);
return tempFile.exists();
}
}
}
Loading

0 comments on commit 95b1004

Please sign in to comment.