Skip to content

Commit d3ae029

Browse files
committed
Add README
1 parent 3dca666 commit d3ae029

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

README.md

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# k6 LDAP Extension
2+
3+
This is a [k6](https://k6.io) extension that enables LDAP operations within k6 test scripts. It provides a wrapper around the `ldap.v3` package, allowing you to perform LDAP operations such as binding, searching, adding, and deleting entries during load testing.
4+
5+
## Features
6+
7+
LDAP Operations
8+
- BIND
9+
- Search
10+
- Add entry
11+
- Delete entry
12+
13+
Utils
14+
- Escape search filter
15+
16+
### Not implemented (yet)
17+
- LDAP Modify
18+
19+
## Installation
20+
21+
To use this extension, you'll need to build k6 with the extension enabled. Follow these steps:
22+
23+
1. Clone this repository
24+
2. Build k6 with the extension using xk6:
25+
```bash
26+
xk6 build --with github.com/kressnick25/xk6-ldap
27+
```
28+
29+
## Usage
30+
31+
```javascript
32+
import ldap from 'k6/x/ldap';
33+
34+
export default function () {
35+
// Create LDAP connection
36+
// Note that if you do not want to create a connection per VU,
37+
// move this to the init context
38+
const conn = ldap.dialURL('ldap://your-ldap-server:389');
39+
40+
try {
41+
// Bind to LDAP server
42+
conn.bind('cn=admin,dc=example,dc=com', 'admin_password');
43+
44+
// Perform a search
45+
const searchRequest = ldap.newSearchRequest(
46+
'dc=example,dc=com', // Base DN
47+
'WholeSubtree', // Scope
48+
0, // Size Limit (0 for no limit)
49+
0, // Time Limit (0 for no limit)
50+
'(objectClass=person)', // Filter
51+
['cn', 'mail'] // Attributes to retrieve
52+
);
53+
54+
const result = conn.search(searchRequest);
55+
console.log(result.entries);
56+
} finally {
57+
// Always close the connection
58+
conn.close();
59+
}
60+
}
61+
```
62+
63+
See also `examples/example.js`
64+
65+
## API Reference
66+
67+
### Ldap
68+
69+
#### `dialURL(addr: string): Conn`
70+
Establishes a new connection to an LDAP server using the provided URL.
71+
72+
#### `escapeFilter(filter: string): string`
73+
Escapes special characters in LDAP filter strings.
74+
75+
#### `newAddRequest(dn: string): AddRequest`
76+
Creates a new request to add an entry to the LDAP directory.
77+
78+
#### `newDelRequest(dn: string): DelRequest`
79+
Creates a new request to delete an entry from the LDAP directory.
80+
81+
#### `newSearchRequest(baseDn: string, scope: "BaseObject" | "SingleLevel" | "WholeSubtree", sizeLimit: number, timeLimit: number, filter: string, attributes: string[]): SearchRequest`
82+
Creates a new search request with the specified parameters.
83+
84+
### Conn
85+
86+
#### `add(addRequest: AddRequest): void`
87+
Adds a new entry to the LDAP directory.
88+
89+
#### `del(delRequest: DelRequest): void`
90+
Deletes an entry from the LDAP directory.
91+
92+
#### `bind(username: string, password: string): void`
93+
Authenticates with the LDAP server.
94+
95+
#### `search(searchRequest: SearchRequest): SearchResult`
96+
Performs a search operation. Returns a SearchResult containing matched entries.
97+
98+
#### `close(): void`
99+
Closes the LDAP connection.
100+
101+
## Contributing
102+
103+
Contributions are welcome! Please feel free to submit a Pull Request.
104+
105+
## License
106+
107+
This project is open-source. Please ensure you check the license terms before using it.
108+
109+
## See Also
110+
111+
- [k6 Documentation](https://k6.io/docs/)
112+
- [LDAP v3 Package Documentation](https://pkg.go.dev/gopkg.in/ldap.v3)
113+

0 commit comments

Comments
 (0)