CertificateTest.java 1.01 KB
Newer Older
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
package org.jivesoftware.util;

import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Basic tests for code used by CertificateManager.
 *
 * @author Gaston Dombiak
 */
public class CertificateTest extends TestCase {

    /**
     * Verify that all CN elements are found.
     */
    public void testCN() {
        Pattern cnPattern = Pattern.compile("(?i)(cn=)([^,]*)");
        String text = "EMAILADDRESS=XXXXX@scifi.com, CN=scifi.com, CN=jabber.scifi.com, OU=Domain validated only, O=XX, L=Skx, C=SE";
        List<String> found = new ArrayList<String>();
        Matcher matcher = cnPattern.matcher(text);
        while (matcher.find()) {
            found.add(matcher.group(2));
        }
        assertEquals("Incorrect number of CNs were found", 2, found.size());
        assertEquals("Incorrect CN found", "scifi.com" , found.get(0));
        assertEquals("Incorrect CN found", "jabber.scifi.com" , found.get(1));
    }
}