@@ -119,5 +119,55 @@ func runAddControlDescriptions(t *testing.T, originalControl Control, childDescr
119119 t .Errorf ("%sdescription not as expected: %s != %s" , header , encodedPacket .Children [i ].Description , desc )
120120 }
121121 }
122+ }
123+
124+ func TestDecodeControl (t * testing.T ) {
125+ type args struct {
126+ packet * ber.Packet
127+ }
122128
129+ tests := []struct {
130+ name string
131+ args args
132+ want Control
133+ wantErr bool
134+ }{
135+ {name : "timeBeforeExpiration" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x29 , 0x30 , 0x27 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0xa , 0x30 , 0x8 , 0xa0 , 0x6 , 0x80 , 0x4 , 0x7f , 0xff , 0xf6 , 0x5c })},
136+ want : & ControlBeheraPasswordPolicy {Expire : 2147481180 , Grace : - 1 , Error : - 1 , ErrorString : "" }, wantErr : false },
137+ {name : "graceAuthNsRemaining" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x26 , 0x30 , 0x24 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x7 , 0x30 , 0x5 , 0xa0 , 0x3 , 0x81 , 0x1 , 0x11 })},
138+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : 17 , Error : - 1 , ErrorString : "" }, wantErr : false },
139+ {name : "passwordExpired" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x0 })},
140+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 0 , ErrorString : "Password expired" }, wantErr : false },
141+ {name : "accountLocked" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x1 })},
142+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 1 , ErrorString : "Account locked" }, wantErr : false },
143+ {name : "passwordModNotAllowed" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x3 })},
144+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 3 , ErrorString : "Policy prevents password modification" }, wantErr : false },
145+ {name : "mustSupplyOldPassword" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x4 })},
146+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 4 , ErrorString : "Policy requires old password in order to change password" }, wantErr : false },
147+ {name : "insufficientPasswordQuality" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x5 })},
148+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 5 , ErrorString : "Password fails quality checks" }, wantErr : false },
149+ {name : "passwordTooShort" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x6 })},
150+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 6 , ErrorString : "Password is too short for policy" }, wantErr : false },
151+ {name : "passwordTooYoung" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x7 })},
152+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 7 , ErrorString : "Password has been changed too recently" }, wantErr : false },
153+ {name : "passwordInHistory" , args : args {packet : ber .DecodePacket ([]byte {0xa0 , 0x24 , 0x30 , 0x22 , 0x4 , 0x19 , 0x31 , 0x2e , 0x33 , 0x2e , 0x36 , 0x2e , 0x31 , 0x2e , 0x34 , 0x2e , 0x31 , 0x2e , 0x34 , 0x32 , 0x2e , 0x32 , 0x2e , 0x32 , 0x37 , 0x2e , 0x38 , 0x2e , 0x35 , 0x2e , 0x31 , 0x4 , 0x5 , 0x30 , 0x3 , 0x81 , 0x1 , 0x8 })},
154+ want : & ControlBeheraPasswordPolicy {Expire : - 1 , Grace : - 1 , Error : 8 , ErrorString : "New password is in list of old passwords" }, wantErr : false },
155+ }
156+ for i := range tests {
157+ addControlDescriptions (tests [i ].args .packet )
158+ tests [i ].args .packet = tests [i ].args .packet .Children [0 ]
159+ }
160+
161+ for _ , tt := range tests {
162+ t .Run (tt .name , func (t * testing.T ) {
163+ got , err := DecodeControl (tt .args .packet )
164+ if (err != nil ) != tt .wantErr {
165+ t .Errorf ("DecodeControl() error = %v, wantErr %v" , err , tt .wantErr )
166+ return
167+ }
168+ if ! reflect .DeepEqual (got , tt .want ) {
169+ t .Errorf ("DecodeControl() got = %v, want %v" , got , tt .want )
170+ }
171+ })
172+ }
123173}
0 commit comments