-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[ldap]: add more global properties for ldap context source #3264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.8.36
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package org.zstack.test.unittest.ldap; | ||
|
|
||
| import com.unboundid.ldap.sdk.*; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.zapodot.junit.ldap.EmbeddedLdapRule; | ||
|
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find and examine the test file
find . -path "*test/src/test/groovy/org/zstack/test/unittest/ldap/TestLdapSearchCase.java" -o -path "*TestLdapSearchCase.java" | head -20Repository: MatheMatrix/zstack Length of output: 138 🏁 Script executed: #!/bin/bash
# Search for assert statements in the codebase
rg -n "assert\s+" --type java -g "*TestLdapSearchCase*" -A 1 -B 1Repository: MatheMatrix/zstack Length of output: 1457 🏁 Script executed: #!/bin/bash
# Check for -ea flag in build configuration files
rg -in "(-ea|enableAssertions|enable-assertions)" -g 'pom.xml' -g '*.gradle*' -g '*.kts' -C 2Repository: MatheMatrix/zstack Length of output: 44 🏁 Script executed: #!/bin/bash
# Read the test file to check imports and see all content
head -80 "test/src/test/groovy/org/zstack/test/unittest/ldap/TestLdapSearchCase.java" | cat -nRepository: MatheMatrix/zstack Length of output: 3749 使用 JUnit 断言替代 Java 多数测试运行环境不会启用 需要进行以下修改:
🤖 Prompt for AI Agents |
||
| import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class TestLdapSearchCase { | ||
| public static String DOMAIN_DSN = "dc=example,dc=com"; | ||
|
|
||
| static { | ||
| System.setProperty("com.unboundid.ldap.sdk.debug.enabled", "true"); | ||
| System.setProperty("com.unboundid.ldap.sdk.debug.level", "FINEST"); | ||
| System.setProperty("com.unboundid.ldap.sdk.LDAPConnectionOptions.followReferrals", "true"); | ||
| } | ||
|
|
||
| @ClassRule | ||
| public static EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder | ||
| .newInstance() | ||
| .usingDomainDsn("dc=example,dc=com") | ||
| .importingLdifs("users-import.ldif") | ||
| .bindingToPort(10389) | ||
| .build(); | ||
|
|
||
| @Test | ||
| public void testLdapWithIgnore() { | ||
| try (LDAPConnection ldapConnection = embeddedLdapRule.unsharedLdapConnection()) { | ||
| ldapConnection.getConnectionOptions().setFollowReferrals(false); | ||
| SearchResult searchResult = ldapConnection.search( | ||
| DOMAIN_DSN, | ||
| SearchScope.SUB, | ||
| "(objectclass=*)"); | ||
|
|
||
| System.out.printf("Found %d entries%n", searchResult.getEntryCount()); | ||
| for (SearchResultEntry entry : searchResult.getSearchEntries()) { | ||
| System.out.println(entry.getDN()); | ||
| for (Attribute attribute : entry.getAttributes()) { | ||
| System.out.printf(" %s: %s%n", attribute.getName(), attribute.getValue()); | ||
| } | ||
| } | ||
|
|
||
| System.out.println("Found referral URLs:" + Arrays.toString(searchResult.getReferralURLs())); | ||
| assert searchResult.getEntryCount() == 6; | ||
| } catch (Exception e) { | ||
| assert false : "Unexpected error during testLdapWithIgnore"; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testLdapWithReferral() throws LDAPException { | ||
| try (LDAPConnection ldapConnection = embeddedLdapRule.unsharedLdapConnection()) { | ||
| ldapConnection.getConnectionOptions().setFollowReferrals(true); | ||
| SearchResult searchResult = ldapConnection.search( | ||
| DOMAIN_DSN, | ||
| SearchScope.SUB, | ||
| "(objectclass=*)"); | ||
|
|
||
| System.out.printf("Found %d entries%n", searchResult.getEntryCount()); | ||
| for (SearchResultEntry entry : searchResult.getSearchEntries()) { | ||
| System.out.println(entry.getDN()); | ||
| for (Attribute attribute : entry.getAttributes()) { | ||
| System.out.printf(" %s: %s%n", attribute.getName(), attribute.getValue()); | ||
| } | ||
| } | ||
|
|
||
| System.out.println("Found referral URLs:" + Arrays.toString(searchResult.getReferralURLs())); | ||
| assert searchResult.getReferenceCount() == 1024; | ||
| } catch (StackOverflowError e) { | ||
| System.out.print("stack over flow expected"); | ||
| return; | ||
| } | ||
|
|
||
| assert false : "Unexpected here"; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 43329
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1723
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 3874
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2237
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1538
建议对 LDAP_REFERRAL 进行 trim 处理,防止空格导致 JNDI 初始化失败。
当前使用
Strings.isEmpty()仅判断 null 或空字符串,无法捕获仅包含空格、换行符等不可见字符的配置值。若 LDAP_REFERRAL 被意外配置为包含空白的值(如" "),该值会被判定为"非空"并传入setReferral(),导致 JNDI 上下文初始化失败。应使用StringUtils.trimToNull()在设置前进行 trim。♻️ 建议修改
Also applies to: 171-175
🤖 Prompt for AI Agents