Skip to content

Commit 3673379

Browse files
authored
Merge pull request #5869 from last-genius/private/asultanov/restr_removal
2 parents a849c1d + a4bbf25 commit 3673379

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

ocaml/tests/dune

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
test_cluster_host test_cluster test_pusb test_network_sriov
88
test_client test_valid_ref_list suite_alcotest_server
99
test_vm_placement test_vm_helpers test_repository test_repository_helpers
10-
test_ref test_vm_group
10+
test_ref test_xapi_helpers test_vm_group
1111
test_livepatch test_rpm test_updateinfo test_storage_smapiv1_wrapper test_storage_quicktest test_observer
1212
test_pool_periodic_update_sync test_pkg_mgr))
1313
(libraries
@@ -79,13 +79,15 @@
7979
(tests
8080
(names test_vm_helpers test_vm_placement test_network_sriov test_vdi_cbt
8181
test_clustering test_pusb test_daemon_manager test_repository test_repository_helpers
82-
test_livepatch test_rpm test_updateinfo test_pool_periodic_update_sync test_pkg_mgr)
82+
test_livepatch test_rpm test_updateinfo test_pool_periodic_update_sync test_pkg_mgr
83+
test_xapi_helpers)
8384
(package xapi)
8485
(modes exe)
8586
(modules test_vm_helpers test_vm_placement test_network_sriov test_vdi_cbt
8687
test_event test_clustering test_cluster_host test_cluster test_pusb
8788
test_daemon_manager test_repository test_repository_helpers test_livepatch test_rpm
88-
test_updateinfo test_pool_periodic_update_sync test_pkg_mgr)
89+
test_updateinfo test_pool_periodic_update_sync test_pkg_mgr
90+
test_xapi_helpers)
8991
(libraries
9092
alcotest
9193
fmt

ocaml/tests/test_xapi_helpers.ml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(*
2+
* Copyright (C) Cloud Software Group, Inc
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published
6+
* by the Free Software Foundation; version 2.1 only. with the special
7+
* exception on linking described in file LICENSE.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*)
14+
15+
let strings =
16+
[
17+
("foobar", "foobar")
18+
; ("foobarproxy_username=password", "foobarproxy_username=(filtered)")
19+
; ("barfooproxy_password=secret", "barfooproxy_password=(filtered)")
20+
; ("password", "password")
21+
; ("username=password", "username=password")
22+
; ("password=password", "password=password")
23+
; ("proxy_username=", "proxy_username=(filtered)")
24+
]
25+
26+
let filtering_test =
27+
List.map
28+
(fun (input, expected) ->
29+
let test_filtering () =
30+
let filtered =
31+
match Helpers.filter_args [input] with x :: _ -> x | _ -> ""
32+
in
33+
Printf.printf "%s\n" input ;
34+
Alcotest.(check string) "secrets must be filtered out" expected filtered
35+
in
36+
( Printf.sprintf {|Validation of argument filtering of "%s"|} input
37+
, `Quick
38+
, test_filtering
39+
)
40+
)
41+
strings
42+
43+
let () =
44+
Suite_init.harness_init () ;
45+
Alcotest.run "Test XAPI Helpers suite" [("Test_xapi_helpers", filtering_test)]

ocaml/xapi/helpers.ml

+3-9
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,15 @@ let log_exn_continue msg f x =
4242
type log_output = Always | Never | On_failure
4343

4444
let filter_patterns =
45-
[
46-
( Re.Str.regexp "^\\(.*proxy_\\(username\\|password\\)=\\)\\(.*\\)$"
47-
, "\\1(filtered)"
48-
)
49-
]
45+
[(Re.Pcre.regexp "^(.*proxy_(username|password)=)(.*)$", "(filtered)")]
5046

5147
let filter_args args =
5248
List.map
5349
(fun arg ->
5450
List.fold_left
5551
(fun acc (r, t) ->
56-
if Re.Str.string_match r acc 0 then
57-
Re.Str.replace_matched t acc
58-
else
59-
acc
52+
try String.concat "" [(Re.Pcre.extract ~rex:r acc).(1); t]
53+
with Not_found -> acc
6054
)
6155
arg filter_patterns
6256
)

0 commit comments

Comments
 (0)