fix arg schema bugs

This commit is contained in:
CaiHQ 2022-09-28 18:15:52 +08:00
parent 56d140a2c7
commit 64cdfecd67
4 changed files with 48 additions and 54 deletions

View File

@ -6,7 +6,7 @@ plugins {
}
group = "org.bdware.sc"
version = "1.6.5"
version = "1.6.7"
repositories {
mavenCentral()
mavenLocal()

View File

@ -92,8 +92,8 @@ public class DebugMain {
String urlFormat = ("http://%s/SCIDE/SCManager?action=%s&arg=%s");
String url = String.format(urlFormat, config.agentAddress, "getAgentConfig", "");
Map<String, Object> resp = HttpUtil.httpGet(url);
String data = (String
) resp.get("response");
String data = (String) resp.get("response");
assert (int) resp.get("responseCode") == 200;
JsonObject jsonObject = JsonUtil.parseStringAsJsonObject(data);
config.cmi = jsonObject.get("cmi").getAsString();
config.dbPath = jsonObject.get("dbPath").getAsString();

View File

@ -5,12 +5,9 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.sc.ContractProcess;
import org.bdware.sc.JSEngine;
import org.bdware.sc.bean.ContractRequest;
import org.bdware.sc.bean.ProjectConfig;
import org.bdware.sc.boundry.ScriptReturnException;
import org.bdware.sc.engine.DesktopEngine;
import org.bdware.sc.node.AnnotationHook;
import org.bdware.sc.node.AnnotationNode;
import org.bdware.sc.node.FunctionNode;
@ -38,13 +35,12 @@ public class ArgSchemaHandler implements AnnotationHook {
@Override
public Object handle(ContractRequest input, JSEngine Engine, Object ret) throws ScriptReturnException {
//input.getArg();
JsonElement je = input.getArg();
ArgSchemaVisitor visitor;
if (je.isJsonObject())
visitor = new ArgSchemaVisitor(input.getArg().getAsJsonObject());
else
visitor = new ArgSchemaVisitor(JsonParser.parseString(input.getArg().toString()));
visitor = new ArgSchemaVisitor(JsonParser.parseString(input.getArg().getAsString()));
if (je.toString().isEmpty() && !a.getArgs().get(0).equals("")) {
JsonObject jo = new JsonObject();
jo.addProperty("msg", "[Empty argument] argument should not be empty");

View File

@ -1,9 +1,5 @@
package org.bdware.sc.engine.hook;
import com.alibaba.datax.transport.transformer.maskingMethods.cryptology.AESEncryptionImpl;
import com.alibaba.datax.transport.transformer.maskingMethods.cryptology.FormatPreservingEncryptionImpl;
import com.alibaba.datax.transport.transformer.maskingMethods.differentialPrivacy.EpsilonDifferentialPrivacyImpl;
import com.alibaba.datax.transport.transformer.maskingMethods.irreversibleInterference.MD5EncryptionImpl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -12,12 +8,12 @@ import org.bdware.mockjava.JsonVisitor;
public class ArgSchemaVisitor extends JsonVisitor {
JsonElement root;
public boolean status=true;
public int errorCode=0;
public boolean status = true;
public int errorCode = 0;
//{"msg":"xxx","code":1000}
//
// JsonElement message = new JsonPrimitive("");
public String message="";
public String message = "";
public ArgSchemaVisitor(JsonElement ret) {
root = ret;
@ -32,37 +28,38 @@ public class ArgSchemaVisitor extends JsonVisitor {
if (key.startsWith("!")) {
//TODO
//if(必選
if(jo.has(key.substring(1))){
if (jo.has(key.substring(1))) {
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key.substring(1)));
visitor.visit(schema.get(key));
jo.add(key, visitor.get());
if (!visitor.status){
errorCode+=visitor.errorCode;
message+=visitor.message;
if (!visitor.status) {
errorCode += visitor.errorCode;
message += visitor.message;
}
status&=visitor.status;
}
else{
message+="[Missing argument] "+key.substring(1)+" should be supplied ";
status &= visitor.status;
} else {
message += "[Missing argument] " + key.substring(1) + " should be supplied ";
status = false;
errorCode=1002;
errorCode = 1002;
}
}
else{
if(jo.has(key)){
} else {
if (jo.has(key)) {
ArgSchemaVisitor visitor = new ArgSchemaVisitor(jo.get(key));
visitor.visit(schema.get(key));
jo.add(key, visitor.get());
if (!visitor.status){
message+=visitor.message;
errorCode+=visitor.errorCode;
if (!visitor.status) {
message += visitor.message;
errorCode += visitor.errorCode;
}
status&=visitor.status;
status &= visitor.status;
}
}
}
} else {
message += "[Incorrect type] should be object";
status = false;
errorCode = 1003;
}
return this;
}
@ -72,11 +69,10 @@ public class ArgSchemaVisitor extends JsonVisitor {
if (root.isJsonArray()) {
JsonArray array = root.getAsJsonArray();
//message = new JsonArray();
for (int i = 0; i < array.size(); i++) {
ArgSchemaVisitor visitor = new ArgSchemaVisitor(array.get(i));
visitor.visit(ele.get(0));
message+=visitor.message;
message += visitor.message;
}
}
return this;
@ -96,54 +92,51 @@ public class ArgSchemaVisitor extends JsonVisitor {
String result = "";
//md5不需要参数
if (type.equals("string")) {
if (root.isJsonPrimitive()&& root.getAsJsonPrimitive().isString()){
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isString()) {
return this;
}else{
} else {
// message=new JsonObject();
// message.getAsJsonObject().addProperty("msg","xxx");
// message.getAsJsonObject().addProperty("code","1000");
message="[Type error] The value ("+root.getAsJsonPrimitive().getAsString() +") should be string";
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be string";
status = false;
errorCode=1001;
errorCode = 1001;
return this;
}
} else if (type.equals("number")) {
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isNumber()) {
return this;
} else {
message="[Type error] The value ("+root.getAsJsonPrimitive().getAsString() +") should be number";
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be number";
status = false;
errorCode=1001;
errorCode = 1001;
return this;
}
}
else if (type.equals("boolean")) {
} else if (type.equals("boolean")) {
if (root.isJsonPrimitive() && root.getAsJsonPrimitive().isBoolean()) {
return this;
} else {
message="[Type error] The value ("+root.getAsJsonPrimitive().getAsString() +") should be boolean";
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be boolean";
status = false;
errorCode=1001;
errorCode = 1001;
return this;
}
}
else if (type.equals("[]")) {
} else if (type.equals("[]")) {
if (root.isJsonArray()) {
return this;
} else {
message="[Type error] The value ("+root.getAsJsonPrimitive().getAsString() +") should be array";
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be array";
status = false;
errorCode=1001;
errorCode = 1001;
return this;
}
}
else if (type.equals("{}")) {
} else if (type.equals("{}")) {
if (root.isJsonObject()) {
return this;
} else {
message="[Type error] The value ("+root.getAsJsonPrimitive().getAsString() +") should be object";
message = "[Type error] The value (" + root.getAsJsonPrimitive().getAsString() + ") should be object";
status = false;
errorCode=1001;
errorCode = 1001;
return this;
}
}
@ -160,7 +153,12 @@ public class ArgSchemaVisitor extends JsonVisitor {
//https://github.com/guohf/DataX-Masking
return this;
}
public boolean getStatus(){return status;}
public String getException() {return message;}
public boolean getStatus() {
return status;
}
public String getException() {
return message;
}
}