Skip to content

CA-408550: XSI-1834: Host netbios name should be added to local hosts file to avoid DNS lookup #6386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions ocaml/tests/test_extauth_plugin_ADwinbind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,106 @@ let test_wbinfo_exception_of_stderr =
in
matrix |> List.map @@ fun (inp, exp) -> ("<omit inp>", `Quick, check inp exp)

let test_add_ipv4_localhost_to_hosts =
let open Extauth_plugin_ADwinbind in
let check inp exp () =
let msg =
Printf.sprintf "%s -> %s" (String.concat "\n" inp) (String.concat "\n" exp)
in
let actual =
HostsConfIPv4.join ~name:"hostname" ~domain:"domain" ~lines:inp
in
Alcotest.(check @@ list string) msg exp actual
in
let matrix =
[
( [
"127.0.0.1 localhost localhost.localdomain localhost4 \
localhost4.localdomain4"
]
, [
"127.0.0.1 localhost localhost.localdomain localhost4 \
localhost4.localdomain4 hostname hostname.domain"
]
)
; ( ["127.0.0.1 localhost hostname hostname.domain localhost.localdomain"]
, ["127.0.0.1 localhost localhost.localdomain hostname hostname.domain"]
)
; ( ["192.168.0.1 some_host"]
, ["127.0.0.1 hostname hostname.domain"; "192.168.0.1 some_host"]
)
; ([], ["127.0.0.1 hostname hostname.domain"])
]
in
matrix |> List.map @@ fun (inp, exp) -> ("<omit inp>", `Quick, check inp exp)

let test_add_ipv4_and_ipv6_localhost_to_hosts =
let open Extauth_plugin_ADwinbind in
let check inp exp () =
let msg =
Printf.sprintf "%s -> %s" (String.concat "\n" inp) (String.concat "\n" exp)
in
let actual =
HostsConfIPv6.join ~name:"hostname" ~domain:"domain" ~lines:inp
|> fun lines ->
HostsConfIPv4.join ~name:"hostname" ~domain:"domain" ~lines
in
Alcotest.(check @@ list string) msg exp actual
in
let matrix =
[
( ["127.0.0.1 localhost"]
, [
"::1 hostname hostname.domain"
; "127.0.0.1 localhost hostname hostname.domain"
]
)
; ( ["127.0.0.1 localhost"; "::1 localhost"]
, [
"127.0.0.1 localhost hostname hostname.domain"
; "::1 localhost hostname hostname.domain"
]
)
; ( []
, ["127.0.0.1 hostname hostname.domain"; "::1 hostname hostname.domain"]
)
]
in
matrix |> List.map @@ fun (inp, exp) -> ("<omit inp>", `Quick, check inp exp)

let test_remove_ipv4_localhost_from_hosts =
let open Extauth_plugin_ADwinbind in
let check inp exp () =
let msg =
Printf.sprintf "%s -> %s" (String.concat "\n" inp) (String.concat "\n" exp)
in
let actual =
HostsConfIPv4.leave ~name:"hostname" ~domain:"domain" ~lines:inp
in
Alcotest.(check @@ list string) msg exp actual
in
let matrix =
[
( [
"127.0.0.1 localhost localhost.localdomain localhost4 \
localhost4.localdomain4"
]
, [
"127.0.0.1 localhost localhost.localdomain localhost4 \
localhost4.localdomain4"
]
)
; ( ["127.0.0.1 localhost hostname hostname.domain localhost.localdomain"]
, ["127.0.0.1 localhost localhost.localdomain"]
)
; (["127.0.0.1 hostname hostname.domain"], [])
; ( ["192.168.0.1 some_host"; "127.0.0.1 localhost hostname"]
, ["192.168.0.1 some_host"; "127.0.0.1 localhost"]
)
]
in
matrix |> List.map @@ fun (inp, exp) -> ("<omit inp>", `Quick, check inp exp)

let tests =
[
("ADwinbind:extract_ou_config", ExtractOuConfig.tests)
Expand All @@ -512,4 +612,13 @@ let tests =
; ( "ADwinbind:test_wbinfo_exception_of_stderr"
, test_wbinfo_exception_of_stderr
)
; ( "ADwinbind:test_add_ipv4_localhost_to_hosts"
, test_add_ipv4_localhost_to_hosts
)
; ( "ADwinbind:test_remove_ipv4_localhost_from_hosts"
, test_remove_ipv4_localhost_from_hosts
)
; ( "ADwinbind:test_add_ipv4_and_ipv6_localhost_to_hosts"
, test_add_ipv4_and_ipv6_localhost_to_hosts
)
]
Loading
Loading