@@ -9,6 +9,19 @@ require_once "tests/utils/basic.inc";
9
9
$ dsn = sprintf ("%s/?ssl=true " , MONGODB_STANDALONE_SSL_URI );
10
10
11
11
$ SSL_DIR = realpath (__DIR__ . "/ " . "./../../scripts/ssl/ " );
12
+ function isValid (array $ cert ) {
13
+ $ from = $ cert ["validFrom_time_t " ];
14
+ $ to = $ cert ["validTo_time_t " ];
15
+
16
+ $ current = time ();
17
+
18
+ if ($ from > $ current && $ current < $ to ) {
19
+ return true ;
20
+ }
21
+
22
+ return false ;
23
+ }
24
+
12
25
$ opts = array (
13
26
"ssl " => array (
14
27
"peer_name " => "MongoDB " ,
@@ -26,7 +39,7 @@ $opts = array(
26
39
"capture_peer_cert_chain " => true ,
27
40
"SNI_enabled " => true ,
28
41
"disable_compression " => false ,
29
- "peer_fingerprint " => "" ,
42
+ "peer_fingerprint " => "0d6dbd95 " ,
30
43
),
31
44
);
32
45
$ context = stream_context_create ($ opts );
@@ -39,17 +52,29 @@ echo throws(function() use($mc) {
39
52
$ batch ->insert (array ("my " => "value " ));
40
53
$ retval = $ mc ->executeWriteBatch (NS , $ batch );
41
54
}, "MongoDB \\SSLConnectionException " , "executeWriteBatch " ), "\n" ;
42
- /*
55
+
56
+
57
+ echo "Changing to server \n" ;
58
+ stream_context_set_option ($ context , "ssl " , "CN_match " , "server " );
59
+ $ batch = new MongoDB \WriteBatch ;
60
+ $ batch ->insert (array ("my " => "value " ));
61
+ $ retval = $ mc ->executeWriteBatch (NS , $ batch );
62
+ printf ("Inserted: %d \n" , $ retval ->getInsertedCount ());
63
+
64
+
43
65
44
66
$ opts = stream_context_get_params ($ context );
45
- var_dump($opts);
46
67
$ cert = openssl_x509_parse ($ opts ["options " ]["ssl " ]["peer_certificate " ]);
47
- var_dump( $cert["name"]);
48
- */
68
+ printf ( " Certificate name: %s \n" , $ cert ["name " ]);
69
+ printf ( " Certificate valid (not expired): %s \n" , isValid ( $ cert ) ? " OK " : " NO " );
49
70
?>
50
71
===DONE===
51
72
<?php exit (0 ); ?>
52
73
--EXPECTF--
53
74
OK: Got MongoDB\SSLConnectionException thrown from executeWriteBatch
54
75
%s
76
+ Changing to server
77
+ Inserted: 1
78
+ Certificate name: /CN=server/OU=Kernel/O=MongoDB/L=New York City/ST=New York/C=US
79
+ Certificate valid (not expired): NO
55
80
===DONE===
0 commit comments