Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 4355893

Browse files
committed
Replace internal controls with @ldapjs/controls (#797)
* Replace internal controls with @ldapjs/controls * Replace EntryChangeNotificationControl * Replace PagedResultsControl * Replace ServerSideSortingRequestControl * Replace ServerSideSortingResponseControl * Replace VLV controls * Reduce coverage requirement * Fix dependency qualifier
1 parent 9bd8761 commit 4355893

21 files changed

+17
-1403
lines changed

.taprc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# These coverage percentages meet thresholds present in the code base
22
# as of 2022-03-27. As the code gets broken out into maintainable modules,
33
# these thresholds should increase until they are all at 100%.
4-
branches: 75
4+
branches: 70
55
functions: 80
66
lines: 85
77
statements: 85

lib/client/client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const VError = require('verror').VError
1818
const Attribute = require('../attribute')
1919
const Change = require('../change')
2020
const Control = require('../controls/index').Control
21+
const { Control: LdapControl } = require('@ldapjs/controls')
2122
const SearchPager = require('./search_pager')
2223
const Protocol = require('../protocol')
2324
const dn = require('../dn')
@@ -67,9 +68,9 @@ function nextClientId () {
6768
function validateControls (controls) {
6869
if (Array.isArray(controls)) {
6970
controls.forEach(function (c) {
70-
if (!(c instanceof Control)) { throw new TypeError('controls must be [Control]') }
71+
if (!(c instanceof Control) && !(c instanceof LdapControl)) { throw new TypeError('controls must be [Control]') }
7172
})
72-
} else if (controls instanceof Control) {
73+
} else if (controls instanceof Control || controls instanceof LdapControl) {
7374
controls = [controls]
7475
} else {
7576
throw new TypeError('controls must be [Control]')

lib/client/search_pager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const assert = require('assert-plus')
88
// var dn = require('../dn')
99
// var messages = require('../messages/index')
1010
// var Protocol = require('../protocol')
11-
const PagedControl = require('../controls/paged_results_control.js')
11+
const { PagedResultsControl } = require('@ldapjs/controls')
1212

1313
const CorkedEmitter = require('../corked_emitter.js')
1414

@@ -47,7 +47,7 @@ function SearchPager (opts) {
4747
this.sendRequest = opts.sendRequest
4848

4949
this.controls.forEach(function (control) {
50-
if (control.type === PagedControl.OID) {
50+
if (control.type === PagedResultsControl.OID) {
5151
// The point of using SearchPager is not having to do this.
5252
// Toss an error if the pagedResultsControl is present
5353
throw new Error('redundant pagedResultControl')
@@ -79,7 +79,7 @@ SearchPager.prototype._onEnd = function _onEnd (res) {
7979
const self = this
8080
let cookie = null
8181
res.controls.forEach(function (control) {
82-
if (control.type === PagedControl.OID) {
82+
if (control.type === PagedResultsControl.OID) {
8383
cookie = control.value.cookie
8484
}
8585
})
@@ -140,7 +140,7 @@ SearchPager.prototype._onError = function _onError (err) {
140140
*/
141141
SearchPager.prototype._nextPage = function _nextPage (cookie) {
142142
const controls = this.controls.slice(0)
143-
controls.push(new PagedControl({
143+
controls.push(new PagedResultsControl({
144144
value: {
145145
size: this.pageSize,
146146
cookie: cookie

lib/controls/control.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

lib/controls/entry_change_notification_control.js

Lines changed: 0 additions & 83 deletions
This file was deleted.

lib/controls/index.js

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,4 @@
11
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
22

3-
const assert = require('assert')
4-
const Ber = require('@ldapjs/asn1').Ber
5-
6-
const Control = require('./control')
7-
const EntryChangeNotificationControl =
8-
require('./entry_change_notification_control')
9-
const PersistentSearchControl = require('./persistent_search_control')
10-
const PagedResultsControl = require('./paged_results_control')
11-
const ServerSideSortingRequestControl =
12-
require('./server_side_sorting_request_control.js')
13-
const ServerSideSortingResponseControl =
14-
require('./server_side_sorting_response_control.js')
15-
const VirtualListViewRequestControl =
16-
require('./virtual_list_view_request_control.js')
17-
const VirtualListViewResponseControl =
18-
require('./virtual_list_view_response_control.js')
19-
20-
/// --- API
21-
22-
module.exports = {
23-
24-
getControl: function getControl (ber) {
25-
assert.ok(ber)
26-
27-
if (ber.readSequence() === null) { return null }
28-
29-
let type
30-
const opts = {
31-
criticality: false,
32-
value: null
33-
}
34-
35-
if (ber.length) {
36-
const end = ber.offset + ber.length
37-
38-
type = ber.readString()
39-
if (ber.offset < end) {
40-
if (ber.peek() === Ber.Boolean) { opts.criticality = ber.readBoolean() }
41-
}
42-
43-
if (ber.offset < end) { opts.value = ber.readString(Ber.OctetString, true) }
44-
}
45-
46-
let control
47-
switch (type) {
48-
case PersistentSearchControl.OID:
49-
control = new PersistentSearchControl(opts)
50-
break
51-
case EntryChangeNotificationControl.OID:
52-
control = new EntryChangeNotificationControl(opts)
53-
break
54-
case PagedResultsControl.OID:
55-
control = new PagedResultsControl(opts)
56-
break
57-
case ServerSideSortingRequestControl.OID:
58-
control = new ServerSideSortingRequestControl(opts)
59-
break
60-
case ServerSideSortingResponseControl.OID:
61-
control = new ServerSideSortingResponseControl(opts)
62-
break
63-
case VirtualListViewRequestControl.OID:
64-
control = new VirtualListViewRequestControl(opts)
65-
break
66-
case VirtualListViewResponseControl.OID:
67-
control = new VirtualListViewResponseControl(opts)
68-
break
69-
default:
70-
opts.type = type
71-
control = new Control(opts)
72-
break
73-
}
74-
75-
return control
76-
},
77-
78-
Control: Control,
79-
EntryChangeNotificationControl: EntryChangeNotificationControl,
80-
PagedResultsControl: PagedResultsControl,
81-
PersistentSearchControl: PersistentSearchControl,
82-
ServerSideSortingRequestControl: ServerSideSortingRequestControl,
83-
ServerSideSortingResponseControl: ServerSideSortingResponseControl,
84-
VirtualListViewRequestControl: VirtualListViewRequestControl,
85-
VirtualListViewResponseControl: VirtualListViewResponseControl
86-
}
3+
const controls = require('@ldapjs/controls')
4+
module.exports = controls

lib/controls/paged_results_control.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)