This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema_test.go
3241 lines (3161 loc) · 108 KB
/
schema_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package schemax
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
//"runtime/pprof"
"testing"
"github.com/JesseCoretta/go-antlr4512"
)
var mySchema Schema
// For release testing only
//func TestNewSchema(t *testing.T) {
// f, err := os.Create("cpu.prof")
// if err != nil {
// t.Fatal(err)
// }
// defer f.Close()
//
// pprof.StartCPUProfile(f)
// defer pprof.StopCPUProfile()
//
// mySchema := NewSchema()
// fmt.Printf("%d types parsed", mySchema.Counters().AT)
// // Output: 214 types parsed
//}
/*
This example demonstrates the so-called "Quick Start Schema" initialization.
The [NewSchema] function imports all built-in definitions instantly, allowing
the user to start their activities with no fuss.
*/
func ExampleNewBasicSchema() {
mySchema := NewBasicSchema()
fmt.Printf("%d syntaxes parsed", mySchema.Counters().LS)
// Output: 67 syntaxes parsed
}
func ExampleSchema_Options() {
opts := mySchema.Options()
opts.Shift(AllowOverride)
fmt.Println(opts.Positive(AllowOverride))
// Output: true
}
/*
This example demonstrates a convenient means of adding any [Definition]
qualifier, such as an [ObjectClass] instance, to the schema. This is
useful when manual type verification is cumbersome.
*/
func ExampleSchema_Push() {
def := mySchema.NewObjectClass()
def.SetNumericOID(`1.3.6.1.4.1.56521.999.1232`)
def.SetKind(AuxiliaryKind)
def.SetName(`exampleClass`)
mySchema.Push(def)
get := mySchema.ObjectClasses().Get(`exampleClass`)
fmt.Printf("%s\n", get.OID())
// Output: exampleClass
}
func ExampleSchema_Exists() {
var def Definition = mySchema.LDAPSyntaxes().Get(`integer`)
fmt.Println(mySchema.Exists(def))
// Output: true
}
func ExampleSchema_Replace_objectClass() {
gon := mySchema.ObjectClasses().Get(`groupOfNames`)
ngon := mySchema.NewObjectClass().
SetNumericOID(gon.NumericOID()).
SetName(gon.Name()).
SetDescription(gon.Description()).
SetKind(gon.Kind()).
SetSuperClass(`top`).
SetMust(`cn`).
SetMay(`member`,
`businessCategory`,
`seeAlso`,
`owner`,
`ou`,
`o`,
`description`).
SetExtension(`X-ORIGIN`, `RFC4519`).
SetExtension(`X-WARNING`, `MODIFIED`). // optional
SetStringer()
mySchema.Options().Unshift(AllowOverride)
mySchema.Replace(ngon)
mySchema.Options().Shift(AllowOverride)
mySchema.Replace(ngon)
fmt.Println(mySchema.ObjectClasses().Get(`groupOfNames`))
// Output: ( 2.5.6.9
// NAME 'groupOfNames'
// SUP top
// STRUCTURAL
// MUST cn
// MAY ( member
// $ businessCategory
// $ seeAlso
// $ owner
// $ ou
// $ o
// $ description )
// X-ORIGIN 'RFC4519'
// X-WARNING 'MODIFIED' )
}
/*
This example demonstrates refreshing the [MatchingRuleUses] collection
within the receiver instance of [Schema]. The result of this operation
is influence by any new [AttributeType] instances that have been added
since the last refresh.
*/
func ExampleSchema_UpdateMatchingRuleUses() {
mySchema.UpdateMatchingRuleUses()
fmt.Printf("%d matchingRuleUses present", mySchema.Counters().MU)
// Output: 32 matchingRuleUses present
}
/*
This example demonstrates obtaining a non thread-safe [Counters] instance,
which outlines the number of [Definition] instances in categorical fashion.
*/
func ExampleSchema_Counters() {
fmt.Printf("%d types present", mySchema.Counters().AT)
// Output: 319 types present
}
/*
This example demonstrates accessing the [Schema] instance's distinguished
name, if set.
*/
func ExampleSchema_DN() {
fmt.Println(mySchema.DN())
// Output: cn=schema
}
/*
This example demonstrates specifying a non-standard distinguished name
for use by the [Schema] instance.
*/
func ExampleSchema_SetDN() {
mySchema := NewEmptySchema()
mySchema.SetDN(`cn=subschema`)
fmt.Println(mySchema.DN())
// Output: cn=subschema
}
func TestLoadSyntaxes(t *testing.T) {
want := 67
if got := mySchema.LDAPSyntaxes().Len(); got != want {
t.Errorf("%s failed: want '%d' ldapSyntaxes, got '%d'",
t.Name(), want, got)
return
}
}
func TestLoadMatchingRules(t *testing.T) {
want := 44
if got := mySchema.MatchingRules().Len(); got != want {
t.Errorf("%s failed: want '%d' matchingRules, got '%d'",
t.Name(), want, got)
return
}
}
func TestLoadAttributeTypes(t *testing.T) {
want := 317 // includes supplementals and dcodSchema
if got := mySchema.AttributeTypes().Len(); got != want {
t.Errorf("%s failed: want '%d' attributeTypes, got '%d'",
t.Name(), want, got)
return
}
}
func TestLoadObjectClasses(t *testing.T) {
want := 80
if got := mySchema.ObjectClasses().Len(); got != want {
t.Errorf("%s failed: want '%d' objectClasses, got '%d'",
t.Name(), want, got)
return
}
}
func TestSchema_codecov(t *testing.T) {
// hopelessly try to overwrite each definition
// with itself. This is only necessary for
// coverage reasons related to the Schema type;
// actual replacements are already covered.
for _, def := range []Definition{
mySchema.LDAPSyntaxes().Index(0),
mySchema.MatchingRules().Index(0),
mySchema.AttributeTypes().Index(0),
mySchema.MatchingRuleUses().Index(0),
mySchema.ObjectClasses().Index(0),
mySchema.DITContentRules().Index(0),
mySchema.NameForms().Index(0),
mySchema.DITStructureRules().Index(0),
} {
mySchema.Replace(def)
mySchema.Exists(def)
}
mySchema.Replace(LDAPSyntax{})
mySchema.Replace(ObjectClass{})
mySchema.Replace(DITStructureRule{})
mySchema.Replace(DITContentRule{})
mySchema.Replace(NameForm{})
mySchema.Replace(AttributeType{})
mySchema.Replace(MatchingRule{})
mySchema.Replace(MatchingRuleUse{})
_ = mySchema.ParseDirectory(`_fnfjnds`)
_, _ = mySchema.marshalOC(antlr4512.ObjectClass{Name: []string{`uiw`}})
_, _ = mySchema.marshalDC(antlr4512.DITContentRule{Name: []string{`uiw`}})
_, _ = mySchema.marshalAT(antlr4512.AttributeType{Name: []string{`uiw`}})
_, _ = mySchema.marshalMR(antlr4512.MatchingRule{Name: []string{`uiw`}})
_, _ = mySchema.marshalMU(antlr4512.MatchingRuleUse{Name: []string{`uiw`}})
_, _ = mySchema.marshalNF(antlr4512.NameForm{Name: []string{`uiw`}})
_, _ = mySchema.marshalLS(antlr4512.LDAPSyntax{Desc: `descriptive text`})
_, _ = mySchema.marshalOC(antlr4512.ObjectClass{OID: `2.5.6.11`, Name: []string{`uiw`}})
_, _ = mySchema.marshalAT(antlr4512.AttributeType{OID: `2.5.6.11`, Name: []string{`uiw`}})
_, _ = mySchema.marshalDC(antlr4512.DITContentRule{OID: `2.5.6.11`, Name: []string{`uiw`}})
_, _ = mySchema.marshalNF(antlr4512.NameForm{OID: `2.5.6.11`, Name: []string{`uiw`}})
_, _ = mySchema.marshalAT(antlr4512.AttributeType{OID: `2.5.6.100011`, Name: []string{`uiw`}})
_, _ = mySchema.marshalMR(antlr4512.MatchingRule{OID: `2.5.6.100011`, Name: []string{`uiw`}})
_, _ = mySchema.marshalMU(antlr4512.MatchingRuleUse{OID: `2.5.6.100011`, Name: []string{`uiw`}})
_, _ = mySchema.marshalDC(antlr4512.DITContentRule{OID: `2.5.6.100011`, Name: []string{`uiw`}})
_, _ = mySchema.marshalOC(antlr4512.ObjectClass{OID: `2.5.6.100011`, Name: []string{`uiw`}})
_, _ = mySchema.marshalMR(antlr4512.MatchingRule{OID: `2.5.6.100011`, Name: []string{`uiw`}})
_, _ = mySchema.marshalMU(antlr4512.MatchingRuleUse{OID: `2.5.6.100011`, Name: []string{`uiw`}})
_, _ = mySchema.marshalMR(antlr4512.MatchingRule{OID: `INTEGERT`, Name: []string{`uiw`}})
_, _ = mySchema.marshalMR(antlr4512.MatchingRule{
OID: `1.3.4.5.6`,
Syntax: `'INTEGER'`,
Name: []string{`uiw`},
})
_, _ = mySchema.marshalMU(antlr4512.MatchingRuleUse{OID: `INTEGERT`, Name: []string{`uiw`}})
//var err error
_ = mySchema.incorporateLS(antlr4512.LDAPSyntaxes{antlr4512.LDAPSyntax{
OID: `1.3.6.1.4.1.1466.115.121.1.52`,
Desc: `uiw`,
}})
_ = mySchema.incorporateDS(antlr4512.DITStructureRules{antlr4512.DITStructureRule{
ID: `-7`,
Form: `badForm`,
}})
_ = mySchema.incorporateDS(antlr4512.DITStructureRules{antlr4512.DITStructureRule{
ID: `7`,
Form: `badForm`,
}})
_ = mySchema.incorporateDS(antlr4512.DITStructureRules{antlr4512.DITStructureRule{
ID: `7`,
Form: `nArcForm`,
SuperRules: []string{`111`, `88`},
}})
_ = mySchema.incorporateNF(antlr4512.NameForms{antlr4512.NameForm{
OID: `1.2.3.4.54.65`,
OC: `2.5.6.11`,
Must: []string{`h`},
}})
_ = mySchema.incorporateNF(antlr4512.NameForms{antlr4512.NameForm{
OID: `1.2.3.4.54.65`,
OC: `2.5.6.11`,
Must: []string{`c`},
May: []string{`h`},
}})
_ = mySchema.incorporateDS(antlr4512.DITStructureRules{antlr4512.DITStructureRule{
ID: `7`,
SuperRules: []string{`100`, `11`},
}})
_ = mySchema.incorporateAT(antlr4512.AttributeTypes{antlr4512.AttributeType{
OID: `2.5.4.3`,
Name: []string{`uiw`},
}})
_ = mySchema.incorporateAT(antlr4512.AttributeTypes{antlr4512.AttributeType{
OID: `2.5.4.1999`,
Name: []string{`uiw`},
Syntax: `1.3.6.1.4.1.56521.999.72.1`,
}})
_ = mySchema.incorporateAT(antlr4512.AttributeTypes{antlr4512.AttributeType{
OID: `2.5.4.1999`,
Name: []string{`uiw`},
Equality: `1.3.6.1.4.1.56521.999.72.1`,
}})
_ = mySchema.incorporateAT(antlr4512.AttributeTypes{antlr4512.AttributeType{
OID: `2.5.4.1999`,
Name: []string{`uiw`},
SuperType: `blarg`,
}})
_ = mySchema.incorporateOC(antlr4512.ObjectClasses{antlr4512.ObjectClass{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`, ``},
}})
_ = mySchema.incorporateMR(antlr4512.MatchingRules{antlr4512.MatchingRule{
OID: ``,
Macro: []string{`nisSchema`, `1.3.6.1.1.1.999`},
Name: []string{`uiw`},
Syntax: `1.3.6.1.4.1.56521.999.72.1`,
}})
_ = mySchema.incorporateMR(antlr4512.MatchingRules{antlr4512.MatchingRule{
///OID: `2.5.6.11`,
Name: []string{`uiw`},
Syntax: `INTEGER`,
}})
_ = mySchema.incorporateMR(antlr4512.MatchingRules{antlr4512.MatchingRule{
//OID: `1.3.6.1.4.1.1466.109.114.1`,
//Macro: []string{`nisSchema`,`1`},
Name: []string{`uiw`},
Syntax: `1.3.6.1.4.1.1466.115.121.1.11`,
}})
_ = mySchema.incorporateMR(antlr4512.MatchingRules{antlr4512.MatchingRule{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Syntax: `NTEGEF`,
}})
_ = mySchema.incorporateMU(antlr4512.MatchingRuleUses{antlr4512.MatchingRuleUse{
OID: `2.5.13.13`,
Name: []string{`uiw`},
Applies: []string{`cn`, `dfjskalf`},
}})
_ = mySchema.incorporateMU(antlr4512.MatchingRuleUses{antlr4512.MatchingRuleUse{
OID: `2.5.13.13`,
Name: []string{`uiw`},
Applies: []string{`cn`},
Extensions: map[string][]string{
`X-ORIGIN`: {`NOWHERE`},
},
}})
_ = mySchema.incorporateOC(antlr4512.ObjectClasses{antlr4512.ObjectClass{
OID: `2.5.6.11`,
Name: []string{`uiw`},
May: []string{`cn`, ``},
}})
_ = mySchema.incorporateOC(antlr4512.ObjectClasses{antlr4512.ObjectClass{
OID: `2.5.6.11`,
Name: []string{`uiw`},
SuperClasses: []string{`p`, `account`},
}})
_ = mySchema.incorporateOC(antlr4512.ObjectClasses{antlr4512.ObjectClass{
OID: `2.5.6.1111111`,
Name: []string{`uiw`},
SuperClasses: []string{`account`},
Kind: `JUNK`,
}})
_ = mySchema.incorporateOC(antlr4512.ObjectClasses{antlr4512.ObjectClass{
OID: `2.5.6.1111111`,
Name: []string{`uiw`},
SuperClasses: []string{`account`},
Must: []string{`xx`},
}})
_ = mySchema.incorporateOC(antlr4512.ObjectClasses{antlr4512.ObjectClass{
OID: `2.5.6.1111111`,
Name: []string{`uiw`},
SuperClasses: []string{`account`},
Must: []string{`cn`},
May: []string{`xx`},
}})
_ = mySchema.incorporateNF(antlr4512.NameForms{antlr4512.NameForm{
OID: `2.5.6.1111111`,
Name: []string{`uiw`},
Must: []string{`xx`},
}})
_ = mySchema.incorporateNF(antlr4512.NameForms{antlr4512.NameForm{
OID: `2.5.6.1111111`,
Name: []string{`uiw`},
Must: []string{`cn`},
May: []string{`xx`},
}})
_ = mySchema.incorporateNF(antlr4512.NameForms{antlr4512.NameForm{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`, ``},
}})
_ = mySchema.incorporateNF(antlr4512.NameForms{antlr4512.NameForm{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`},
May: []string{``},
}})
_ = mySchema.incorporateNF(antlr4512.NameForms{antlr4512.NameForm{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`},
May: []string{`_l`},
}})
_ = mySchema.incorporateDC(antlr4512.DITContentRules{antlr4512.DITContentRule{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`, ``},
}})
_ = mySchema.incorporateDC(antlr4512.DITContentRules{antlr4512.DITContentRule{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`},
May: []string{``},
}})
_ = mySchema.incorporateDC(antlr4512.DITContentRules{antlr4512.DITContentRule{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`},
May: []string{`l`},
Not: []string{``},
}})
_ = mySchema.incorporateDC(antlr4512.DITContentRules{antlr4512.DITContentRule{
OID: `2.5.6.11`,
Name: []string{`uiw`},
Must: []string{`cn`},
May: []string{`l`},
Not: []string{`drink`},
Aux: []string{``},
}})
_ = mySchema.ParseNameForm(mySchema.NameForms().Index(0).String())
_ = mySchema.ParseDITStructureRule(mySchema.DITStructureRules().Index(0).String())
_ = mySchema.ParseDITContentRule(mySchema.DITContentRules().Index(0).String())
_ = mySchema.ParseMatchingRuleUse(mySchema.MatchingRuleUses().Index(0).String())
_a := &attributeType{}
_aa := antlr4512.AttributeType{
Usage: `distributedOperation`,
}
_a.marshalUsage(_aa)
}
/*
this test generates a temporary dir/file and uses its newly written contents
to parse into our schema. It is not practical to make true Examples for these
methods :(
*/
func TestSchema_ParseFileAndDirectory(t *testing.T) {
// Create a temp file
tempDir, err := ioutil.TempDir("", "test")
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
}
defer os.RemoveAll(tempDir)
fileName := `test.schema`
tempFile := filepath.Join(tempDir, fileName)
text := []byte("attributeType ( 1.3.6.1.4.1.56521.999.87.1 NAME 'fakeAttribute' )")
if err = ioutil.WriteFile(tempFile, text, 0644); err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
}
if err = mySchema.ParseFile(tempFile); err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
}
if err = mySchema.ParseDirectory(tempDir); err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
}
// We generate a fake (non-existent) file/dir name rather
// than hard-coding something bogus that could be abused...
bogusName := randString(8)
_ = mySchema.ParseFile(bogusName + `.schema`)
_ = mySchema.ParseDirectory(bogusName)
}
func TestLoads_codecov(t *testing.T) {
coolSchema := NewEmptySchema()
coolSchema.LoadRFC4517Syntaxes()
coolSchema.LoadRFC2307Syntaxes()
coolSchema.LoadRFC4523Syntaxes()
coolSchema.LoadRFC4530Syntaxes()
coolSchema.LoadRFC4517MatchingRules()
coolSchema.LoadRFC2307MatchingRules()
coolSchema.LoadRFC4523MatchingRules()
coolSchema.LoadRFC4530MatchingRules()
coolSchema.LoadX501AttributeTypes()
coolSchema.LoadRFC4512AttributeTypes()
coolSchema.LoadRFC2079AttributeTypes()
coolSchema.LoadRFC2589AttributeTypes()
coolSchema.LoadRFC2798AttributeTypes()
coolSchema.LoadRFC3045AttributeTypes()
coolSchema.LoadRFC3672AttributeTypes()
coolSchema.LoadRFC4519AttributeTypes()
coolSchema.LoadRFC2307AttributeTypes()
coolSchema.LoadRFC3671AttributeTypes()
coolSchema.LoadRFC4403AttributeTypes()
coolSchema.LoadRFC4523AttributeTypes()
coolSchema.LoadRFC4524AttributeTypes()
coolSchema.LoadRFC4530AttributeTypes()
coolSchema.LoadRFC5020AttributeTypes()
coolSchema.LoadRFC4512ObjectClasses()
coolSchema.LoadRFC2079ObjectClasses()
coolSchema.LoadRFC2589ObjectClasses()
coolSchema.LoadRFC2798ObjectClasses()
coolSchema.LoadRFC2307ObjectClasses()
coolSchema.LoadRFC4512ObjectClasses()
coolSchema.LoadRFC3671ObjectClasses()
coolSchema.LoadRFC3672ObjectClasses()
coolSchema.LoadRFC4403ObjectClasses()
coolSchema.LoadRFC4519ObjectClasses()
coolSchema.LoadRFC4523ObjectClasses()
coolSchema.LoadRFC4524ObjectClasses()
coolSchema.LoadRFC2377NameForms()
coolSchema.LoadRFC4403NameForms()
coolSchema.LoadRFC4403DITStructureRules()
}
// supplemental attributeTypes not sourced from an official doc, but
// are useful in UTs, et al.
//
// Currently empty.
var suplATs []string = []string{}
func init() {
// Prepare our UT/Example reference schema
mySchema = NewEmptySchema(
AllowOverride,
SortExtensions,
SortLists,
HangingIndents,
AllowReindexedStructureRules,
)
funks := []func() error{
mySchema.LoadLDAPSyntaxes, // import all built-in Syntaxes
mySchema.LoadMatchingRules, // import all built-in Matching Rules
mySchema.LoadAttributeTypes, // import all built-in Attribute Types
mySchema.LoadObjectClasses, // import all built-in Object Classes
mySchema.LoadNameForms, // import all built-in Name Forms
mySchema.LoadDITStructureRules, // import all built-in DIT Structure Rules
}
var err error
for i := 0; i < len(funks) && err == nil; i++ {
if err = funks[i](); err != nil {
fmt.Printf("I:%d\n", i)
panic(err)
}
}
// load some supplemental attributeTypes used for special cases
for _, at := range suplATs {
if err := mySchema.ParseAttributeType(at); err != nil {
panic(err)
}
}
// load dcodSchema for more meaningful examples of certain
// lesser-used definition types. This is not a built-in, as
// it is an unapproved I-D used here strictly for robust UTs.
if err := mySchema.ParseRaw(dcodSchema); err != nil {
panic(err)
}
// Refresh our matching rules
mySchema.updateMatchingRuleUses(mySchema.AttributeTypes())
}
/*
dcodSchema contains definitions per draft-coretta-oiddir-schema. These
are not considered "built-ins" as they are not importable by users. They
are present here only for testing and examples.
*/
var dcodSchema []byte = []byte(`# Author: Jesse Coretta (February 29, 2024)
# Based on: https://datatracker.ietf.org/doc/html/draft-coretta-oiddir-schema-01
# NOT FOR PRODUCTION USE !
##########################
#
# 2.3. Attribute Types
#
# The following subsections detail one hundred three (103) attribute
# types created for use within implementations of this specification.
#
# Please note that a great many of these attribute type definitions are
# sub types of attribute types defined in the following Standards, and
# as such are considered dependencies:
#
# - [RFC2079] for URI support
# - [RFC4519] for so-called "core" schema elements
# - [RFC4524] for Cosine schema elements
#
# If the nature of a particular directory implementation precludes the
# use of sub typed attributes, this specification may not be practical
# for adoption.
#
# 2.3.1. 'n'
#
# The 'n' attribute type allows the assignment of an unsigned integer
# used to represent the Number Form of a registration per ITU-T Rec.
# [X.680].
#
# A practical ABNF production, labeled 'number', is defined in Section
# 1.4 of [RFC4512].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.1
NAME ( 'n' 'numberForm' )
DESC 'X.680, cl. 32.3: NumberForm'
EQUALITY integerMatch
ORDERING integerOrderingMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "56521", "0"
#
# 2.3.2. 'dotNotation'
#
# The 'dotNotation' attribute type allows the assignment of one (1) OID
# to any non root registration.
#
# A practical ABNF production, labeled 'numericoid', is defined within
# Section 1.4 of [RFC4512].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.2
NAME 'dotNotation'
DESC 'X.680: OID in dotted notation'
EQUALITY objectIdentifierMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.38
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "1.3.6.1", "2.999"
#
# 2.3.3. 'iRI'
#
# The 'iRI' attribute type allows the assignment of one (1) or more
# OID-IRI values to a registration.
#
# A practical ABNF production for this attribute type, as derived from
# clause 34.3 of ITU-T Rec. [X.680], is as follows:
#
# subArcId = SOLIDUS arcId [ subArcId ]
# arcId = SOLIDUS ( intUV / nintUV )
# nintUV = 1*iunreserved ; non-integer unicode value
# intUV = number ; integer unicode value
#
# SOLIDUS = "%x2f" ; "/"
#
# The 'number' ABNF production originates in Section 1.4 of [RFC4512].
# The 'iunreserved' ABNR production originates within Section 2.2 of
# [RFC3987].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.3
NAME 'iRI'
DESC 'X.680, cl. 34: OID-IRI'
EQUALITY octetStringMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "/ITU-T", "/ISO/Identified-Organization", "/ASN.1"
#
# 2.3.4. 'aSN1Notation'
#
# The 'aSN1Notation' attribute type allows the assignment of an OID in
# ASN.1, or ITU-T Rec. [X.680] ObjectIdentifierValue, notation.
#
# A practical ABNF production for this attribute type is as follows:
#
# asn1notation = LCURL forms RCURL
# forms = nanf *( SPACE nanf )
#
# SPACE = "%x20" ; " "
# LCURL = "%x7b" ; "{"
# RCURL = "%x7d" ; "}"
#
# The 'nanf' ABNF originates in Section 2.3.19.
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.4
NAME 'aSN1Notation'
DESC 'X.680, cl. 32.3: ObjectIdentifierValue'
EQUALITY caseIgnoreMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "{itu-t(0)}", "{iso(1) identified-organization(3)}"
#
# 2.3.5. 'unicodeValue'
#
# The 'unicodeValue' attribute type allows the assignment of a single
# non-integer Unicode label to a registration, per ITU-T Rec. [X.660].
#
# A practical ABNF production for this attribute type is as follows:
#
# uval = 1*iunreserved
#
# The ABNF production 'iunreserved' is defined in Section 2.2 of
# [RFC3987].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.5
NAME 'unicodeValue'
DESC 'X.660, cl. 7.5: non-integer Unicode label'
EQUALITY octetStringMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "ITU-T", "Identified-Organization"
#
# 2.3.6. 'additionalUnicodeValue'
#
# The 'additionalUnicodeValue' attribute type allows for the assignment
# of one (1) or more additional non-integer Unicode labels, per clause
# 3.5.2 of ITU-T Rec. [X.660], to a registration.
#
# A practical ABNF production for this attribute type is defined within
# Section 2.3.5.
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.6
NAME 'additionalUnicodeValue'
DESC 'X.660, cl. 3.5.2: additional non-integer Unicode labels'
EQUALITY octetStringMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# 2.3.7. 'identifier'
#
# The 'identifier' attribute type allows for the assignment of one (1)
# non-numeric, non-Unicode identifier, or nameForm, to a registration.
#
# Per clause 12.3 of ITU-T Rec. [X.680]:
#
# An "identifier" shall consist of an arbitrary number (one or more)
# of letters, digits, and hyphens. The initial character shall be a
# lower-case letter. A hyphen shall not be the last character. A
# hyphen shall not be immediately followed by another hyphen.
#
# As a practical ABNF production, the above clause translates as
# follows:
#
# identifier = leadkeychar *keychar
# leadkeychar = LOWER
# keychar = *( [ HYPHEN ] ( ALPHA / DIGIT ) )
#
# ALPHA = ( LOWER / UPPER ) ; a-z / A-Z
# UPPER = "%x41-%x5a" ; A-Z
# LOWER = "%x61-%x7a" ; a-z
# DIGIT = "%x30-%x39" ; 0-9
# HYPHEN = "%x2d" ; "-"
#
# The attribute type 'name', as defined in Section 2.18 of [RFC4519],
# is a super type of this attribute type.
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.7
NAME ( 'identifier' 'nameForm' )
DESC 'X.680, cl. 12.3: Identifier'
SUP name
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "itu-t", "iso"
#
# 2.3.8. 'secondaryIdentifier'
#
# The 'secondaryIdentifier' attribute type allows the assignment of
# one (1) or more additional secondary non-numeric non-Unicode values,
# per clause 3.5.1 of ITU-T Rec. [X.660], to a registration.
#
# A practical ABNF production for this attribute type is defined within
# Section 2.3.7.
#
# The attribute type 'name', as defined in Section 2.18 of [RFC4519],
# is a super type of this attribute type.
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.8
NAME 'secondaryIdentifier'
DESC 'X.660, cl. 3.5.1: Additional Identifiers'
SUP name
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "enterprises", "ccitt"
#
# 2.3.9. 'registrationInformation'
#
# The 'registrationInformation' attribute type allows the OPTIONAL
# assignment of octet-based values intended for extended information
# relating to the registration in question.
#
# The 'OCTET' ABNF production defined in Section 1.4 of [RFC4512] is
# applicable in any non-zero quantity or combination, as no defined
# syntax or standard exists to govern this type.
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.9
NAME 'registrationInformation'
DESC 'Extended octet-based registration data'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Example: "Acme, Co., Research & Development, Copyright (c) 2024"
#
#
# 2.3.10. 'registrationURI'
#
# The 'registrationURI' attribute type allows for the assignment of one
# (1) or more URI values, with optional labels, to a registration.
#
# The attribute type 'labeledURI', as defined in [RFC2079], is a super
# type of this attribute type.
#
# A practical ABNF production for this attribute type is defined within
# Appendix A of [RFC3986].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.10
NAME 'registrationURI'
DESC 'Uniform Resource Identifier for a registration'
SUP labeledURI
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "http://example.com Example", "ftp://example.com"
#
# 2.3.11. 'registrationCreated'
#
# The 'registrationCreated' attribute type allows for the assignment
# of a generalized timestamp indicating the date and time at which a
# registration was, or will be, created or officiated.
#
# A practical ABNF production for this attribute type is defined within
# Section 3.3.13 of [RFC4517].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.11
NAME 'registrationCreated'
DESC 'Generalized timestamp for a registration creation'
EQUALITY generalizedTimeMatch
ORDERING generalizedTimeOrderingMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.24
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "19800229114853Z", "20130109033116Z"
#
# 2.3.12. 'registrationModified'
#
# The 'registrationModified' attribute type allows for the assignment
# of one (1) or more generalized timestamp values indicating the dates
# and times of all applied updates to a registration.
#
# A practical ABNF production for this attribute type is defined within
# Section 3.3.13 of [RFC4517].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.12
NAME 'registrationModified'
DESC 'Generalized timestamps for registration modifications'
EQUALITY generalizedTimeMatch
ORDERING generalizedTimeOrderingMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.24
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "19951231115959Z", "20130109033116Z"
#
# 2.3.13. 'registrationRange'
#
# The 'registrationRange' attribute type allows for the expression of
# an OID sibling allocation range, such as "100" to indicate 'up to
# 100', or "-1" to indicate 'to infinity'.
#
# A practical ABNF production, labeled 'number', is defined in Section
# 1.4 of [RFC4512]. This satisfies the unsigned form of instances of
# this type.
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.13
NAME 'registrationRange'
DESC 'Numerical registration range expression'
EQUALITY integerMatch
ORDERING integerOrderingMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "-1", "1999", "1000000"
#
# 2.3.14. 'registrationStatus'
#
# The 'registrationStatus' attribute type allows for the assignment of
# status information meant to define the state of the registration.
#
# A practical ABNF production for the super type, 'description', is
# found within Section 3.3.6 of [RFC4517].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.14
NAME 'registrationStatus'
DESC 'Current registration status'
SUP description
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "OBSOLETE", "DEALLOCATED", "RESERVED"
#
# 2.3.15. 'registrationClassification'
#
# The 'registrationClassification' attribute type allows a registration
# to bear an informal classification value, thereby describing an OID's
# context or category.
#
# A practical ABNF production for the super type, 'description', can be
# found within Section 3.3.6 in [RFC4517].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.15
NAME 'registrationClassification'
DESC 'Known registration classification'
SUP description
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "Standard", "Individual", "ASN.1 Modules"
#
# 2.3.16. 'isLeafNode'
#
# The 'isLeafNode' attribute type allows for the assignment of a single
# Boolean value indicative of whether a registration can be a parent to
# any subordinate registrations.
#
# A practical ABNF production for this attribute type is found within
# Section 3.3.3 of [RFC4517].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.16
NAME 'isLeafNode'
DESC 'Whether a registration may allocate sub arcs'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "TRUE", "FALSE", or Undefined (implies "FALSE")
#
# 2.3.17. 'isFrozen'
#
# The 'isFrozen' attribute type allows for the assignment of a single
# Boolean value indicative of whether a registration can be a parent
# to any further subordinate registrations beyond those that already
# exist at present.
#
# A practical ABNF production for this attribute type is found within
# Section 3.3.3 of [RFC4517].
#
attributetype ( 1.3.6.1.4.1.56521.101.2.3.17
NAME 'isFrozen'
DESC 'Whether additional sub arcs are permitted'
EQUALITY booleanMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7
SINGLE-VALUE
X-ORIGIN 'draft-coretta-oiddir-schema' )
#
# Examples: "TRUE", "FALSE", or Undefined (implies "FALSE")
#
# 2.3.18. 'standardizedNameForm'
#
# The 'standardizedNameForm' attribute type allows for the assignment
# of one (1) or more Standardized NameForm values, per clauses A.2 and
# A.3 of ITU-T Rec. [X.660], to a registration only if its 'identifier'
# value is considered standardized.
#
# A practical ABNF production for this attribute type is as follows:
#