2222 * SOFTWARE.
2323 */
2424
25+ declare (strict_types=1 );
26+
2527namespace web_eid \web_eid_authtoken_validation_php \validator \ocsp ;
2628
2729use phpseclib3 \File \X509 ;
@@ -32,9 +34,45 @@ class OcspUrlTest extends TestCase
3234 public function testWhenExtensionValueIsNullThenReturnsNull ()
3335 {
3436 $ mockCertificate = $ this ->createMock (X509 ::class);
35- $ mockCertificate ->method (' getExtension ' )->willReturn (null );
37+ $ mockCertificate ->method (" getExtension " )->willReturn (null );
3638 $ this ->assertNull (OcspUrl::getOcspUri ($ mockCertificate ));
3739 }
3840
39- // TODO: Investigate two more tests
41+ public function testWhenExtensionValueIsInvalidThenReturnsNull ()
42+ {
43+ $ mockCertificate = $ this ->createMock (X509 ::class);
44+ $ mockCertificate ->method ("getExtension " )->willReturn ([
45+ [
46+ "accessMethod " => "id-ad-ocsp " ,
47+ 'accessLocation ' => ["uniformResourceIdentifier " => pack ("c* " , ...array (1 , 2 , 3 ))]
48+ ]
49+ ]);
50+
51+ // We will get empty uri parts
52+ $ url = OcspUrl::getOcspUri ($ mockCertificate );
53+ $ this ->assertFalse ($ url ->isAbsolute ());
54+ $ this ->assertEmpty ($ url ->getScheme ());
55+ $ this ->assertEmpty ($ url ->getHost ());
56+ }
57+
58+ public function testWhenExtensionValueIsNotAiaThenReturnsNull ()
59+ {
60+ $ mockCertificate = $ this ->createMock (X509 ::class);
61+ $ mockCertificate ->method ("getExtension " )->willReturn ([
62+ [
63+ "accessMethod " => "id-ad-ocsp " ,
64+ 'accessLocation ' => ["uniformResourceIdentifier " => pack ("c* " , ...array (4 , 64 , 48 , 62 , 48 , 50 , 6 , 11 , 43 , 6 , 1 , 4 , 1 , -125 , -111 , 33 , 1 , 2 , 1 , 48 ,
65+ 35 , 48 , 33 , 6 , 8 , 43 , 6 , 1 , 5 , 5 , 7 , 2 , 1 , 22 , 21 , 104 , 116 , 116 , 112 , 115 ,
66+ 58 , 47 , 47 , 119 , 119 , 119 , 46 , 115 , 107 , 46 , 101 , 101 , 47 , 67 , 80 , 83 , 48 ,
67+ 8 , 6 , 6 , 4 , 0 , -113 , 122 , 1 , 2 ))]
68+ ]
69+ ]);
70+
71+ // We will get empty uri parts
72+ $ url = OcspUrl::getOcspUri ($ mockCertificate );
73+ $ this ->assertFalse ($ url ->isAbsolute ());
74+ $ this ->assertEmpty ($ url ->getScheme ());
75+ $ this ->assertEmpty ($ url ->getHost ());
76+ }
77+
4078}
0 commit comments