@@ -50,8 +50,8 @@ public static void main(String[] args) throws Exception {
50
50
try (Recording recording = new Recording ()) {
51
51
recording .enable (EventNames .X509Validation );
52
52
recording .start ();
53
- // intermeditate certificate test
54
- TestCertificate .generateChain (false );
53
+ // intermediate certificate test
54
+ TestCertificate .generateChain (false , true );
55
55
recording .stop ();
56
56
List <RecordedEvent > events = Events .fromRecording (recording );
57
57
Asserts .assertEquals (events .size (), 3 , "Incorrect number of events" );
@@ -62,12 +62,23 @@ public static void main(String[] args) throws Exception {
62
62
recording .enable (EventNames .X509Validation );
63
63
recording .start ();
64
64
// self signed certificate test
65
- TestCertificate .generateChain (true );
65
+ TestCertificate .generateChain (true , true );
66
66
recording .stop ();
67
67
List <RecordedEvent > events = Events .fromRecording (recording );
68
68
Asserts .assertEquals (events .size (), 2 , "Incorrect number of events" );
69
69
assertEvent2 (events );
70
70
}
71
+
72
+ try (Recording recording = new Recording ()) {
73
+ recording .enable (EventNames .X509Validation );
74
+ recording .start ();
75
+ // intermediate certificate test, with no Cert for trust anchor
76
+ TestCertificate .generateChain (true , false );
77
+ recording .stop ();
78
+ List <RecordedEvent > events = Events .fromRecording (recording );
79
+ Asserts .assertEquals (events .size (), 2 , "Incorrect number of events" );
80
+ assertEvent3 (events );
81
+ }
71
82
}
72
83
73
84
private static void assertEvent1 (List <RecordedEvent > events ) throws Exception {
@@ -111,4 +122,26 @@ private static void assertEvent2(List<RecordedEvent> events) throws Exception {
111
122
}
112
123
}
113
124
}
125
+ /*
126
+ * Self signed certificate test
127
+ */
128
+ private static void assertEvent3 (List <RecordedEvent > events ) throws Exception {
129
+ for (RecordedEvent e : events ) {
130
+ int pos = e .getInt ("certificatePosition" );
131
+ switch (pos ) {
132
+ // use public key of cert provided in TrustAnchor
133
+ case 1 :
134
+ Asserts .assertEquals (e .getLong ("certificateId" ),
135
+ Long .valueOf (TestCertificate .ROOT_CA .certificate ().getPublicKey ().hashCode ()));
136
+ break ;
137
+ case 2 :
138
+ Events .assertField (e , "certificateId" )
139
+ .equal (TestCertificate .ROOT_CA .certId );
140
+ break ;
141
+ default :
142
+ System .out .println (events );
143
+ throw new Exception ("Unexpected position:" + pos );
144
+ }
145
+ }
146
+ }
114
147
}
0 commit comments