1
+ /*
2
+ * Copyright (c) 2025 MarkLogic Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ let testconfig = require ( '../etc/test-config.js' ) ;
18
+ let should = require ( 'should' ) ;
19
+ let marklogic = require ( '../' ) ;
20
+ const { exec } = require ( 'child_process' ) ;
21
+ let db = marklogic . createDatabaseClient ( testconfig . restWriterConnection ) ;
22
+
23
+ describe ( 'document content' , function ( ) {
24
+ this . timeout ( 5000 ) ;
25
+ before ( function ( done ) {
26
+ updateTlsVersion ( 'TLSv1.3' ) ;
27
+ setTimeout ( ( ) => { done ( ) ; } , 3000 ) ;
28
+ } ) ;
29
+
30
+ after ( function ( done ) {
31
+ db . documents . remove ( '/test/write_tlsV1.3.json' , '/test/write_tlsV1.2.json' )
32
+ . result ( ( ) => done ( ) )
33
+ . catch ( error => done ( error ) ) ;
34
+ } ) ;
35
+
36
+ it ( 'should write document with minimum TLS versions 1.3 and 1.2' , function ( done ) {
37
+
38
+ db . documents . write ( {
39
+ uri : '/test/write_tlsV1.3.json' ,
40
+ contentType : 'application/json' ,
41
+ content : '{"key1":"With TLS 1.3"}'
42
+ } )
43
+ . result ( function ( response ) {
44
+ db . documents . read ( '/test/write_tlsV1.3.json' )
45
+ . result ( function ( documents ) {
46
+ documents [ 0 ] . content . should . have . property ( 'key1' ) ;
47
+ documents [ 0 ] . content . key1 . should . equal ( 'With TLS 1.3' ) ;
48
+
49
+ } ) . then ( ( ) => {
50
+ updateTlsVersion ( 'TLSv1.2' ) ;
51
+ } )
52
+ . then ( ( ) => {
53
+ db . documents . write ( {
54
+ uri : '/test/write_tlsV1.2.json' ,
55
+ contentType : 'application/json' ,
56
+ content : '{"key1":"With TLS 1.2"}'
57
+ } ) . result ( function ( ) {
58
+ db . documents . read ( '/test/write_tlsV1.2.json' )
59
+ . result ( function ( documents ) {
60
+ documents [ 0 ] . content . should . have . property ( 'key1' ) ;
61
+ documents [ 0 ] . content . key1 . should . equal ( 'With TLS 1.2' ) ;
62
+ done ( ) ;
63
+ } )
64
+ } )
65
+ } )
66
+ . catch ( error => done ( error ) ) ;
67
+ } )
68
+ . catch ( error => done ( error ) ) ;
69
+ } ) ;
70
+ } )
71
+
72
+ function updateTlsVersion ( tlsVersion ) {
73
+ return new Promise ( ( resolve , reject ) => {
74
+ const curlCommand = `
75
+ curl --anyauth --user admin:admin -X PUT -H "Content-Type: application/json" \\
76
+ -d '{"ssl-min-allow-tls": "${ tlsVersion } "}' \\
77
+ 'http://localhost:8002/manage/v2/servers/unittest-nodeapi/properties?group-id=Default'
78
+ ` ;
79
+ exec ( curlCommand , ( error , stdout , stderr ) => {
80
+ if ( error ) {
81
+ throw new Error ( `Error executing curl: ${ stderr } ` ) ;
82
+ }
83
+ } ) ;
84
+ } ) ;
85
+ }
0 commit comments