Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8b8c589

Browse files
【安全】新增使用 UnitAuto 做单元测试时不返回敏感信息的代码示例及相关注释
1 parent a6da9b8 commit 8b8c589

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

‎APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/boot/DemoApplication.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public SQLExecutor createSQLExecutor() {
110110

111111

112112
// UnitAuto 单元测试配置 https://github.com/TommyLemon/UnitAuto <<<<<<<<<<<<<<<<<<<<<<<<<<<
113-
113+
// FIXME 不要开放给项目组后端之外的任何人使用 UnitAuto(强制登录鉴权)!!!如果不需要单元测试则移除相关代码或 unitauto.Log.DEBUG = false;
114114
UnitAutoApp.init();
115115

116116
// 适配 Spring 注入的类及 Context 等环境相关的类
@@ -177,6 +177,21 @@ public boolean apply(Object object, String name, Object value) {
177177
return false;
178178
}
179179

180+
// 防止通过 UnitAuto 远程执行 getDBPassword 等方法来查到敏感信息,但如果直接调用 public String getDBUri 这里没法拦截,仍然会返回敏感信息
181+
// if (object instanceof SQLConfig) {
182+
// // 这个类部分方法不序列化返回
183+
// if ("dBUri".equalsIgnoreCase(name) || "dBPassword".equalsIgnoreCase(name) || "dBAccount".equalsIgnoreCase(name)) {
184+
// return false;
185+
// }
186+
// return false; // 这个类所有方法都不序列化返回
187+
// }
188+
189+
// 所有类中的方法只要包含关键词就不序列化返回
190+
String n = StringUtil.toLowerCase(name);
191+
if (n.contains("database") || n.contains("schema") || n.contains("dburi") || n.contains("password") || n.contains("account")) {
192+
return false;
193+
}
194+
180195
return Modifier.isPublic(value.getClass().getModifiers());
181196
}
182197
}));
@@ -229,7 +244,8 @@ public boolean apply(Object object, String name, Object value) {
229244
public static void main(String[] args) throws Exception {
230245
SpringApplication.run(DemoApplication.class, args);
231246

232-
Log.DEBUG = true; // 上线生产环境前改为 false,可不输出 APIJSONORM 的日志 以及 SQLException 的原始(敏感)信息
247+
// FIXME 不要开放给项目组后端之外的任何人使用 UnitAuto(强制登录鉴权)!!!如果不需要单元测试则移除相关代码或 unitauto.Log.DEBUG = false;
248+
unitauto.Log.DEBUG = Log.DEBUG = true; // 上线生产环境前改为 false,可不输出 APIJSONORM 的日志 以及 SQLException 的原始(敏感)信息
233249
APIJSONApplication.init();
234250
}
235251

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /