Skip to content

Commit 626c1d8

Browse files
author
patched.codes[bot]
committed
Patched /tmp/tmpptoa8sbv/test/ldap/v1/test.js
1 parent d791484 commit 626c1d8

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

test/ldap/v1/test.js

+110
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import { sep } from 'path';
55
const version = __dirname.split(sep).reverse()[0];
66
const endpoint = `${version}/ldap`;
77

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+
*/
819
describe('ldap:', () => {
920
const url = 'ldap%3A%2F%2Fldap.forumsys.com';
1021
const username = 'cn=read-only-admin,dc=example,dc=com';
@@ -14,6 +25,16 @@ describe('ldap:', () => {
1425
const scope = 'sub';
1526
const tlsOptions = 'rejectUnauthorized%3Dtrue';
1627

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+
*/
1738
it(`GET ${endpoint}/search - bad request / missing required query parameter - returns 400`, async () => {
1839
const res = await request({
1940
method: 'GET',
@@ -24,6 +45,17 @@ describe('ldap:', () => {
2445
expect(res.result.error).to.equal('"url" is required');
2546
});
2647

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+
*/
2759
it(`GET ${endpoint}/search - complete query parameters and correct parameter values - returns 200`, async () => {
2860
const res = await request({
2961
method: 'GET',
@@ -34,6 +66,16 @@ describe('ldap:', () => {
3466
expect(res.result.length > 0).to.equal(true);
3567
});
3668

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+
*/
3779
it(`GET ${endpoint}/search - unauthorized / user/password invalid - returns 401`, async () => {
3880
const res = await request({
3981
method: 'GET',
@@ -44,6 +86,17 @@ describe('ldap:', () => {
4486
expect(res.result.error).to.equal('Invalid Credentials');
4587
});
4688

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+
*/
47100
it(`GET ${endpoint}/search - search for a user that does exist - returns 200`, async () => {
48101
const res = await request({
49102
method: 'GET',
@@ -54,6 +107,17 @@ describe('ldap:', () => {
54107
expect(res.result.length).to.equal(1);
55108
});
56109

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+
*/
57121
it(`GET ${endpoint}/search - search result without supplied raw parameter - returns 200`, async () => {
58122
const res = await request({
59123
method: 'GET',
@@ -64,6 +128,16 @@ describe('ldap:', () => {
64128
expect(Object.keys(res.result[0]).includes('messageId')).to.equal(false);
65129
});
66130

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+
*/
67141
it(`GET ${endpoint}/search - search result with supplied raw parameter value false - returns 200`, async () => {
68142
const res = await request({
69143
method: 'GET',
@@ -74,11 +148,30 @@ describe('ldap:', () => {
74148
const resultKeys = Object.keys(res.result[0]);
75149

76150
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+
```
77159
expect(requiredKeys.every((key) => resultKeys.includes(key))).to.equal(
78160
true
79161
);
80162
});
81163

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+
*/
82175
it(`GET ${endpoint}/search - search result with supplied raw parameter value true - returns 200`, async () => {
83176
const res = await request({
84177
method: 'GET',
@@ -90,12 +183,29 @@ describe('ldap:', () => {
90183

91184
expect(res.statusCode).to.equal(200);
92185
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+
*/
93192
requiredKeys.every((key) => resultKeys.includes(key)) &&
94193
res.result[0]['type'] === 'SearchResultEntry' &&
95194
Array.isArray(res.result[0]['attributes'])
96195
).to.equal(true);
97196
});
98197

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+
*/
99209
it(`GET ${endpoint}/search - search result with paged parameter value true - returns 200`, async () => {
100210
const res = await request({
101211
method: 'GET',

0 commit comments

Comments
 (0)