1
- import type { Server } from 'ldapjs' ;
1
+ import type { SearchRequest , Server , SearchResponse , CompareRequest , CompareResponse , BindResponse , BindRequest } from 'ldapjs' ;
2
2
import type { Operation } from 'effection' ;
3
3
import { createServer , InvalidCredentialsError , NoSuchObjectError , OperationsError } from 'ldapjs' ;
4
- import type { LDAPOptions } from './types' ;
4
+ import type { LDAPOptions , LDAPStoreOptions , Port , UserData } from './types' ;
5
5
import type { SimulationState , Simulator } from '@simulacrum/server' ;
6
6
import type { ResourceServiceCreator } from '@simulacrum/server' ;
7
7
import dedent from 'dedent' ;
@@ -14,18 +14,8 @@ const DefaultOptions: Partial<LDAPOptions> = {
14
14
port : 389
15
15
} ;
16
16
17
- interface UserData {
18
- uuid : string ;
19
- cn : string ;
20
- password : string ;
21
- }
22
-
23
- export interface LDAPStoreOptions < T extends UserData > {
24
- users : Iterable < T > ;
25
- }
26
-
27
- export interface Port {
28
- port : number ;
17
+ export interface NextFunction {
18
+ < E > ( err ?: E ) : void ;
29
19
}
30
20
31
21
export function createLDAPServer < T extends UserData > ( options : LDAPOptions & LDAPStoreOptions < T > ) : Operation < Server & Port > {
@@ -54,23 +44,21 @@ export function createLDAPServer<T extends UserData>(options: LDAPOptions & LDAP
54
44
55
45
let server = createServer ( { log : silence } ) ;
56
46
57
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
- server . search ( "" , function ( req : any , res : any , next : any ) {
47
+ server . search ( "" , function ( req : SearchRequest , res : SearchResponse , next : NextFunction ) {
59
48
logger . log ( dedent `--- Root DSE ---
60
- scope: ${ req . scope }
61
- ` ) ;
49
+ scope: ${ req . scope }
50
+ `) ;
62
51
res . send ( {
63
- "dn" : "" ,
64
- " attributes" : {
52
+ dn : "" ,
53
+ attributes : {
65
54
"vendorName" : "Frontside, Inc."
66
55
} ,
67
56
} ) ;
68
57
res . end ( ) ;
69
58
return next ( ) ;
70
59
} ) ;
71
60
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- server . search ( baseDN , function ( req : any , res : any , next : any ) {
61
+ server . search ( baseDN , function ( req : SearchRequest , res : SearchResponse , next : NextFunction ) {
74
62
logger . log ( dedent `--- User Search ---
75
63
dn: ${ req . dn . toString ( ) }
76
64
scope: ${ req . scope }
@@ -106,18 +94,16 @@ filter: ${req.filter.toString()}
106
94
return next ( ) ;
107
95
} ) ;
108
96
109
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
- server . compare ( groupDN , ( req : any , res : any ) => {
97
+ server . compare ( groupDN , ( req : CompareRequest , res : CompareResponse ) => {
111
98
logger . log ( '--- Compare ---' ) ;
112
99
logger . log ( `DN: ${ req . dn . toString ( ) } ` ) ;
113
100
logger . log ( `attribute name: ${ req . attribute } ` ) ;
114
101
logger . log ( `attribute value: ${ req . value } ` ) ;
115
102
116
- res . end ( true ) ;
103
+ res . end ( 0 ) ;
117
104
} ) ;
118
105
119
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- server . bind ( baseDN , function ( req : any , res : any , next : any ) {
106
+ server . bind ( baseDN , function ( req : BindRequest , res : BindResponse , next : NextFunction ) {
121
107
logger . log ( '--- Bind ---' ) ;
122
108
logger . log ( `bind DN: ${ req . dn . toString ( ) } ` ) ;
123
109
logger . log ( `bind PW: ${ req . credentials } ` ) ;
0 commit comments