Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/improve precision of archunit, add translaiton #34

Merged
merged 20 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ on:
jobs:
build-and-test:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v3
- name: Set up JDK 22
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'adopt'
Expand All @@ -30,17 +30,8 @@ jobs:
sudo wget -q -O - "https://apache.osuosl.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz" | sudo tar xzf - -C /usr/share
sudo ln -s /usr/share/apache-maven-3.9.8/bin/mvn /usr/bin/mvn

- name: Build and Test with Maven
run: |
mvn -B package --file pom.xml -DskipTests
mvn test
- name: Build
run: mvn clean package -DskipTests

- name: Run Tests on Student Submission
run: |
git config --global url.https://github.com/.insteadOf git://github.com/
git clone https://github.com/sarpsahinalp/test-student-submission.git
mkdir test-student-submission/libs
cp target/*.jar test-student-submission/libs
cd test-student-submission
./gradlew build
./gradlew test
- name: Test
run: mvn test
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.1</version>
<configuration>
<forkCount>1</forkCount>
<argLine>-javaagent:${project.build.directory}/ares-2.0.0-SNAPSHOT-agent.jar -Xbootclasspath/a:${user.home}/.m2/repository/org/aspectj/aspectjrt/${aspectj.version}/aspectjrt-${aspectj.version}.jar</argLine>
<argLine>-javaagent:${project.build.directory}${file.separator}ares-2.0.0-SNAPSHOT-agent.jar -Xbootclasspath/a:${user.home}${file.separator}.m2${file.separator}repository${file.separator}org${file.separator}aspectj${file.separator}aspectjrt${file.separator}${aspectj.version}${file.separator}aspectjrt-${aspectj.version}.jar</argLine>
</configuration>
</plugin>
<!-- Shade Plugin to package the agent JAR -->
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/de/tum/cit/ase/ares/api/aop/java/JavaAOPMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.List;
import java.util.stream.Stream;

import static de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationAdviceToolbox.localize;

/**
* Enum representing the different modes of Aspect-Oriented Programming (AOP)
* available for Java in Ares.
Expand Down Expand Up @@ -212,16 +214,16 @@ public void reset() {
method.setAccessible(false);

} catch (ClassNotFoundException e) {
throw new SecurityException("Ares Security Error (Reason: Ares-Code; Stage: Creation): The class for the specific security test case settings could not be found. Ensure the class name is correct and the class is available at runtime.", e);
throw new SecurityException(localize("security.creation.reset.class.not.found.exception"), e);

} catch (NoSuchMethodException e) {
throw new SecurityException("Ares Security Error (Reason: Ares-Code; Stage: Creation): The 'reset' method could not be found in the specified class. Ensure the method exists and is correctly named.", e);
throw new SecurityException(localize("security.creation.reset.no.method.exception"), e);

} catch (IllegalAccessException e) {
throw new SecurityException("Ares Security Error (Reason: Ares-Code; Stage: Creation): Access to the 'reset' method was denied. Ensure the method is public and accessible.", e);
throw new SecurityException(localize("security.creation.reset.illegal.access.exception"), e);

} catch (InvocationTargetException e) {
throw new SecurityException("Ares Security Error (Reason: Ares-Code; Stage: Creation): An error occurred while invoking the 'reset' method. This could be due to an underlying issue within the method implementation.", e);
throw new SecurityException(localize("security.creation.reset.invocation.target.exception"), e);
}
}
//</editor-fold>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static de.tum.cit.ase.ares.api.aop.java.instrumentation.advice.JavaInstrumentationAdviceToolbox.localize;
//</editor-fold>

/**
Expand Down Expand Up @@ -80,21 +82,13 @@ private static String generateAdviceSettingValue(@Nonnull String dataType, @Nonn
return switch (dataType) {
case "String" -> {
if (!(value instanceof String)) {
throw new SecurityException(String.format(
"Ares Security Error (Reason: Ares-Code; Stage: Creation): "
+ "Invalid value type for String advice setting: "
+ "%s but should be String.",
value.getClass()));
throw new SecurityException(localize("security.advice.settings.data.type.mismatch.string", value.getClass()));
}
yield String.format("private static String %s = \"%s\";%n", adviceSetting, value);
}
case "String[]" -> {
if (!(value instanceof List<?>)) {
throw new SecurityException(String.format(
"Ares Security Error (Reason: Ares-Code; Stage: Creation): "
+ "Invalid value type for String[] advice setting: "
+ "%s but should be List<String>.",
value.getClass()));
throw new SecurityException(localize("security.advice.settings.data.type.mismatch.string[]", value.getClass()));
}
String stringArrayValue = ((List<?>) value).stream()
.map(Object::toString)
Expand All @@ -104,11 +98,7 @@ private static String generateAdviceSettingValue(@Nonnull String dataType, @Nonn
}
case "String[][]" -> {
if (!(value instanceof List<?>)) {
throw new SecurityException(String.format(
"Ares Security Error (Reason: Ares-Code; Stage: Creation): "
+ "Invalid value type for String[][] advice setting: "
+ "%s but should be List<List<String>>.",
value.getClass()));
throw new SecurityException(localize("security.advice.settings.data.type.mismatch.string[][]", value.getClass()));
}
String stringArrayArrayValue = ((List<?>) value).stream()
.filter(e -> e instanceof List<?>)
Expand All @@ -123,38 +113,17 @@ private static String generateAdviceSettingValue(@Nonnull String dataType, @Nonn
}
case "int[]" -> {
if (!(value instanceof List<?>)) {
throw new SecurityException(String.format(
"Ares Security Error (Reason: Ares-Code; Stage: Creation): "
+ "Invalid value type for int[] advice setting: "
+ "%s but should be List<Integer>.",
value.getClass()));
throw new SecurityException(localize("security.advice.settings.data.type.mismatch.int[]", value.getClass()));
}
String intArrayValue = ((List<?>) value).stream()
.map(Object::toString)
.collect(Collectors.joining(", "));
yield String.format("private static int[] %s = new int[] {%s};%n", adviceSetting, intArrayValue);
}
default -> throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation): "
+ "Unknown data type while creating the value "
+ value
+ " for the advice settings "
+ dataType
+ " "
+ adviceSetting
);
default -> throw new SecurityException(localize("security.advice.settings.data.type.unknown", value, dataType, adviceSetting));
};
} catch (IllegalFormatException e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation): "
+ "Format error while creating the value "
+ value
+ " for the advice settings "
+ dataType
+ " "
+ adviceSetting,
e
);
throw new SecurityException(localize("security.advice.invalid.format", value, dataType, adviceSetting));
}

}
Expand All @@ -179,53 +148,31 @@ public static void setJavaAdviceSettingValue(@Nonnull String adviceSetting, @Nul
field.setAccessible(false);
} catch (LinkageError e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation):"
+ "Linkage error while accessing field '"
+ adviceSetting
+ "' in AdviceSettings",
localize("security.advice.linkage.exception", adviceSetting),
e);
} catch (ClassNotFoundException e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation):"
+ "Could not find 'JavaSecurityTestCaseSettings' class to access field '"
+ adviceSetting
+ "'",
localize("security.advice.class.not.found.exception", adviceSetting),
e);
} catch (NoSuchFieldException e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation):"
+ "Field '"
+ adviceSetting
+ "' not found in AdviceSettings",
localize("security.advice.no.such.field.exception", adviceSetting),
e);
} catch (NullPointerException e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation):"
+ "Null pointer exception while accessing field '"
+ adviceSetting
+ "' in AdviceSettings",
localize("security.advice.null.pointer.exception", adviceSetting),
e);
} catch (IllegalAccessException e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation):"
+ "Field '"
+ adviceSetting
+ "' is not accessible in AdviceSettings",
localize("security.advice.illegal.access.exception", adviceSetting),
e);
} catch (IllegalArgumentException e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation):"
+ "Illegal argument while setting field '"
+ adviceSetting
+ "' in AdviceSettings with value "
+ value,
localize("security.advice.illegal.argument.exception", adviceSetting, value),
e);
} catch (InaccessibleObjectException e) {
throw new SecurityException(
"Ares Security Error (Reason: Ares-Code; Stage: Creation):"
+ "Field '"
+ adviceSetting
+ "' is inaccessible in AdviceSettings",
localize("security.advice.inaccessible.object.exception", adviceSetting),
e);
}
}
Expand Down Expand Up @@ -265,7 +212,7 @@ private List<String> getPermittedFilePaths(@Nonnull String filePermission) {
case "execute" -> FilePermission::executeAllFiles;
case "delete" -> FilePermission::deleteAllFiles;
default ->
throw new IllegalArgumentException("Ares Security Error (Reason: Ares-Code; Stage: Creation): Invalid file permission: " + filePermission);
throw new IllegalArgumentException(localize("security.advice.settings.invalid.file.permission", filePermission));
};
return resourceAccesses.regardingFileSystemInteractions()
.stream()
Expand Down Expand Up @@ -328,7 +275,7 @@ private List<String> getPermittedNetworkHosts(@Nonnull String networkPermission)
case "send" -> NetworkPermission::sendData;
case "receive" -> NetworkPermission::receiveData;
default ->
throw new IllegalArgumentException("Ares Security Error (Reason: Ares-Code; Stage: Creation): Invalid network permission: " + networkPermission);
throw new IllegalArgumentException(localize("security.advice.settings.invalid.network.permission", networkPermission));
};
return resourceAccesses.regardingNetworkConnections()
.stream()
Expand All @@ -350,7 +297,7 @@ private List<Integer> getPermittedNetworkPorts(@Nonnull String networkPermission
case "send" -> NetworkPermission::sendData;
case "receive" -> NetworkPermission::receiveData;
default ->
throw new IllegalArgumentException("Ares Security Error (Reason: Ares-Code; Stage: Creation): Invalid network permission: " + networkPermission);
throw new IllegalArgumentException(localize("security.advice.settings.invalid.network.permission", networkPermission));
};
return resourceAccesses.regardingNetworkConnections()
.stream()
Expand Down
Loading