使用ActiveDirectoryLdapAuthenticationProvider进行集成测试

5

上次我在我们的项目中添加了另一个身份验证提供程序,以便通过Windows Active Directory服务器对用户进行身份验证:

<security:authentication-manager id="authenticationManager" erase-credentials="true">
        <security:authentication-provider ref="ldapActiveDirectoryAuthProvider" />
        <security:authentication-provider ref="authenticationProvider1"/>
        <security:authentication-provider ref="authenticationProvider2"/>
    </security:authentication-manager>

     <bean id="customLdapUserDetailsMapper" class="security.authentication.customLdapUserDetailsMapper">
     </bean>

     <bean id="ldapActiveDirectoryAuthProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
       <constructor-arg value="my.domain"/>
       <constructor-arg value="ldap://my.custom.host:389" />
       <property name="useAuthenticationRequestCredentials" value="true" />
       <property name="convertSubErrorCodesToExceptions" value="true" />
       <property name="userDetailsContextMapper" ref="customLdapUserDetailsMapper" />
     </bean>

几乎所有工作都很好,除了与身份验证流程一起工作的现有集成测试。即每个测试在 ActiveDirectoryLdapAuthenticationProvider.bindAsUser 时尝试连接服务器,但由于此类型的测试不可用,因此失败了 my.custom.host

我开始搜索这种测试的某些模拟,但不幸的是,我只发现了这篇文章 Integration tests with spring-security and ldap ,其中 Luke Taylor 建议使用现有的集成测试作为指南。我看了一下,但没有包含任何此类提供程序的测试。

我对这方面还比较新,所以想知道以下几点:

  1. 使用在LDAP集成测试中提到的 new ApacheDSContainer("dc=springframework,dc=org", "classpath:test-server.ldif"); 这种方法重新使用是否正确(我不确定它是否适合我,因为我没有在应用程序上下文中创建嵌入式LDAP服务器,也没有在上述配置中指定任何 .ldif 文件)?
  2. 哪种方式可以适当地模拟以下提供程序?
1个回答

1
实际上,您只需提供另一个配置文件以进行测试。在那里,您可以定义一个不同的身份验证提供者,例如只能对每个人进行身份验证...... 或者只是简单地完全禁用身份验证。
因为您不想测试spring提供的功能。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接