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" group = "org.bdware.sc"
version = "1.6.5" version = "1.6.7"
repositories { repositories {
mavenCentral() mavenCentral()
mavenLocal() mavenLocal()

View File

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

View File

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

View File

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