|
@@ -24,6 +24,7 @@ public class DataPermissionInterceptorTest {
|
|
|
private static String TEST_2 = "com.baomidou.userMapper.selectById";
|
|
|
private static String TEST_3 = "com.baomidou.roleMapper.selectByCompanyId";
|
|
|
private static String TEST_4 = "com.baomidou.roleMapper.selectById";
|
|
|
+ private static String TEST_5 = "com.baomidou.roleMapper.selectByRoleId";
|
|
|
|
|
|
/**
|
|
|
* 这里可以理解为数据库配置的数据权限规则 SQL
|
|
@@ -34,6 +35,7 @@ public class DataPermissionInterceptorTest {
|
|
|
put(TEST_2, "u.state=1 and u.amount > 1000");
|
|
|
put(TEST_3, "companyId in (1,2,3)");
|
|
|
put(TEST_4, "username like 'abc%'");
|
|
|
+ put(TEST_5, "id=1 and role_id in (select id from sys_role)");
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -45,7 +47,7 @@ public class DataPermissionInterceptorTest {
|
|
|
String sqlSegment = sqlSegmentMap.get(mappedStatementId);
|
|
|
Expression sqlSegmentExpression = CCJSqlParserUtil.parseCondExpression(sqlSegment);
|
|
|
if (null != where) {
|
|
|
- System.out.println("原 where = " + where.toString());
|
|
|
+ System.out.println("原 where : " + where.toString());
|
|
|
if (mappedStatementId.equals(TEST_4)) {
|
|
|
// 这里测试返回 OR 条件
|
|
|
return new OrExpression(where, sqlSegmentExpression);
|
|
@@ -84,6 +86,12 @@ public class DataPermissionInterceptorTest {
|
|
|
"SELECT * FROM sys_role WHERE id = 3 OR username LIKE 'abc%'");
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void test5() {
|
|
|
+ assertSql(TEST_5, "select * from sys_role where id=3",
|
|
|
+ "SELECT * FROM sys_role WHERE id = 3 AND id = 1 AND role_id IN (SELECT id FROM sys_role)");
|
|
|
+ }
|
|
|
+
|
|
|
void assertSql(String mappedStatementId, String sql, String targetSql) {
|
|
|
assertThat(interceptor.parserSingle(sql, mappedStatementId)).isEqualTo(targetSql);
|
|
|
}
|