1
+ /**
2
+ * The Javascript Just In Time compiler is deprecated in 7.0.
3
+ *
4
+ * This test checks that we log the deprecation warning correctly when setting the server parameter
5
+ * on startup or on runtime.
6
+ */
7
+ ( function ( ) {
8
+ 'use strict' ;
9
+ load ( "jstests/libs/log.js" ) ; // For findMatchingLogLine.
10
+
11
+ const dbName = 'testDB' ;
12
+
13
+ function checkLogs ( db , deprecationMsg , numMatchingLines ) {
14
+ const globalLogs = db . adminCommand ( { getLog : 'global' } ) ;
15
+ const matchingLogLines = [ ...findMatchingLogLines ( globalLogs . log , deprecationMsg ) ] ;
16
+ assert . eq ( matchingLogLines . length , numMatchingLines , matchingLogLines ) ;
17
+ }
18
+
19
+ /**
20
+ * This function will test for the logging of the deprecation messages for the disableJavaScriptJIT
21
+ * server parameter. The test can run either on mongod or mongos.
22
+ *
23
+ * db: The specified mongod or mongos.
24
+ * deprecationMsg: The expected log message.
25
+ * command: The setParameter command.
26
+ * shards: The ShardingTest containing the shards that pair up with the mongos. Null by
27
+ * default to accomodate for the mongod case.
28
+ */
29
+ function deprecationTest ( db , deprecationMsg , command , shards = null ) {
30
+ // We set the parameter on startup so the message should get logged.
31
+ checkLogs ( db , deprecationMsg , 1 ) ;
32
+
33
+ if ( shards ) {
34
+ // Same as above but in the shards.
35
+ checkLogs ( shards . shard0 . getDB ( db ) , deprecationMsg , 1 ) ;
36
+ checkLogs ( shards . shard1 . getDB ( db ) , deprecationMsg , 1 ) ;
37
+ }
38
+
39
+ // We change the parameter during runtime to log the message again.
40
+ assert . commandWorked ( db . adminCommand ( command ) ) ;
41
+ checkLogs ( db , deprecationMsg , 2 ) ;
42
+ if ( shards ) {
43
+ // Same as above but in the shards.
44
+ assert . commandWorked ( shards . shard0 . getDB ( db ) . adminCommand ( command ) ) ;
45
+ assert . commandWorked ( shards . shard1 . getDB ( db ) . adminCommand ( command ) ) ;
46
+ checkLogs ( shards . shard0 . getDB ( db ) , deprecationMsg , 2 ) ;
47
+ checkLogs ( shards . shard1 . getDB ( db ) , deprecationMsg , 2 ) ;
48
+ }
49
+ }
50
+
51
+ const deprecationMessage = {
52
+ msg : "The Javascript Just In Time compiler is deprecated, and should be disabled " +
53
+ "for security reasons. The server parameter will be removed in a future major " +
54
+ "version. See https://www.mongodb.com/docs/manual/reference/parameters for " +
55
+ "more information."
56
+ } ;
57
+
58
+ const setParameterCmdObj = {
59
+ setParameter : 1 ,
60
+ disableJavaScriptJIT : false
61
+ } ;
62
+
63
+ jsTest . log ( 'Test standalone' ) ;
64
+
65
+ const standaloneWithKnob = MongoRunner . runMongod ( { setParameter : { disableJavaScriptJIT : false } } ) ;
66
+ const standaloneWithKnobDB = standaloneWithKnob . getDB ( dbName ) ;
67
+
68
+ deprecationTest ( standaloneWithKnobDB , deprecationMessage , setParameterCmdObj ) ;
69
+
70
+ MongoRunner . stopMongod ( standaloneWithKnob ) ;
71
+
72
+ jsTest . log ( 'Test sharded' ) ;
73
+
74
+ const shardsWithKnob = new ShardingTest ( {
75
+ shards : 2 ,
76
+ mongos : 1 ,
77
+ other : {
78
+ shardOptions : { setParameter : { disableJavaScriptJIT : false } } ,
79
+ mongosOptions : { setParameter : { disableJavaScriptJIT : false } }
80
+ }
81
+ } ) ;
82
+ const sessionWithKnob = shardsWithKnob . s . getDB ( dbName ) . getMongo ( ) . startSession ( ) ;
83
+ const shardedWithKnobDB = sessionWithKnob . getDatabase ( dbName ) ;
84
+
85
+ deprecationTest ( shardedWithKnobDB , deprecationMessage , setParameterCmdObj , shardsWithKnob ) ;
86
+
87
+ shardsWithKnob . stop ( ) ;
88
+
89
+ jsTest . log ( 'Negative tests' ) ;
90
+
91
+ // Now we do negative tests to check that the message isn't logged if we don't set the parameter.
92
+ const standaloneWithoutKnob = MongoRunner . runMongod ( ) ;
93
+ const standaloneWithoutKnobDB = standaloneWithoutKnob . getDB ( dbName ) ;
94
+
95
+ checkLogs ( standaloneWithoutKnobDB , deprecationMessage , 0 ) ;
96
+
97
+ MongoRunner . stopMongod ( standaloneWithoutKnob ) ;
98
+
99
+ const shardsWithoutKnob = new ShardingTest ( {
100
+ shards : 2 ,
101
+ mongos : 1 ,
102
+ } ) ;
103
+ const sessionWithoutKnob = shardsWithoutKnob . s . getDB ( dbName ) . getMongo ( ) . startSession ( ) ;
104
+ const shardedWithoutKnobDB = sessionWithoutKnob . getDatabase ( dbName ) ;
105
+
106
+ checkLogs ( shardedWithoutKnobDB , deprecationMessage , 0 ) ;
107
+ checkLogs ( shardsWithoutKnob . shard0 . getDB ( shardedWithoutKnobDB ) , deprecationMessage , 0 ) ;
108
+ checkLogs ( shardsWithoutKnob . shard1 . getDB ( shardedWithoutKnobDB ) , deprecationMessage , 0 ) ;
109
+
110
+ shardsWithoutKnob . stop ( ) ;
111
+ } ) ( ) ;
0 commit comments