|
17 | 17 | import apijson.fastjson2.APIJSONController; |
18 | 18 | import apijson.fastjson2.APIJSONParser; |
19 | 19 | import apijson.fastjson2.JSONRequest; |
20 | | -import apijson.framework.APIJSONApplication; |
21 | | -import apijson.framework.APIJSONConstant; |
22 | | -import apijson.framework.APIJSONCreator; |
| 20 | +import apijson.framework.*; |
23 | 21 | import apijson.orm.exception.*; |
24 | 22 | import com.alibaba.fastjson2.JSONArray; |
25 | 23 | import com.alibaba.fastjson2.JSONObject; |
|
68 | 66 | import apijson.demo.model.Privacy; |
69 | 67 | import apijson.demo.model.User; |
70 | 68 | import apijson.demo.model.Verify; |
71 | | -import apijson.framework.BaseModel; |
72 | 69 | import unitauto.MethodUtil; |
73 | 70 |
|
74 | 71 | import static apijson.JSON.getString; |
@@ -3320,10 +3317,16 @@ public String au() { |
3320 | 3317 | //} |
3321 | 3318 |
|
3322 | 3319 | @PostMapping("method/list") |
3323 | | - public Map<String, Object> listMethod(@RequestBody String request) { |
| 3320 | + public Map<String, Object> listMethod(@RequestBody String request, HttpSession session) { |
3324 | 3321 | if (Log.DEBUG == false) { |
3325 | 3322 | return MethodUtil.JSON_CALLBACK.newErrorResult(new IllegalAccessException("非 DEBUG 模式下不允许使用 UnitAuto 单元测试!")); |
3326 | 3323 | } |
| 3324 | + try { |
| 3325 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3326 | + } catch (Exception e) { |
| 3327 | + return MethodUtil.JSON_CALLBACK.newErrorResult(e); |
| 3328 | + } |
| 3329 | + |
3327 | 3330 | return MethodUtil.listMethod(request); |
3328 | 3331 | } |
3329 | 3332 |
|
@@ -3351,9 +3354,19 @@ public void complete(com.alibaba.fastjson.JSONObject data, Method method, Method |
3351 | 3354 | } |
3352 | 3355 | }; |
3353 | 3356 |
|
3354 | | - if (Log.DEBUG == false) { |
| 3357 | + Exception err = Log.DEBUG ? null : new IllegalAccessException("非 DEBUG 模式下不允许使用 UnitAuto 单元测试!"); |
| 3358 | + if (err == null) { |
3355 | 3359 | try { |
3356 | | - listener.complete(MethodUtil.JSON_CALLBACK.newErrorResult(new IllegalAccessException("非 DEBUG 模式下不允许使用 UnitAuto 单元测试!"))); |
| 3360 | + HttpSession session = servletRequest.getSession(); |
| 3361 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3362 | + } catch (Exception e) { |
| 3363 | + err = e; |
| 3364 | + } |
| 3365 | + } |
| 3366 | + |
| 3367 | + if (err != null) { |
| 3368 | + try { |
| 3369 | + listener.complete(MethodUtil.JSON_CALLBACK.newErrorResult(err)); |
3357 | 3370 | } |
3358 | 3371 | catch (Exception e1) { |
3359 | 3372 | e1.printStackTrace(); |
@@ -3384,51 +3397,99 @@ public void complete(com.alibaba.fastjson.JSONObject data, Method method, Method |
3384 | 3397 |
|
3385 | 3398 | @GetMapping("api/test/start") |
3386 | 3399 | public String startApiTest(HttpSession session) { |
| 3400 | + try { |
| 3401 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3402 | + } catch (Exception e) { |
| 3403 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3404 | + } |
| 3405 | + |
3387 | 3406 | //response.sendRedirect("http://localhost:3000/test/start"); |
3388 | 3407 | long id = 100000 + Math.round(899999*Math.random()); |
3389 | 3408 | DemoParser.KEY_MAP.put(String.valueOf(id), session); // 调这个接口一般是前端/CI/CD,调查询接口的是 Node,Session 不同 session.setAttribute("key", id); |
3390 | 3409 | return delegate("http://localhost:3000/test/start?key=" + id, session); |
3391 | 3410 | } |
3392 | 3411 | @GetMapping("api/test/status") |
3393 | 3412 | public String getApiTestStatus(@RequestParam(value = "key", required = false) String key, HttpSession session) { |
| 3413 | + try { |
| 3414 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3415 | + } catch (Exception e) { |
| 3416 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3417 | + } |
| 3418 | + |
3394 | 3419 | //response.sendRedirect("http://localhost:3000/test/status"); |
3395 | 3420 | DemoParser.KEY_MAP.remove(key); |
3396 | 3421 | return delegate("http://localhost:3000/test/status", session); |
3397 | 3422 | } |
3398 | 3423 |
|
3399 | 3424 | @GetMapping("unit/test/start") |
3400 | 3425 | public String startUnitTest(HttpSession session) { |
| 3426 | + try { |
| 3427 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3428 | + } catch (Exception e) { |
| 3429 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3430 | + } |
| 3431 | + |
3401 | 3432 | long id = 100000 + Math.round(899999*Math.random()); |
3402 | 3433 | DemoParser.KEY_MAP.put(String.valueOf(id), session); // 调这个接口一般是前端/CI/CD,调查询接口的是 Node,Session 不同 session.setAttribute("key", id); |
3403 | 3434 | return delegate("http://localhost:3001/test/start?key=" + id, session); |
3404 | 3435 | } |
3405 | 3436 | @GetMapping("unit/test/status") |
3406 | 3437 | public String getUnitTestStatus(@RequestParam(value = "key", required = false) String key, HttpSession session) { |
| 3438 | + try { |
| 3439 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3440 | + } catch (Exception e) { |
| 3441 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3442 | + } |
| 3443 | + |
3407 | 3444 | DemoParser.KEY_MAP.remove(key); |
3408 | 3445 | return delegate("http://localhost:3001/test/status", session); |
3409 | 3446 | } |
3410 | 3447 |
|
3411 | 3448 | @GetMapping("sql/test/start") |
3412 | 3449 | public String startSQLTest(HttpSession session) { |
| 3450 | + try { |
| 3451 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3452 | + } catch (Exception e) { |
| 3453 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3454 | + } |
| 3455 | + |
3413 | 3456 | long id = 100000 + Math.round(899999*Math.random()); |
3414 | 3457 | DemoParser.KEY_MAP.put(String.valueOf(id), session); // 调这个接口一般是前端/CI/CD,调查询接口的是 Node,Session 不同 session.setAttribute("key", id); |
3415 | 3458 | return delegate("http://localhost:3002/test/start?key=" + id, session); |
3416 | 3459 | } |
3417 | 3460 | @GetMapping("sql/test/status") |
3418 | 3461 | public String getSQLTestStatus(@RequestParam("key") String key, HttpSession session) { |
| 3462 | + try { |
| 3463 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3464 | + } catch (Exception e) { |
| 3465 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3466 | + } |
| 3467 | + |
3419 | 3468 | DemoParser.KEY_MAP.remove(key); |
3420 | 3469 | return delegate("http://localhost:3002/test/status", session); |
3421 | 3470 | } |
3422 | 3471 |
|
3423 | 3472 | @GetMapping("cv/test/start") |
3424 | 3473 | public String startCvTest(HttpSession session) { |
| 3474 | + try { |
| 3475 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3476 | + } catch (Exception e) { |
| 3477 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3478 | + } |
| 3479 | + |
3425 | 3480 | //response.sendRedirect("http://localhost:3003/test/start"); |
3426 | 3481 | long id = 100000 + Math.round(899999*Math.random()); |
3427 | 3482 | DemoParser.KEY_MAP.put(String.valueOf(id), session); // 调这个接口一般是前端/CI/CD,调查询接口的是 Node,Session 不同 session.setAttribute("key", id); |
3428 | 3483 | return delegate("http://localhost:3003/test/start?key=" + id, session); |
3429 | 3484 | } |
3430 | 3485 | @GetMapping("cv/test/status") |
3431 | 3486 | public String getCvTestStatus(@RequestParam(value = "key", required = false) String key, HttpSession session) { |
| 3487 | + try { |
| 3488 | + COMMON_PARSER.getVerifier().setVisitor(APIJSONVerifier.getVisitor(session)).verifyLogin(); |
| 3489 | + } catch (Exception e) { |
| 3490 | + return JSON.toJSONString(COMMON_PARSER.newErrorResult(e)); |
| 3491 | + } |
| 3492 | + |
3432 | 3493 | //response.sendRedirect("http://localhost:3003/test/status"); |
3433 | 3494 | DemoParser.KEY_MAP.remove(key); |
3434 | 3495 | return delegate("http://localhost:3003/test/status", session); |
|
0 commit comments