@@ -5,6 +5,17 @@ import { sep } from 'path';
5
5
const version = __dirname . split ( sep ) . reverse ( ) [ 0 ] ;
6
6
const endpoint = `${ version } /ldap` ;
7
7
8
+ /**
9
+ * Describes a series of tests for LDAP search functionality
10
+ * @param {string } url - The LDAP server URL
11
+ * @param {string } username - The LDAP username for authentication
12
+ * @param {string } password - The password for LDAP authentication
13
+ * @param {string } base - The LDAP search base
14
+ * @param {string } filter - The LDAP search filter
15
+ * @param {string } scope - The LDAP search scope
16
+ * @param {string } tlsOptions - TLS options for LDAP connection
17
+ * @returns {void } This function doesn't return a value, it contains test cases
18
+ */
8
19
describe ( 'ldap:' , ( ) => {
9
20
const url = 'ldap%3A%2F%2Fldap.forumsys.com' ;
10
21
const username = 'cn=read-only-admin,dc=example,dc=com' ;
@@ -14,6 +25,16 @@ describe('ldap:', () => {
14
25
const scope = 'sub' ;
15
26
const tlsOptions = 'rejectUnauthorized%3Dtrue' ;
16
27
28
+ /**
29
+ * Tests the GET /search endpoint for bad request due to missing required query parameter
30
+ * @param {string } endpoint - The base URL of the API endpoint
31
+ * @param {string } username - The username for authentication
32
+ * @param {string } password - The password for authentication
33
+ * @param {string } base - The base parameter for the search query
34
+ * @param {string } filter - The filter parameter for the search query
35
+ * @param {string } scope - The scope parameter for the search query
36
+ * @returns {void } No return value, uses assertions to validate the response
37
+ */
17
38
it ( `GET ${ endpoint } /search - bad request / missing required query parameter - returns 400` , async ( ) => {
18
39
const res = await request ( {
19
40
method : 'GET' ,
@@ -24,6 +45,17 @@ describe('ldap:', () => {
24
45
expect ( res . result . error ) . to . equal ( '"url" is required' ) ;
25
46
} ) ;
26
47
48
+ /**
49
+ * Tests the GET /search endpoint with complete query parameters and correct parameter values
50
+ * @param {string } endpoint - The base endpoint for the API
51
+ * @param {string } url - The URL parameter for the search query
52
+ * @param {string } username - The username parameter for authentication
53
+ * @param {string } password - The password parameter for authentication
54
+ * @param {string } base - The base parameter for the search query
55
+ * @param {string } filter - The filter parameter for the search query
56
+ * @param {string } scope - The scope parameter for the search query
57
+ * @returns {void } This test case doesn't return a value, but asserts the response status code and result length
58
+ */
27
59
it ( `GET ${ endpoint } /search - complete query parameters and correct parameter values - returns 200` , async ( ) => {
28
60
const res = await request ( {
29
61
method : 'GET' ,
@@ -34,6 +66,16 @@ describe('ldap:', () => {
34
66
expect ( res . result . length > 0 ) . to . equal ( true ) ;
35
67
} ) ;
36
68
69
+ /**
70
+ * Tests the GET /search endpoint for unauthorized access with invalid user credentials
71
+ * @param {string } endpoint - The base API endpoint
72
+ * @param {string } url - The URL parameter for the search query
73
+ * @param {string } username - The username for authentication
74
+ * @param {string } base - The base parameter for the search query
75
+ * @param {string } filter - The filter parameter for the search query
76
+ * @param {string } scope - The scope parameter for the search query
77
+ * @returns {void } No return value, uses assertions to verify the response
78
+ */
37
79
it ( `GET ${ endpoint } /search - unauthorized / user/password invalid - returns 401` , async ( ) => {
38
80
const res = await request ( {
39
81
method : 'GET' ,
@@ -44,6 +86,17 @@ describe('ldap:', () => {
44
86
expect ( res . result . error ) . to . equal ( 'Invalid Credentials' ) ;
45
87
} ) ;
46
88
89
+ /**
90
+ * Tests the GET endpoint for searching a user that exists
91
+ * @param {string } endpoint - The base URL for the API endpoint
92
+ * @param {string } url - The LDAP server URL
93
+ * @param {string } username - The username for LDAP authentication
94
+ * @param {string } password - The password for LDAP authentication
95
+ * @param {string } base - The base DN for the LDAP search
96
+ * @param {string } scope - The search scope for the LDAP query
97
+ * @param {string } tlsOptions - TLS options for the LDAP connection
98
+ * @returns {void } This test doesn't return a value, it uses assertions to verify the response
99
+ */
47
100
it ( `GET ${ endpoint } /search - search for a user that does exist - returns 200` , async ( ) => {
48
101
const res = await request ( {
49
102
method : 'GET' ,
@@ -54,6 +107,17 @@ describe('ldap:', () => {
54
107
expect ( res . result . length ) . to . equal ( 1 ) ;
55
108
} ) ;
56
109
110
+ /**
111
+ * Tests the GET /search endpoint without a supplied raw parameter
112
+ * @param {string } endpoint - The base endpoint for the API
113
+ * @param {string } url - The URL parameter for the search query
114
+ * @param {string } username - The username for authentication
115
+ * @param {string } password - The password for authentication
116
+ * @param {string } base - The base parameter for the search query
117
+ * @param {string } filter - The filter parameter for the search query
118
+ * @param {string } scope - The scope parameter for the search query
119
+ * @returns {Object } The response object with status code and result
120
+ */
57
121
it ( `GET ${ endpoint } /search - search result without supplied raw parameter - returns 200` , async ( ) => {
58
122
const res = await request ( {
59
123
method : 'GET' ,
@@ -64,6 +128,16 @@ describe('ldap:', () => {
64
128
expect ( Object . keys ( res . result [ 0 ] ) . includes ( 'messageId' ) ) . to . equal ( false ) ;
65
129
} ) ;
66
130
131
+ /**
132
+ * Tests the GET /search endpoint with raw parameter set to false
133
+ * @param {string } endpoint - The base endpoint for the API
134
+ * @param {string } url - The LDAP server URL
135
+ * @param {string } username - The username for LDAP authentication
136
+ * @param {string } password - The password for LDAP authentication
137
+ * @param {string } base - The search base for LDAP
138
+ * @param {string } scope - The search scope for LDAP
139
+ * @returns {void } No return value, uses assertions to validate the response
140
+ */
67
141
it ( `GET ${ endpoint } /search - search result with supplied raw parameter value false - returns 200` , async ( ) => {
68
142
const res = await request ( {
69
143
method : 'GET' ,
@@ -74,11 +148,30 @@ describe('ldap:', () => {
74
148
const resultKeys = Object . keys ( res . result [ 0 ] ) ;
75
149
76
150
expect ( res . statusCode ) . to . equal ( 200 ) ;
151
+ `` `
152
+ /**
153
+ * Checks if all required keys are present in the result keys array
154
+ * @param {Array} requiredKeys - An array of keys that must be present
155
+ * @param {Array} resultKeys - An array of keys to check against
156
+ * @returns {boolean} True if all required keys are present, false otherwise
157
+ */
158
+ ` ``
77
159
expect ( requiredKeys . every ( ( key ) => resultKeys . includes ( key ) ) ) . to . equal (
78
160
true
79
161
) ;
80
162
} ) ;
81
163
164
+ /**
165
+ * Tests the GET search endpoint with raw parameter set to true
166
+ * @param {string } endpoint - The base endpoint for the API
167
+ * @param {string } url - The LDAP server URL
168
+ * @param {string } username - The username for LDAP authentication
169
+ * @param {string } password - The password for LDAP authentication
170
+ * @param {string } base - The search base for LDAP
171
+ * @param {string } filter - The LDAP search filter
172
+ * @param {string } scope - The search scope for LDAP
173
+ * @returns {void } Does not return a value, but expects a 200 status code and specific response structure
174
+ */
82
175
it ( `GET ${ endpoint } /search - search result with supplied raw parameter value true - returns 200` , async ( ) => {
83
176
const res = await request ( {
84
177
method : 'GET' ,
@@ -90,12 +183,29 @@ describe('ldap:', () => {
90
183
91
184
expect ( res . statusCode ) . to . equal ( 200 ) ;
92
185
expect (
186
+ /**
187
+ * Checks if all required keys are present in the result keys array
188
+ * @param {string[] } requiredKeys - Array of keys that must be present
189
+ * @param {string[] } resultKeys - Array of keys to check against
190
+ * @returns {boolean } True if all required keys are present, false otherwise
191
+ */
93
192
requiredKeys . every ( ( key ) => resultKeys . includes ( key ) ) &&
94
193
res . result [ 0 ] [ 'type' ] === 'SearchResultEntry' &&
95
194
Array . isArray ( res . result [ 0 ] [ 'attributes' ] )
96
195
) . to . equal ( true ) ;
97
196
} ) ;
98
197
198
+ /**
199
+ * Tests the GET /search endpoint with paged parameter set to true
200
+ * @param {string } endpoint - The base endpoint for the API
201
+ * @param {string } url - The URL parameter for the search query
202
+ * @param {string } username - The username for authentication
203
+ * @param {string } password - The password for authentication
204
+ * @param {string } base - The base parameter for the search query
205
+ * @param {string } filter - The filter parameter for the search query
206
+ * @param {string } scope - The scope parameter for the search query
207
+ * @returns {void } No return value
208
+ */
99
209
it ( `GET ${ endpoint } /search - search result with paged parameter value true - returns 200` , async ( ) => {
100
210
const res = await request ( {
101
211
method : 'GET' ,
0 commit comments