@@ -499,6 +499,106 @@ let test_wbinfo_exception_of_stderr =
499
499
in
500
500
matrix |> List. map @@ fun (inp , exp ) -> (" <omit inp>" , `Quick , check inp exp)
501
501
502
+ let test_add_ipv4_localhost_to_hosts =
503
+ let open Extauth_plugin_ADwinbind in
504
+ let check inp exp () =
505
+ let msg =
506
+ Printf. sprintf " %s -> %s" (String. concat " \n " inp) (String. concat " \n " exp)
507
+ in
508
+ let actual =
509
+ HostsConfIPv4. join ~name: " hostname" ~domain: " domain" ~lines: inp
510
+ in
511
+ Alcotest. (check @@ list string ) msg exp actual
512
+ in
513
+ let matrix =
514
+ [
515
+ ( [
516
+ " 127.0.0.1 localhost localhost.localdomain localhost4 \
517
+ localhost4.localdomain4"
518
+ ]
519
+ , [
520
+ " 127.0.0.1 localhost localhost.localdomain localhost4 \
521
+ localhost4.localdomain4 hostname hostname.domain"
522
+ ]
523
+ )
524
+ ; ( [" 127.0.0.1 localhost hostname hostname.domain localhost.localdomain" ]
525
+ , [" 127.0.0.1 localhost localhost.localdomain hostname hostname.domain" ]
526
+ )
527
+ ; ( [" 192.168.0.1 some_host" ]
528
+ , [" 127.0.0.1 hostname hostname.domain" ; " 192.168.0.1 some_host" ]
529
+ )
530
+ ; ([] , [" 127.0.0.1 hostname hostname.domain" ])
531
+ ]
532
+ in
533
+ matrix |> List. map @@ fun (inp , exp ) -> (" <omit inp>" , `Quick , check inp exp)
534
+
535
+ let test_add_ipv4_and_ipv6_localhost_to_hosts =
536
+ let open Extauth_plugin_ADwinbind in
537
+ let check inp exp () =
538
+ let msg =
539
+ Printf. sprintf " %s -> %s" (String. concat " \n " inp) (String. concat " \n " exp)
540
+ in
541
+ let actual =
542
+ HostsConfIPv6. join ~name: " hostname" ~domain: " domain" ~lines: inp
543
+ |> fun lines ->
544
+ HostsConfIPv4. join ~name: " hostname" ~domain: " domain" ~lines
545
+ in
546
+ Alcotest. (check @@ list string ) msg exp actual
547
+ in
548
+ let matrix =
549
+ [
550
+ ( [" 127.0.0.1 localhost" ]
551
+ , [
552
+ " ::1 hostname hostname.domain"
553
+ ; " 127.0.0.1 localhost hostname hostname.domain"
554
+ ]
555
+ )
556
+ ; ( [" 127.0.0.1 localhost" ; " ::1 localhost" ]
557
+ , [
558
+ " 127.0.0.1 localhost hostname hostname.domain"
559
+ ; " ::1 localhost hostname hostname.domain"
560
+ ]
561
+ )
562
+ ; ( []
563
+ , [" 127.0.0.1 hostname hostname.domain" ; " ::1 hostname hostname.domain" ]
564
+ )
565
+ ]
566
+ in
567
+ matrix |> List. map @@ fun (inp , exp ) -> (" <omit inp>" , `Quick , check inp exp)
568
+
569
+ let test_remove_ipv4_localhost_from_hosts =
570
+ let open Extauth_plugin_ADwinbind in
571
+ let check inp exp () =
572
+ let msg =
573
+ Printf. sprintf " %s -> %s" (String. concat " \n " inp) (String. concat " \n " exp)
574
+ in
575
+ let actual =
576
+ HostsConfIPv4. leave ~name: " hostname" ~domain: " domain" ~lines: inp
577
+ in
578
+ Alcotest. (check @@ list string ) msg exp actual
579
+ in
580
+ let matrix =
581
+ [
582
+ ( [
583
+ " 127.0.0.1 localhost localhost.localdomain localhost4 \
584
+ localhost4.localdomain4"
585
+ ]
586
+ , [
587
+ " 127.0.0.1 localhost localhost.localdomain localhost4 \
588
+ localhost4.localdomain4"
589
+ ]
590
+ )
591
+ ; ( [" 127.0.0.1 localhost hostname hostname.domain localhost.localdomain" ]
592
+ , [" 127.0.0.1 localhost localhost.localdomain" ]
593
+ )
594
+ ; ([" 127.0.0.1 hostname hostname.domain" ], [] )
595
+ ; ( [" 192.168.0.1 some_host" ; " 127.0.0.1 localhost hostname" ]
596
+ , [" 192.168.0.1 some_host" ; " 127.0.0.1 localhost" ]
597
+ )
598
+ ]
599
+ in
600
+ matrix |> List. map @@ fun (inp , exp ) -> (" <omit inp>" , `Quick , check inp exp)
601
+
502
602
let tests =
503
603
[
504
604
(" ADwinbind:extract_ou_config" , ExtractOuConfig. tests)
@@ -512,4 +612,13 @@ let tests =
512
612
; ( " ADwinbind:test_wbinfo_exception_of_stderr"
513
613
, test_wbinfo_exception_of_stderr
514
614
)
615
+ ; ( " ADwinbind:test_add_ipv4_localhost_to_hosts"
616
+ , test_add_ipv4_localhost_to_hosts
617
+ )
618
+ ; ( " ADwinbind:test_remove_ipv4_localhost_from_hosts"
619
+ , test_remove_ipv4_localhost_from_hosts
620
+ )
621
+ ; ( " ADwinbind:test_add_ipv4_and_ipv6_localhost_to_hosts"
622
+ , test_add_ipv4_and_ipv6_localhost_to_hosts
623
+ )
515
624
]
0 commit comments