Skip to content

Commit

Permalink
feat: Add mutators for lowercase/uppercase expanding strings
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed Jan 24, 2025
1 parent 8ab2dab commit 392e192
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.endava.cats.fuzzer.special.mutators.impl;

import com.endava.cats.fuzzer.special.mutators.api.BodyMutator;
import com.endava.cats.generator.simple.UnicodeGenerator;
import com.endava.cats.util.CatsUtil;
import com.endava.cats.util.JsonUtils;
import jakarta.inject.Singleton;

@Singleton
public class LowercaseExpandingBytesMutator implements BodyMutator {
@Override
public String mutate(String inputJson, String selectedField) {
int length = String.valueOf(JsonUtils.getVariableFromJson(inputJson, selectedField)).length();
String generated = CatsUtil.selectRandom(UnicodeGenerator.getLowercaseExpandingBytes(), length);
return CatsUtil.justReplaceField(inputJson, selectedField, generated).json();
}

@Override
public String description() {
return "replace field with strings that expand bytes when lowercased";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.endava.cats.fuzzer.special.mutators.impl;

import com.endava.cats.fuzzer.special.mutators.api.BodyMutator;
import com.endava.cats.generator.simple.UnicodeGenerator;
import com.endava.cats.util.CatsUtil;
import com.endava.cats.util.JsonUtils;
import jakarta.inject.Singleton;

@Singleton
public class LowercaseExpandingLengthMutator implements BodyMutator {
@Override
public String mutate(String inputJson, String selectedField) {
int length = String.valueOf(JsonUtils.getVariableFromJson(inputJson, selectedField)).length();
String generated = CatsUtil.selectRandom(UnicodeGenerator.getLowercaseExpandingLength(), length);
return CatsUtil.justReplaceField(inputJson, selectedField, generated).json();
}

@Override
public String description() {
return "replace field with strings that expand length when lowercased";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.endava.cats.fuzzer.special.mutators.impl;

import com.endava.cats.fuzzer.special.mutators.api.BodyMutator;
import com.endava.cats.generator.simple.UnicodeGenerator;
import com.endava.cats.util.CatsUtil;
import com.endava.cats.util.JsonUtils;
import jakarta.inject.Singleton;

@Singleton
public class UppercaseExpandingBytesMutator implements BodyMutator {
@Override
public String mutate(String inputJson, String selectedField) {
int length = String.valueOf(JsonUtils.getVariableFromJson(inputJson, selectedField)).length();
String generated = CatsUtil.selectRandom(UnicodeGenerator.getUppercaseExpandingBytes(), length);
return CatsUtil.justReplaceField(inputJson, selectedField, generated).json();
}

@Override
public String description() {
return "replace field with strings that expand bytes when uppercased";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.endava.cats.fuzzer.special.mutators.impl;

import com.endava.cats.fuzzer.special.mutators.api.BodyMutator;
import com.endava.cats.generator.simple.UnicodeGenerator;
import com.endava.cats.util.CatsUtil;
import com.endava.cats.util.JsonUtils;
import jakarta.inject.Singleton;

@Singleton
public class UppercaseExpandingLengthMutator implements BodyMutator {
@Override
public String mutate(String inputJson, String selectedField) {
int length = String.valueOf(JsonUtils.getVariableFromJson(inputJson, selectedField)).length();
String generated = CatsUtil.selectRandom(UnicodeGenerator.getUppercaseExpandingLength(), length);
return CatsUtil.justReplaceField(inputJson, selectedField, generated).json();
}

@Override
public String description() {
return "replace field with strings that expand length when uppercased";
}
}

0 comments on commit 392e192

Please sign in to comment.