Skip to content

Commit

Permalink
Address the changes!
Browse files Browse the repository at this point in the history
  • Loading branch information
sarpsahinalp committed Nov 27, 2024
1 parent 013b0e7 commit b7ae64b
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
public class JavaSecurityTestCaseFactoryAndBuilder implements SecurityTestCaseAbstractFactoryAndBuilder {

//<editor-fold desc="Attributes">
/**
* The package name where the main classes reside.
*/
private static final String ARES_PACKAGE = "de.tum.cit.ase.ares";
/**
* The build tool used in the project (e.g., Maven or Gradle).
*/
Expand Down Expand Up @@ -380,7 +384,7 @@ public void executeSecurityTestCases() {
"allowedListedClasses",
Stream.concat(
Arrays.stream(testClasses),
("de.tum.cit.ase.ares").equals(packageName) ? Arrays.stream(functionClasses) : Stream.of("de.tum.cit.ase.ares")
(ARES_PACKAGE).equals(packageName) ? Arrays.stream(functionClasses) : Stream.of(ARES_PACKAGE)
).toArray(String[]::new),
javaAOPMode.toString());
javaArchUnitTestCases.forEach(javaArchitectureTestCase -> javaArchitectureTestCase.executeArchitectureTestCase(javaArchitectureMode));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,156 @@
package de.tum.cit.ase.ares.integration;

import de.tum.cit.ase.ares.integration.testuser.ArchitectureSecurityUser;
import de.tum.cit.ase.ares.testutilities.TestTest;
import de.tum.cit.ase.ares.testutilities.UserBased;
import de.tum.cit.ase.ares.testutilities.UserTestResults;
import org.junit.platform.testkit.engine.Events;

import static de.tum.cit.ase.ares.testutilities.CustomConditions.testFailedWith;

@UserBased(ArchitectureSecurityUser.class)
public class ArchitectureSecurityTest {
// TODO Sarp: Implement tests

@UserTestResults
private static Events tests;

// <editor-fold desc="File System Rules">
@TestTest
void testArchUnitFileAccess() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitFileAccess", SecurityException.class));
}

@TestTest
void testWalaFileAccess() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaFileAccess", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Network Rules">
@TestTest
void testArchUnitNetworkAccess() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitNetworkAccess", SecurityException.class));
}

@TestTest
void testWalaNetworkAccess() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaNetworkAccess", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Command Execution Rules">
@TestTest
void testArchUnitCommandExecution() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitCommandExecution", SecurityException.class));
}

@TestTest
void testWalaCommandExecution() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaCommandExecution", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Thread Creation Rules">
@TestTest
void testArchUnitThreadCreation() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitThreadCreation", SecurityException.class));
}

@TestTest
void testWalaThreadCreation() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWaLaThreadCreation", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Package Import Rules">
@TestTest
void testArchUnitPackageImport() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitPackageImport", SecurityException.class));
}

@TestTest
void testWalaPackageImport() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaPackageImport", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="JVMTermination Rules">
@TestTest
void testArchUnitJVMTermination() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitJVMTermination", SecurityException.class));
}

@TestTest
void testWalaJVMTermination() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaJVMTermination", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Reflection Rules">
@TestTest
void testArchUnitReflection() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitReflection", SecurityException.class));
}

@TestTest
void testWalaReflection() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaReflection", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Serialization Rules">
@TestTest
void testArchUnitSerialization() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitSerialization", SecurityException.class));
}

@TestTest
void testWalaSerialization() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaSerialization", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Classloading Rules">
@TestTest
void testArchUnitClassloading() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitClassloading", SecurityException.class));
}

@TestTest
void testWalaClassloading() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaClassloading", SecurityException.class));
}
// </editor-fold>

// <editor-fold desc="Third Party Package Access Rules">
@TestTest
void testArchUnitThirdPartyPackageAccess() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testArchUnitThirdPartyPackageAccess", SecurityException.class));
}

@TestTest
void testWalaThirdPartyPackageAccess() {
tests.assertThatEvents().haveExactly(1,
testFailedWith("testWalaThirdPartyPackageAccess", SecurityException.class));
}
// </editor-fold>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,35 @@
@StrictTimeout(5)
public class ArchitectureSecurityUser {

// <editor-fold desc="File System Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/classloading")
void testArchUnitClassloading() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/fileSystem")
void testArchUnitFileAccess() {
// do nothing
}

@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/classloading")
void testWalaClassloading() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/fileSystem")
void testWalaFileAccess() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Network Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/network")
void testArchUnitNetworkAccess() {
// do nothing
}

@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/network")
void testWalaNetworkAccess() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Command Execution Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/commandexecution")
void testArchUnitCommandExecution() {
Expand All @@ -32,31 +49,51 @@ void testArchUnitCommandExecution() {
void testWalaCommandExecution() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Thread Creation Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/fileSystem")
void testArchUnitFileAccess() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/thread_manipulation")
void testArchUnitThreadCreation() {
// do nothing
}

@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/fileSystem")
void testWalaFileAccess() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/thread_manipulation")
void testWalaThreadCreation() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Package Import Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/network")
void testArchUnitNetworkAccess() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/packageImport")
void testArchUnitPackageImport() {
// do nothing
}

@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/network")
void testWalaNetworkAccess() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/packageImport")
void testWalaPackageImport() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="JVMTermination Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/jvmTermination")
void testArchUnitJVMTermination() {
// do nothing
}

@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/jvmTermination")
void testWalaJVMTermination() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Reflection Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/reflection")
void testArchUnitReflection() {
Expand All @@ -68,7 +105,9 @@ void testArchUnitReflection() {
void testWalaReflection() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Serialization Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/serialization")
void testArchUnitSerialization() {
Expand All @@ -80,29 +119,34 @@ void testArchUnitSerialization() {
void testWalaSerialization() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Classloading Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/thirdpartypackage")
void testArchUnitThirdPartyPackageAccess() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/classloading")
void testArchUnitClassloading() {
// do nothing
}

@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/thirdpartypackage")
void testWalaThirdPartyPackageAccess() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/classloading")
void testWalaClassloading() {
// do nothing
}
// </editor-fold>

// <editor-fold desc="Third Party Package Access Rules">
@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/jvmTermination")
void testArchUnitJVMTermination() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicy.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/thirdPartyAccess")
void testArchUnitThirdPartyPackageAccess() {
// do nothing
}

@PublicTest
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/jvmTermination")
void testWalaJVMTermination() {
@Policy(value = "src/test/resources/de/tum/cit/ase/ares/integration/testuser/securitypolicies/EverythingForbiddenPolicyWala.yaml", withinPath = "test-classes/de/tum/cit/ase/ares/integration/testuser/subject/architectureTests/thirdPartyAccess")
void testWalaThirdPartyPackageAccess() {
// do nothing
}
// </editor-fold>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.tum.cit.ase.ares.integration.testuser.subject.architectureTests.packageImport;

import ch.qos.logback.core.FileAppender;

import java.io.IOException;

public class PackageImportPenguin {

void accessPathThroughThirdPartyPackage() throws IOException {
FileAppender fileAppender = new FileAppender();
fileAppender.openFile("path/to/file");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package de.tum.cit.ase.ares.integration.testuser.subject.architectureTests.student;
package de.tum.cit.ase.ares.integration.testuser.subject.architectureTests.thirdPartyAccess;

import de.tum.cit.ase.ares.integration.testuser.subject.architectureTests.thirdpartypackage.ThirdPartyPackagePenguin;

import java.io.IOException;

public class Student {
public class ThirdPartyAccessPenguin {
public void accessPathThroughThirdPartyPackage() throws IOException {
ThirdPartyPackagePenguin.accessFileSystem();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package de.tum.cit.ase.ares.integration.testuser.subject.architectureTests.thread_manipulation;

public class ThreadAccessPenguin {

void createThread() {
Thread thread = new Thread();
thread.start();
}
}

0 comments on commit b7ae64b

Please sign in to comment.