简体   繁体   English

JMockIt安全异常签名者信息不匹配

[英]JMockIt security exception signer information does not match

When running JMockIt and trying to mock an instance in testng that is loaded from a signed jar I get an error along the lines of (in this case of a jetty server): 当运行JMockIt并尝试模拟从已签名的jar加载的testng中的实例时,出现以下错误(在这种情况下为码头服务器):

FAILED CONFIGURATION: @BeforeClass startServer
java.lang.SecurityException: class "javax.servlet.FilterRegistration"'s signer information does not match signer information of other classes in the same package
    at java.lang.ClassLoader.checkCerts(ClassLoader.java:943)
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:657)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:785)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    ...

The dependency order in the pom is correct, and without the mocks the tests run fine. pom中的依赖关系顺序是正确的,并且在没有模拟的情况下测试也可以正常运行。 So the tips from Java SecurityException: signer information does not match do not help here. 因此,来自Java SecurityException的提示:签名人信息不匹配在这里没有帮助。

Is there a workaround? 有解决方法吗?


Here is a sample test up, that should produce the error. 这是一个示例测试,应该会产生错误。 In this case we start an entire container for an integration test: 在这种情况下,我们启动整个容器进行集成测试:

public class MyServletTest {
    private final Server server = new Server(PORT);
    private MockUp<OpenIDAuthenticationProvider> openIDap;

    @BeforeClass
    public void startServer() throws Exception {
        final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.addServlet(MyServlet.class, "/my/*");
        this.server.setHandler(context);
        this.server.start();
        this.openIDap = new MockUp<OpenIDAuthenticationProvider>() {
            @Mock
            void $init(final UserDAO userDao) {}
        };
    }

    @Test
    ...
}

The OpenIDAuthenticationProvider is called from within MyServlet and instantiated during startup, although I'm not sure that even matters. OpenIDAuthenticationProvider是从MyServlet内部调用的,并在启动过程中实例化,尽管我不确定这是否重要。

the corresponding part in the pom.xml looks like this: pom.xml中的相应部分如下所示:

<dependencies>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-servlet</artifactId>
        <version>9.0.3.v20130506</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-server</artifactId>
        <version>9.0.3.v20130506</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

One way is to use JMockIt to deactivate the certificate check. 一种方法是使用JMockIt停用证书检查。 Since JMockIt (and other Mocking Frameworks) work via instrumentation, any class can be modified. 由于JMockIt(和其他Mocking框架)通过检测工作,因此可以修改任何类。 Here is an example as to how to mock the part of the ClassLoader, that causes the troubles: 这是一个有关如何模拟ClassLoader部分的示例,这会引起麻烦:

@BeforeSuite
public void deactivateCertChecker() {
    new MockUp<ClassLoader>() {
        @Mock
        void checkCerts(final String name, final CodeSource cs) {}
    };
}

Mind you though, that this is not a fix for actually running a program that has signing issues, as the effect is only available during test runs, when mocking has been instrumented. 请注意,这并不是实际运行存在签名问题的程序的解决方案,因为只有在测试了模拟后,该效果才在测试运行期间可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 签名者信息不匹配 - Signer information does not match 签名者信息与同一个其他类的签名者信息不匹配 package - Signer information does not match signer information of other classes in the same package Java SecurityException:签名者信息不匹配 - Java SecurityException: signer information does not match java.lang.SecurityException:签名者信息与同一包中其他类的签名者信息不匹配 - java.lang.SecurityException: signer information does not match signer information of other classes in the same package JFace签名者信息与同一package中其他类的签名者信息不匹配 - JFace signer information does not match signer information of other classes in the same package Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配 - Hamcrest Matcher signer information does not match signer information of other classes in the same package 类“ SynchronousHelper”的签名者信息与同一包中其他类的签名者信息不匹配 - class “SynchronousHelper”'s signer information does not match signer information of other classes in the same package org.bouncycastle.asn1.ASN1ObjectIdentifier“的签名者信息与签名者信息不匹配 - org.bouncycastle.asn1.ASN1ObjectIdentifier"'s signer information does not match signer information 启动程序后CGLIB错误(签名者信息与同一软件包中其他类的签名者信息不匹配) - CGLIB error after launching program (signer information does not match signer information of other classes in the same package) 类“ org.bouncycastle.cms.CMSProcessable”的签名者信息与其他类的签名者信息不匹配 - class “org.bouncycastle.cms.CMSProcessable”'s signer information does not match signer information of other classes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM