testing with JAZZER

This commit is contained in:
Jan-Niclas Loosen 2024-10-30 19:29:50 +01:00
commit 51f58d19bc
27 changed files with 401 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="JAZZER">
<CLASSES>
<root url="jar://$PROJECT_DIR$/out/production/JAZZER/jazzer-junit-0.22.1.jar!/" />
<root url="jar://$PROJECT_DIR$/out/production/JAZZER/junit-4.13.2.jar!/" />
<root url="jar://$PROJECT_DIR$/out/production/JAZZER/junit5-4.6.14.jar!/" />
<root url="jar://$PROJECT_DIR$/out/production/JAZZER/jazzer_standalone.jar!/" />
<root url="jar://$PROJECT_DIR$/out/production/JAZZER/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="example_junit">
<CLASSES>
<root url="jar://$PROJECT_DIR$/JAZZER/example_junit/out/production/example_junit/hamcrest-core-1.3.jar!/" />
<root url="jar://$PROJECT_DIR$/JAZZER/example_junit/out/production/example_junit/junit-4.13.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="example_junit2">
<CLASSES>
<root url="jar://$PROJECT_DIR$/JAZZER/example_junit/hamcrest-core-1.3.jar!/" />
<root url="jar://$PROJECT_DIR$/JAZZER/example_junit/junit-4.13.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="example_unit_jazzer">
<CLASSES>
<root url="jar://$PROJECT_DIR$/JAZZER/example_unit_jazzer/jazzer_standalone.jar!/" />
<root url="jar://$PROJECT_DIR$/JAZZER/example_unit_jazzer/junit5-4.6.14.jar!/" />
<root url="jar://$PROJECT_DIR$/JAZZER/example_unit_jazzer/jazzer-junit-0.22.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="example_unit_jazzer2">
<CLASSES>
<root url="jar://$PROJECT_DIR$/JAZZER/example_unit_jazzer/out/production/example_unit_jazzer/junit5-4.6.14.jar!/" />
<root url="jar://$PROJECT_DIR$/JAZZER/example_unit_jazzer/out/production/example_unit_jazzer/jazzer-junit-0.22.1.jar!/" />
<root url="jar://$PROJECT_DIR$/JAZZER/example_unit_jazzer/out/production/example_unit_jazzer/jazzer_standalone.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="jars">
<CLASSES>
<root url="file://$PROJECT_DIR$/jars" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$PROJECT_DIR$/jars" recursive="false" />
</library>
</component>

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="jazzer_standalone">
<CLASSES>
<root url="jar://$PROJECT_DIR$/JAZZER/example_jazzer/jazzer_standalone.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

6
testing/.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/testing.iml" filepath="$PROJECT_DIR$/testing.iml" />
</modules>
</component>
</project>

6
testing/.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

129
testing/.idea/workspace.xml Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="8b58daba-b979-4e25-9211-ae1b5daed24c" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/libraries/JAZZER.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/example_junit.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/example_junit2.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/example_unit_jazzer.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/example_unit_jazzer2.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/jars.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/jazzer_standalone.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeEmailMatcher/EmailMatcher.class" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeEmailMatcher/EmailMatcher.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeEmailMatcher/EmailMatcherFuzzTest.class" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeEmailMatcher/EmailMatcherFuzzTest.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeEmailMatcher/ExampleMatcher.class" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeEmailMatcher/ExampleMatcher.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeEmailMatcher/fuzz.bat" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeUserRegistration/EmailMatcher.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeUserRegistration/ExampleUserRegistration.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeUserRegistration/UserRegistration.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeUserRegistration/UserRegistrationFuzzTest.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AufgabeUserRegistration/fuzz.bat" afterDir="false" />
<change afterPath="$PROJECT_DIR$/jars/jazzer-junit-0.22.1.jar" afterDir="false" />
<change afterPath="$PROJECT_DIR$/jars/jazzer_standalone.jar" afterDir="false" />
<change afterPath="$PROJECT_DIR$/jars/junit5-4.6.14.jar" afterDir="false" />
<change afterPath="$PROJECT_DIR$/testing.iml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 1
}]]></component>
<component name="ProjectId" id="2o7Ha53qsIzLXvN7m9IjC7BvDQt" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Batch.fuzz.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/Jan-Niclas Loosen/Documents/Projekte/softwaretechnik_II/testing/jars",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"project.structure.last.edited": "Project",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Jan-Niclas Loosen\Documents\Projekte\softwaretechnik_II\testing\jars" />
<recent name="C:\Users\Jan-Niclas Loosen\Documents\Projekte\softwaretechnik_II\testing\AufgabeEmailMatcher" />
<recent name="C:\Users\Jan-Niclas Loosen\Documents\Projekte\softwaretechnik_II\testing\AufgabeUserRegistration" />
</key>
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="" />
</key>
</component>
<component name="RunManager">
<configuration name="fuzz" type="BatchConfigurationType" factoryName="Batch" temporary="true">
<module name="testing" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="WORKING_DIRECTORY" value="C:\Users\Jan-Niclas Loosen\Documents\Projekte\softwaretechnik_II\testing\AufgabeEmailMatcher" />
<option name="PARENT_ENVS" value="true" />
<option name="SCRIPT_NAME" value="fuzz.bat" />
<option name="PARAMETERS" value="" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Batch.fuzz" />
</list>
</recent_temporary>
</component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-jdk-9823dce3aa75-28b599e66164-intellij.indexing.shared.core-IU-242.23339.11" />
<option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-IU-242.23339.11" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="8b58daba-b979-4e25-9211-ae1b5daed24c" name="Changes" comment="" />
<created>1730213753923</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1730213753923</updated>
<workItem from="1730213754948" duration="5609000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

Binary file not shown.

View File

@ -0,0 +1,17 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class EmailMatcher {
// Regex für Emailadressen
static String emailRegex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
static Pattern pattern = Pattern.compile(emailRegex);
static boolean isValidEmail(String email) {
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
}

Binary file not shown.

View File

@ -0,0 +1,14 @@
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.junit.FuzzTest;
import java.security.InvalidParameterException;
public class EmailMatcherFuzzTest {
@FuzzTest
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
String email = data.consumeString(100);
if(EmailMatcher.isValidEmail(email)) {
throw new InvalidParameterException("Valid email found!");
}
}
}

Binary file not shown.

View File

@ -0,0 +1,18 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class ExampleMatcher {
public static void main(String[] args) {
if (args.length<1) {
System.out.println("No data provided as command line argument!");
} else {
if (EmailMatcher.isValidEmail(args[0])) {
System.out.println("Valid email address");
}
}
}
}

View File

@ -0,0 +1,12 @@
set CLASSPATH=.\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar;..\jars\jazzer-junit-0.22.1.jar;..\jars\junit5-4.6.14.jar
javac EmailMatcher.java
javac EmailMatcherFuzzTest.java
java com.code_intelligence.jazzer.Jazzer --target_class=EmailMatcherFuzzTest
@rem ALTERNATIV Klassenpfad im Befehl angeben:
@rem javac -cp .\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar EmailMatcher.java
@rem javac -cp .\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar;..\jars\jazzer-junit-0.22.1.jar;..\jars\junit5-4.6.14.jar EmailMatcherFuzzTest.java
@rem java -cp .\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar;..\jars\jazzer-junit-0.22.1.jar;..\jars\junit5-4.6.14.jar com.code_intelligence.jazzer.Jazzer --target_class=EmailMatcherFuzzTest

View File

@ -0,0 +1,16 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailMatcher {
// Regex für Emailadressen
static String emailRegex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,63}$";
static Pattern pattern = Pattern.compile(emailRegex);
static boolean isValidEmail(String email) {
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
}

View File

@ -0,0 +1,26 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class ExampleUserRegistration {
public static void main(String[] args) {
if (args.length<3) {
System.out.println("Please provide username, password and email as command line arguments");
} else {
String user = args[0];
String password = args[1];
String email = args[2];
try {
if (UserRegistration.registerUser(user, password, email))
System.out.println("User successfully registered!");
} catch (RegistrationException e) {
System.out.println(e.getMessage());
}
}
}
}

View File

@ -0,0 +1,28 @@
import java.util.regex.Pattern;
public class UserRegistration {
// Regex für Benutzernamen, nur Buchstaben und Zahlen
private static final Pattern USERNAME_PATTERN = Pattern.compile("^[A-Za-z0-9]{3,15}$");
public static boolean registerUser(String username, String password, String email) throws RegistrationException {
if (!USERNAME_PATTERN.matcher(username).matches()) {
throw new RegistrationException("Invalid username. Only letters and numbers allowed, 3-15 characters.");
}
if (password.length() < 8 || password.length() > 20) {
throw new RegistrationException("Invalid password length. Password must be 8-20 characters.");
}
if (!EmailMatcher.isValidEmail(email)) {
throw new RegistrationException("Invalid email format.");
}
return true;
}
}
class RegistrationException extends Exception {
RegistrationException(String msg) { super(msg); }
}

View File

@ -0,0 +1,20 @@
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
import com.code_intelligence.jazzer.junit.FuzzTest;
import java.security.InvalidParameterException;
public class UserRegistrationFuzzTest {
@FuzzTest
public static void fuzzerTestOneInput(FuzzedDataProvider data) {
String email = data.consumeString(100);
if(EmailMatcher.isValidEmail(email)) {
String user = data.consumeString(100);
String password = data.consumeString(100);
try {
UserRegistration.registerUser(user, password, email);
System.out.println("User: " + user + ", Password: " + password + ", Email: " + email);
throw new InvalidParameterException("This registration is valid!");
} catch (RegistrationException e) { }
}
}
}

View File

@ -0,0 +1,13 @@
set CLASSPATH=.\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar;..\jars\jazzer-junit-0.22.1.jar;..\jars\junit5-4.6.14.jar
javac UserRegistration.java
javac EmailMatcher.java
javac UserRegistrationFuzzTest.java
java com.code_intelligence.jazzer.Jazzer --target_class=UserRegistrationFuzzTest
@rem ALTERNATIV Klassenpfad im Befehl angeben:
@rem javac -cp .\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar UserRegistration.java
@rem javac -cp .\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar;..\jars\jazzer-junit-0.22.1.jar;..\jars\junit5-4.6.14.jar UserRegistrationFuzzTest.java
@rem java -cp .\;%JAVA_HOME%\lib;..\jars\jazzer_standalone.jar;..\jars\jazzer-junit-0.22.1.jar;..\jars\junit5-4.6.14.jar com.code_intelligence.jazzer.Jazzer --target_class=UserRegistrationFuzzTest

Binary file not shown.

Binary file not shown.

Binary file not shown.

14
testing/testing.iml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/AufgabeEmailMatcher" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/AufgabeUserRegistration" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="JAZZER" level="project" />
<orderEntry type="library" name="jars" level="project" />
</component>
</module>