summaryrefslogtreecommitdiffstats
path: root/vespa-athenz/src/test/java/com/yahoo/vespa/athenz/tls/Pkcs10CsrUtilsTest.java
blob: fcbc6d00a8e0bf75ad851f9fab933dcefeabceb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.yahoo.vespa.athenz.tls;

import com.yahoo.security.KeyAlgorithm;
import com.yahoo.security.KeyUtils;
import org.junit.Test;

import javax.security.auth.x500.X500Principal;
import java.security.KeyPair;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

/**
 * @author bjorncs
 */
public class Pkcs10CsrUtilsTest {

    @Test
    public void can_deserialize_serialized_pem_csr() {
        X500Principal subject = new X500Principal("CN=subject");
        KeyPair keypair = KeyUtils.generateKeypair(KeyAlgorithm.RSA, 2048);
        Pkcs10Csr csr = Pkcs10CsrBuilder.fromKeypair(subject, keypair, SignatureAlgorithm.SHA256_WITH_RSA).build();
        String pem = Pkcs10CsrUtils.toPem(csr);
        Pkcs10Csr deserializedCsr = Pkcs10CsrUtils.fromPem(pem);
        assertThat(pem, containsString("BEGIN CERTIFICATE REQUEST"));
        assertThat(pem, containsString("END CERTIFICATE REQUEST"));
        assertEquals(subject, deserializedCsr.getSubject());
    }

}