Skip to content

Commit f7f5b48

Browse files
authored
Add test for OpenJdkSelfSignedCertGenerator (#15619)
Motivation: We recently had a problem where we run into issues when we ported some changes to 4.2 that made the OpenJdkSelfSignedCertGenerator not work at all anymore. We should test that it works on the expected JDK versions Modifications: Add unit test Result: Better coverage
1 parent 9e4bb29 commit f7f5b48

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2025 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package io.netty.handler.ssl.util;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.condition.EnabledOnJre;
21+
import org.junit.jupiter.api.condition.JRE;
22+
23+
import java.security.KeyPair;
24+
import java.security.KeyPairGenerator;
25+
import java.security.SecureRandom;
26+
import java.util.Date;
27+
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
30+
31+
public class OpenJdkSelfSignedCertGeneratorTest {
32+
33+
@Test
34+
@EnabledOnJre({ JRE.JAVA_8, JRE.JAVA_9, JRE.JAVA_10, JRE.JAVA_11 })
35+
public void testGenerate() throws Exception {
36+
SecureRandom random = new SecureRandom();
37+
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
38+
keyGen.initialize(2048, random);
39+
KeyPair keypair = keyGen.generateKeyPair();
40+
41+
String[] generated = OpenJdkSelfSignedCertGenerator.generate("netty.io", keypair, random,
42+
new Date(), new Date(253402300799000L), "RSA");
43+
assertEquals(2, generated.length);
44+
assertNotEquals(0, generated[0].length());
45+
assertNotEquals(0, generated[1].length());
46+
}
47+
}

0 commit comments

Comments
 (0)