• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pgpainless / sop-java / #66

12 Jan 2026 12:52PM UTC coverage: 58.148% (+0.2%) from 57.95%
#66

push

other

vanitasvitae
MergeCertsTest: Add test for non-armored output

19 of 22 new or added lines in 1 file covered. (86.36%)

2123 of 3651 relevant lines covered (58.15%)

0.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.21
/sop-java-testfixtures/src/main/java/sop/testsuite/operation/MergeCertsTest.java
1
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
2
//
3
// SPDX-License-Identifier: Apache-2.0
4

5
package sop.testsuite.operation;
6

7
import kotlin.collections.ArraysKt;
8
import org.junit.jupiter.params.ParameterizedTest;
9
import org.junit.jupiter.params.provider.Arguments;
10
import org.junit.jupiter.params.provider.MethodSource;
11
import sop.SOP;
12

13
import java.io.IOException;
14
import java.util.stream.Stream;
15

16
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
17

18
public class MergeCertsTest extends AbstractSOPTest {
1✔
19

20
    static Stream<Arguments> provideInstances() {
21
        return provideBackends();
1✔
22
    }
23

24
    @ParameterizedTest
25
    @MethodSource("provideInstances")
26
    public void testMergeWithItself(SOP sop) throws IOException {
27
        byte[] key = assumeSupported(sop::generateKey)
1✔
28
                .userId("Alice <alice@pgpainless.org>")
1✔
29
                .generate()
1✔
30
                .getBytes();
1✔
31

32
        byte[] cert = assumeSupported(sop::extractCert)
1✔
33
                .key(key)
1✔
34
                .getBytes();
1✔
35

36
        byte[] merged = assumeSupported(sop::mergeCerts)
1✔
37
                .updates(cert)
1✔
38
                .baseCertificates(cert)
1✔
39
                .getBytes();
×
40

41
        assertArrayEquals(cert, merged);
×
42
    }
×
43

44
    @ParameterizedTest
45
    @MethodSource("provideInstances")
46
    public void testMergeWithItselfArmored(SOP sop) throws IOException {
47
        byte[] key = assumeSupported(sop::generateKey)
1✔
48
                .noArmor()
1✔
49
                .userId("Alice <alice@pgpainless.org>")
1✔
50
                .generate()
1✔
51
                .getBytes();
1✔
52

53
        byte[] cert = assumeSupported(sop::extractCert)
1✔
54
                .key(key)
1✔
55
                .getBytes();
1✔
56

57
        byte[] merged = assumeSupported(sop::mergeCerts)
1✔
58
                .updates(cert)
1✔
59
                .baseCertificates(cert)
1✔
60
                .getBytes();
×
61

62
        assertArrayEquals(cert, merged);
×
63
    }
×
64

65
    @ParameterizedTest
66
    @MethodSource("provideInstances")
67
    public void testMergeWithItselfViaBase(SOP sop) throws IOException {
68
        byte[] key = assumeSupported(sop::generateKey)
1✔
69
                .userId("Alice <alice@pgpainless.org>")
1✔
70
                .generate()
1✔
71
                .getBytes();
1✔
72

73
        byte[] cert = assumeSupported(sop::extractCert)
1✔
74
                .key(key)
1✔
75
                .getBytes();
1✔
76

77
        byte[] certs = ArraysKt.plus(cert, cert);
1✔
78

79
        byte[] merged = assumeSupported(sop::mergeCerts)
1✔
80
                .updates(cert)
1✔
81
                .baseCertificates(certs)
1✔
82
                .getBytes();
×
83

84
        assertArrayEquals(cert, merged);
×
85
    }
×
86

87
    @ParameterizedTest
88
    @MethodSource("provideInstances")
89
    public void testApplyBaseToUpdate(SOP sop) throws IOException {
90
        byte[] key = assumeSupported(sop::generateKey)
1✔
91
                .userId("Alice <alice@pgpainless.org>")
1✔
92
                .generate()
1✔
93
                .getBytes();
1✔
94

95
        byte[] cert = assumeSupported(sop::extractCert)
1✔
96
                .key(key)
1✔
97
                .getBytes();
1✔
98

99
        byte[] update = assumeSupported(sop::revokeKey)
1✔
100
                .keys(key)
1✔
101
                .getBytes();
×
102

103
        byte[] merged = assumeSupported(sop::mergeCerts)
×
104
                .updates(cert)
×
105
                .baseCertificates(update)
×
106
                .getBytes();
×
107

108
        assertArrayEquals(update, merged);
×
109
    }
×
110

111
    @ParameterizedTest
112
    @MethodSource("provideInstances")
113
    public void testApplyUpdateToBase(SOP sop) throws IOException {
114
        byte[] key = assumeSupported(sop::generateKey)
1✔
115
                .userId("Alice <alice@pgpainless.org>")
1✔
116
                .generate()
1✔
117
                .getBytes();
1✔
118

119
        byte[] cert = assumeSupported(sop::extractCert)
1✔
120
                .key(key)
1✔
121
                .getBytes();
1✔
122

123
        byte[] update = assumeSupported(sop::revokeKey)
1✔
124
                .keys(key)
1✔
125
                .getBytes();
×
126

127
        byte[] merged = assumeSupported(sop::mergeCerts)
×
128
                .updates(update)
×
129
                .baseCertificates(cert)
×
130
                .getBytes();
×
131

132
        assertArrayEquals(update, merged);
×
133
    }
×
134

135
    @ParameterizedTest
136
    @MethodSource("provideInstances")
137
    public void testApplyUpdateToMissingBaseDoesNothing(SOP sop) throws IOException {
138
        byte[] aliceKey = assumeSupported(sop::generateKey)
1✔
139
                .userId("Alice <alice@pgpainless.org>")
1✔
140
                .generate()
1✔
141
                .getBytes();
1✔
142

143
        byte[] aliceCert = assumeSupported(sop::extractCert)
1✔
144
                .key(aliceKey)
1✔
145
                .getBytes();
1✔
146

147
        byte[] bobKey = assumeSupported(sop::generateKey)
1✔
148
                .userId("Bob <bob@pgpainless.org>")
1✔
149
                .generate()
1✔
150
                .getBytes();
1✔
151

152
        byte[] bobCert = assumeSupported(sop::extractCert)
1✔
153
                .key(bobKey)
1✔
154
                .getBytes();
1✔
155

156
        byte[] merged = assumeSupported(sop::mergeCerts)
1✔
157
                .updates(bobCert)
1✔
158
                .baseCertificates(aliceCert)
1✔
159
                .getBytes();
×
160

161
        assertArrayEquals(aliceCert, merged);
×
162
    }
×
163

164
    @ParameterizedTest
165
    @MethodSource("provideInstances")
166
    public void testApplyUpdateToMissingBaseDoesNothingNoArmor(SOP sop) throws IOException {
167
        byte[] aliceKey = assumeSupported(sop::generateKey)
1✔
168
                .userId("Alice <alice@pgpainless.org>")
1✔
169
                .generate()
1✔
170
                .getBytes();
1✔
171

172
        byte[] aliceCert = assumeSupported(sop::extractCert)
1✔
173
                .noArmor()
1✔
174
                .key(aliceKey)
1✔
175
                .getBytes();
1✔
176

177
        byte[] bobKey = assumeSupported(sop::generateKey)
1✔
178
                .userId("Bob <bob@pgpainless.org>")
1✔
179
                .generate()
1✔
180
                .getBytes();
1✔
181

182
        byte[] bobCert = assumeSupported(sop::extractCert)
1✔
183
                .key(bobKey)
1✔
184
                .getBytes();
1✔
185

186
        byte[] merged = assumeSupported(sop::mergeCerts)
1✔
187
                .noArmor()
1✔
188
                .updates(bobCert)
1✔
189
                .baseCertificates(aliceCert)
1✔
NEW
190
                .getBytes();
×
191

NEW
192
        assertArrayEquals(aliceCert, merged);
×
NEW
193
    }
×
194

195
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc