aboutsummaryrefslogtreecommitdiff
path: root/src/test/model/ca/TemplateTest.java
blob: 774d38cd8e6d6fcc623655e39645c946653246a5 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package model.ca;

import model.asn1.ASN1Object;
import model.asn1.ObjectIdentifier;
import model.asn1.PrintableString;
import model.asn1.exceptions.ParseException;
import model.x501.AttributeTypeAndValue;
import model.x501.Name;
import model.x501.RelativeDistinguishedName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class TemplateTest {
    @Test
    void testConstructor() throws ParseException {
        Template template = new Template("123", true, (Name) null, 123);
        assertEquals("123", template.getName());
        assertTrue(template.isEnabled());
        assertNull(template.getSubject());
        assertEquals(123, template.getValidity());

        template = new Template("123", true,
                new Name(ASN1Object.TAG_SEQUENCE, null, new RelativeDistinguishedName[]{
                        new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{
                                new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null,
                                        new ObjectIdentifier(ObjectIdentifier.TAG, null,
                                                ObjectIdentifier.OID_CN),
                                        new PrintableString(PrintableString.TAG, null, "Test"))}),
                        new RelativeDistinguishedName(ASN1Object.TAG_SET, null, new AttributeTypeAndValue[]{
                                new AttributeTypeAndValue(ASN1Object.TAG_SEQUENCE, null,
                                        new ObjectIdentifier(ObjectIdentifier.TAG, null,
                                                ObjectIdentifier.OID_C),
                                        new PrintableString(PrintableString.TAG, null, "CA"))})}),
                123);
        assertEquals("CN=Test,C=CA", template.getSubject().toString());

        template = new Template("123", true, (String) null, 123);
        assertNull(template.getSubject());
    }

    @Test
    void testSetSubject() throws ParseException {
        Template template = new Template("123", true, "ABC", 123);
        assertEquals("CN=ABC,C=CA", template.getSubject().toString());

        assertThrows(ParseException.class, () -> new Template("123", true, "*",
                123));
    }
}