Skip to content

Commit de62f3d

Browse files
christian-roggiajohnweldon
authored andcommitted
Add Microsoft "Notification" and "Show Deleted" Controls (#175)
* Add Microsoft "Notification" and "Show Deleted" Controls * Add unittests and switch cases for Microsoft controls
1 parent 6c4b4ea commit de62f3d

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

control.go

+72-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ const (
1818
ControlTypeVChuPasswordWarning = "2.16.840.1.113730.3.4.5"
1919
// ControlTypeManageDsaIT - https://tools.ietf.org/html/rfc3296
2020
ControlTypeManageDsaIT = "2.16.840.1.113730.3.4.2"
21+
22+
// ControlTypeMicrosoftNotification - https://msdn.microsoft.com/en-us/library/aa366983(v=vs.85).aspx
23+
ControlTypeMicrosoftNotification = "1.2.840.113556.1.4.528"
24+
// ControlTypeMicrosoftShowDeleted - https://msdn.microsoft.com/en-us/library/aa366989(v=vs.85).aspx
25+
ControlTypeMicrosoftShowDeleted = "1.2.840.113556.1.4.417"
2126
)
2227

2328
// ControlTypeMap maps controls to text descriptions
2429
var ControlTypeMap = map[string]string{
25-
ControlTypePaging: "Paging",
26-
ControlTypeBeheraPasswordPolicy: "Password Policy - Behera Draft",
27-
ControlTypeManageDsaIT: "Manage DSA IT",
30+
ControlTypePaging: "Paging",
31+
ControlTypeBeheraPasswordPolicy: "Password Policy - Behera Draft",
32+
ControlTypeManageDsaIT: "Manage DSA IT",
33+
ControlTypeMicrosoftNotification: "Change Notification - Microsoft",
34+
ControlTypeMicrosoftShowDeleted: "Show Deleted Objects - Microsoft",
2835
}
2936

3037
// Control defines an interface controls provide to encode and describe themselves
@@ -238,6 +245,64 @@ func NewControlManageDsaIT(Criticality bool) *ControlManageDsaIT {
238245
return &ControlManageDsaIT{Criticality: Criticality}
239246
}
240247

248+
// ControlMicrosoftNotification implements the control described in https://msdn.microsoft.com/en-us/library/aa366983(v=vs.85).aspx
249+
type ControlMicrosoftNotification struct{}
250+
251+
// GetControlType returns the OID
252+
func (c *ControlMicrosoftNotification) GetControlType() string {
253+
return ControlTypeMicrosoftNotification
254+
}
255+
256+
// Encode returns the ber packet representation
257+
func (c *ControlMicrosoftNotification) Encode() *ber.Packet {
258+
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
259+
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftNotification, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftNotification]+")"))
260+
261+
return packet
262+
}
263+
264+
// String returns a human-readable description
265+
func (c *ControlMicrosoftNotification) String() string {
266+
return fmt.Sprintf(
267+
"Control Type: %s (%q)",
268+
ControlTypeMap[ControlTypeMicrosoftNotification],
269+
ControlTypeMicrosoftNotification)
270+
}
271+
272+
// NewControlMicrosoftNotification returns a ControlMicrosoftNotification control
273+
func NewControlMicrosoftNotification() *ControlMicrosoftNotification {
274+
return &ControlMicrosoftNotification{}
275+
}
276+
277+
// ControlMicrosoftShowDeleted implements the control described in https://msdn.microsoft.com/en-us/library/aa366989(v=vs.85).aspx
278+
type ControlMicrosoftShowDeleted struct{}
279+
280+
// GetControlType returns the OID
281+
func (c *ControlMicrosoftShowDeleted) GetControlType() string {
282+
return ControlTypeMicrosoftShowDeleted
283+
}
284+
285+
// Encode returns the ber packet representation
286+
func (c *ControlMicrosoftShowDeleted) Encode() *ber.Packet {
287+
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control")
288+
packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftShowDeleted, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftShowDeleted]+")"))
289+
290+
return packet
291+
}
292+
293+
// String returns a human-readable description
294+
func (c *ControlMicrosoftShowDeleted) String() string {
295+
return fmt.Sprintf(
296+
"Control Type: %s (%q)",
297+
ControlTypeMap[ControlTypeMicrosoftShowDeleted],
298+
ControlTypeMicrosoftShowDeleted)
299+
}
300+
301+
// NewControlMicrosoftShowDeleted returns a ControlMicrosoftShowDeleted control
302+
func NewControlMicrosoftShowDeleted() *ControlMicrosoftShowDeleted {
303+
return &ControlMicrosoftShowDeleted{}
304+
}
305+
241306
// FindControl returns the first control of the given type in the list, or nil
242307
func FindControl(controls []Control, controlType string) Control {
243308
for _, c := range controls {
@@ -385,6 +450,10 @@ func DecodeControl(packet *ber.Packet) (Control, error) {
385450
value.Value = c.Expire
386451

387452
return c, nil
453+
case ControlTypeMicrosoftNotification:
454+
return NewControlMicrosoftNotification(), nil
455+
case ControlTypeMicrosoftShowDeleted:
456+
return NewControlMicrosoftShowDeleted(), nil
388457
default:
389458
c := new(ControlString)
390459
c.ControlType = ControlType

control_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ func TestControlManageDsaIT(t *testing.T) {
2020
runControlTest(t, NewControlManageDsaIT(false))
2121
}
2222

23+
func TestControlMicrosoftNotification(t *testing.T) {
24+
runControlTest(t, NewControlMicrosoftNotification())
25+
}
26+
27+
func TestControlMicrosoftShowDeleted(t *testing.T) {
28+
runControlTest(t, NewControlMicrosoftShowDeleted())
29+
}
30+
2331
func TestControlString(t *testing.T) {
2432
runControlTest(t, NewControlString("x", true, "y"))
2533
runControlTest(t, NewControlString("x", true, ""))
@@ -77,6 +85,14 @@ func TestDescribeControlPaging(t *testing.T) {
7785
runAddControlDescriptions(t, NewControlPaging(0), "Control Type (Paging)", "Control Value (Paging)")
7886
}
7987

88+
func TestDescribeControlMicrosoftNotification(t *testing.T) {
89+
runAddControlDescriptions(t, NewControlMicrosoftNotification(), "Control Type (Change Notification - Microsoft)")
90+
}
91+
92+
func TestDescribeControlMicrosoftShowDeleted(t *testing.T) {
93+
runAddControlDescriptions(t, NewControlMicrosoftShowDeleted(), "Control Type (Show Deleted Objects - Microsoft)")
94+
}
95+
8096
func TestDescribeControlString(t *testing.T) {
8197
runAddControlDescriptions(t, NewControlString("x", true, "y"), "Control Type ()", "Criticality", "Control Value")
8298
runAddControlDescriptions(t, NewControlString("x", true, ""), "Control Type ()", "Criticality", "Control Value")

0 commit comments

Comments
 (0)