commit 51f58d19bc1b6617f51bfda3c6ebf86cc59c19ef Author: Loosen-IT Date: Wed Oct 30 19:29:50 2024 +0100 testing with JAZZER diff --git a/testing/.idea/libraries/JAZZER.xml b/testing/.idea/libraries/JAZZER.xml new file mode 100644 index 0000000..579cdf8 --- /dev/null +++ b/testing/.idea/libraries/JAZZER.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/libraries/example_junit.xml b/testing/.idea/libraries/example_junit.xml new file mode 100644 index 0000000..1ce2b70 --- /dev/null +++ b/testing/.idea/libraries/example_junit.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/libraries/example_junit2.xml b/testing/.idea/libraries/example_junit2.xml new file mode 100644 index 0000000..89390a6 --- /dev/null +++ b/testing/.idea/libraries/example_junit2.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/libraries/example_unit_jazzer.xml b/testing/.idea/libraries/example_unit_jazzer.xml new file mode 100644 index 0000000..07506cb --- /dev/null +++ b/testing/.idea/libraries/example_unit_jazzer.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/libraries/example_unit_jazzer2.xml b/testing/.idea/libraries/example_unit_jazzer2.xml new file mode 100644 index 0000000..885c3c6 --- /dev/null +++ b/testing/.idea/libraries/example_unit_jazzer2.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/libraries/jars.xml b/testing/.idea/libraries/jars.xml new file mode 100644 index 0000000..a177615 --- /dev/null +++ b/testing/.idea/libraries/jars.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/libraries/jazzer_standalone.xml b/testing/.idea/libraries/jazzer_standalone.xml new file mode 100644 index 0000000..c0df1c9 --- /dev/null +++ b/testing/.idea/libraries/jazzer_standalone.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/misc.xml b/testing/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/testing/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/testing/.idea/modules.xml b/testing/.idea/modules.xml new file mode 100644 index 0000000..a01fb27 --- /dev/null +++ b/testing/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/testing/.idea/vcs.xml b/testing/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/testing/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/testing/.idea/workspace.xml b/testing/.idea/workspace.xml new file mode 100644 index 0000000..d53d6a6 --- /dev/null +++ b/testing/.idea/workspace.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1730213753923 + + + + + + \ No newline at end of file diff --git a/testing/AufgabeEmailMatcher/EmailMatcher.class b/testing/AufgabeEmailMatcher/EmailMatcher.class new file mode 100644 index 0000000..f5bd699 Binary files /dev/null and b/testing/AufgabeEmailMatcher/EmailMatcher.class differ diff --git a/testing/AufgabeEmailMatcher/EmailMatcher.java b/testing/AufgabeEmailMatcher/EmailMatcher.java new file mode 100644 index 0000000..e16bbfd --- /dev/null +++ b/testing/AufgabeEmailMatcher/EmailMatcher.java @@ -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(); + } + +} \ No newline at end of file diff --git a/testing/AufgabeEmailMatcher/EmailMatcherFuzzTest.class b/testing/AufgabeEmailMatcher/EmailMatcherFuzzTest.class new file mode 100644 index 0000000..c63ddd1 Binary files /dev/null and b/testing/AufgabeEmailMatcher/EmailMatcherFuzzTest.class differ diff --git a/testing/AufgabeEmailMatcher/EmailMatcherFuzzTest.java b/testing/AufgabeEmailMatcher/EmailMatcherFuzzTest.java new file mode 100644 index 0000000..184eba9 --- /dev/null +++ b/testing/AufgabeEmailMatcher/EmailMatcherFuzzTest.java @@ -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!"); + } + } +} diff --git a/testing/AufgabeEmailMatcher/ExampleMatcher.class b/testing/AufgabeEmailMatcher/ExampleMatcher.class new file mode 100644 index 0000000..4272f23 Binary files /dev/null and b/testing/AufgabeEmailMatcher/ExampleMatcher.class differ diff --git a/testing/AufgabeEmailMatcher/ExampleMatcher.java b/testing/AufgabeEmailMatcher/ExampleMatcher.java new file mode 100644 index 0000000..85d361c --- /dev/null +++ b/testing/AufgabeEmailMatcher/ExampleMatcher.java @@ -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"); + } + } + } + +} \ No newline at end of file diff --git a/testing/AufgabeEmailMatcher/fuzz.bat b/testing/AufgabeEmailMatcher/fuzz.bat new file mode 100644 index 0000000..2df5221 --- /dev/null +++ b/testing/AufgabeEmailMatcher/fuzz.bat @@ -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 \ No newline at end of file diff --git a/testing/AufgabeUserRegistration/EmailMatcher.java b/testing/AufgabeUserRegistration/EmailMatcher.java new file mode 100644 index 0000000..e0a3809 --- /dev/null +++ b/testing/AufgabeUserRegistration/EmailMatcher.java @@ -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(); + } + +} \ No newline at end of file diff --git a/testing/AufgabeUserRegistration/ExampleUserRegistration.java b/testing/AufgabeUserRegistration/ExampleUserRegistration.java new file mode 100644 index 0000000..f64fe28 --- /dev/null +++ b/testing/AufgabeUserRegistration/ExampleUserRegistration.java @@ -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()); + } + } + + } + +} \ No newline at end of file diff --git a/testing/AufgabeUserRegistration/UserRegistration.java b/testing/AufgabeUserRegistration/UserRegistration.java new file mode 100644 index 0000000..1468754 --- /dev/null +++ b/testing/AufgabeUserRegistration/UserRegistration.java @@ -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); } +} \ No newline at end of file diff --git a/testing/AufgabeUserRegistration/UserRegistrationFuzzTest.java b/testing/AufgabeUserRegistration/UserRegistrationFuzzTest.java new file mode 100644 index 0000000..761ca26 --- /dev/null +++ b/testing/AufgabeUserRegistration/UserRegistrationFuzzTest.java @@ -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) { } + } + } +} diff --git a/testing/AufgabeUserRegistration/fuzz.bat b/testing/AufgabeUserRegistration/fuzz.bat new file mode 100644 index 0000000..a5a4e0e --- /dev/null +++ b/testing/AufgabeUserRegistration/fuzz.bat @@ -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 \ No newline at end of file diff --git a/testing/jars/jazzer-junit-0.22.1.jar b/testing/jars/jazzer-junit-0.22.1.jar new file mode 100644 index 0000000..11e83fe Binary files /dev/null and b/testing/jars/jazzer-junit-0.22.1.jar differ diff --git a/testing/jars/jazzer_standalone.jar b/testing/jars/jazzer_standalone.jar new file mode 100644 index 0000000..eac29c1 Binary files /dev/null and b/testing/jars/jazzer_standalone.jar differ diff --git a/testing/jars/junit5-4.6.14.jar b/testing/jars/junit5-4.6.14.jar new file mode 100644 index 0000000..c20d1e1 Binary files /dev/null and b/testing/jars/junit5-4.6.14.jar differ diff --git a/testing/testing.iml b/testing/testing.iml new file mode 100644 index 0000000..e8af208 --- /dev/null +++ b/testing/testing.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file