]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/account/TestCertificateRequest.java
fix: unfinished test
[gigi.git] / tests / org / cacert / gigi / pages / account / TestCertificateRequest.java
1 package org.cacert.gigi.pages.account;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
5
6 import java.io.IOException;
7 import java.security.GeneralSecurityException;
8 import java.security.KeyPair;
9
10 import org.cacert.gigi.GigiApiException;
11 import org.cacert.gigi.dbObjects.EmailAddress;
12 import org.cacert.gigi.dbObjects.Group;
13 import org.cacert.gigi.pages.account.certs.CertificateRequest;
14 import org.cacert.gigi.testUtils.ClientTest;
15 import org.cacert.gigi.util.AuthorizationContext;
16 import org.junit.Test;
17
18 public class TestCertificateRequest extends ClientTest {
19
20     KeyPair kp = generateKeypair();
21
22     AuthorizationContext ac;
23
24     public TestCertificateRequest() throws GeneralSecurityException, IOException {
25         ac = new AuthorizationContext(u, u);
26         makeAssurer(u.getId());
27         grant(email, Group.CODESIGNING);
28
29     }
30
31     @Test
32     public void testIssuingOtherName() throws Exception {
33         try {
34             new CertificateRequest(ac, generatePEMCSR(kp, "CN=hansi")).draft();
35             fail();
36         } catch (GigiApiException e) {
37             assertThat(e.getMessage(), containsString("name you entered was invalid"));
38         }
39     }
40
41     @Test
42     public void testIssuingDefault() throws Exception {
43         new CertificateRequest(ac, generatePEMCSR(kp, "CN=" + CertificateRequest.DEFAULT_CN + ",EMAIL=" + email)).draft();
44     }
45
46     @Test
47     public void testIssuingRealName() throws Exception {
48         new CertificateRequest(ac, generatePEMCSR(kp, "CN=a b,EMAIL=" + email)).draft();
49     }
50
51     @Test
52     public void testIssuingModifiedName() throws Exception {
53         try {
54             new CertificateRequest(ac, generatePEMCSR(kp, "CN=a ab")).draft();
55             fail();
56         } catch (GigiApiException e) {
57             assertThat(e.getMessage(), containsString("name you entered was invalid"));
58         }
59
60     }
61
62     // TODO annotate that this depends on default config
63     @Test
64     public void testCodesignModifiedName() throws Exception {
65         try {
66             CertificateRequest cr = new CertificateRequest(ac, generatePEMCSR(kp, "CN=a ab"));
67             System.out.println("eml");
68             for (EmailAddress e : u.getEmails()) {
69                 System.out.println(e.getAddress());
70             }
71             cr.update("name", "SHA512", "code-a", null, null, "email:" + email, null, null);
72             cr.draft();
73             fail();
74         } catch (GigiApiException e) {
75             assertThat(e.getMessage(), containsString("does not match the details"));
76         }
77
78     }
79 }