Skip to content

Commit 858767b

Browse files
committed
CP-51836: UT for restrict/check binary_url
Signed-off-by: Bengang Yuan <[email protected]>
1 parent 6267461 commit 858767b

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

ocaml/tests/test_repository.ml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let test_introduce_duplicate_repo_name () =
2121
let name_description_1 = "description1" in
2222
let binary_url = "https://repo.example.com" in
2323
let binary_url_1 = "https://repo1.example.com" in
24+
let binary_url_2 = "https://1.1.1.1/repository/enabled" in
2425
let source_url = "https://repo-src.example.com" in
2526
let source_url_1 = "https://repo-src1.example.com" in
2627
let gpgkey_path = "" in
@@ -42,6 +43,14 @@ let test_introduce_duplicate_repo_name () =
4243
Repository.introduce_bundle ~__context ~name_label
4344
~name_description:name_description_1
4445
|> ignore
46+
) ;
47+
Alcotest.check_raises "test_introduce_duplicate_repo_name_3"
48+
Api_errors.(Server_error (repository_already_exists, [Ref.string_of ref]))
49+
(fun () ->
50+
Repository.introduce_remote_pool ~__context ~name_label
51+
~name_description:name_description_1 ~binary_url:binary_url_2
52+
~certificate:""
53+
|> ignore
4554
)
4655

4756
let test_introduce_duplicate_binary_url () =
@@ -58,7 +67,7 @@ let test_introduce_duplicate_binary_url () =
5867
Repository.introduce ~__context ~name_label ~name_description ~binary_url
5968
~source_url ~update:true ~gpgkey_path
6069
in
61-
Alcotest.check_raises "test_introduce_duplicate_binary_url"
70+
Alcotest.check_raises "test_introduce_duplicate_binary_url_1"
6271
Api_errors.(Server_error (repository_already_exists, [Ref.string_of ref]))
6372
(fun () ->
6473
Repository.introduce ~__context ~binary_url ~name_label:name_label_1
@@ -110,6 +119,56 @@ let test_introduce_duplicate_bundle_repo () =
110119
|> ignore
111120
)
112121

122+
let test_introduce_invalid_remote_pool_repo_url () =
123+
let __context = T.make_test_database () in
124+
let name_label = "name" in
125+
let name_label_1 = "name1" in
126+
let name_description = "description" in
127+
let valid_url = "https://1.1.1.1/repository/enabled" in
128+
let invalid_url_1 = "http://1.1.1.1/repository/enabled" in
129+
let invalid_url_2 = "https://1.1.1.257/repository/enabled" in
130+
let invalid_url_3 = "https://test.com/repository/enabled" in
131+
let invalid_url_4 = "https://1.1.1.1/other" in
132+
let invalid_url_5 = "https://1.1.1.1" in
133+
Repository.introduce_remote_pool ~__context ~name_label ~name_description
134+
~binary_url:valid_url ~certificate:""
135+
|> ignore ;
136+
Alcotest.check_raises "test_introduce_duplicate_bundle_repo_1"
137+
Api_errors.(Server_error (invalid_base_url, [invalid_url_1]))
138+
(fun () ->
139+
Repository.introduce_remote_pool ~__context ~name_label:name_label_1
140+
~name_description ~binary_url:invalid_url_1 ~certificate:""
141+
|> ignore
142+
) ;
143+
Alcotest.check_raises "test_introduce_duplicate_bundle_repo_2"
144+
Api_errors.(Server_error (invalid_base_url, [invalid_url_2]))
145+
(fun () ->
146+
Repository.introduce_remote_pool ~__context ~name_label:name_label_1
147+
~name_description ~binary_url:invalid_url_2 ~certificate:""
148+
|> ignore
149+
) ;
150+
Alcotest.check_raises "test_introduce_duplicate_bundle_repo_3"
151+
Api_errors.(Server_error (invalid_base_url, [invalid_url_3]))
152+
(fun () ->
153+
Repository.introduce_remote_pool ~__context ~name_label:name_label_1
154+
~name_description ~binary_url:invalid_url_3 ~certificate:""
155+
|> ignore
156+
) ;
157+
Alcotest.check_raises "test_introduce_duplicate_bundle_repo_4"
158+
Api_errors.(Server_error (invalid_base_url, [invalid_url_4]))
159+
(fun () ->
160+
Repository.introduce_remote_pool ~__context ~name_label:name_label_1
161+
~name_description ~binary_url:invalid_url_4 ~certificate:""
162+
|> ignore
163+
) ;
164+
Alcotest.check_raises "test_introduce_duplicate_bundle_repo_5"
165+
Api_errors.(Server_error (invalid_base_url, [invalid_url_5]))
166+
(fun () ->
167+
Repository.introduce_remote_pool ~__context ~name_label:name_label_1
168+
~name_description ~binary_url:invalid_url_5 ~certificate:""
169+
|> ignore
170+
)
171+
113172
let test =
114173
[
115174
( "test_introduce_duplicate_repo_name"
@@ -128,6 +187,10 @@ let test =
128187
, `Quick
129188
, test_introduce_duplicate_bundle_repo
130189
)
190+
; ( "test_introduce_invalid_remote_pool_repo_url"
191+
, `Quick
192+
, test_introduce_invalid_remote_pool_repo_url
193+
)
131194
]
132195

133196
let () =

0 commit comments

Comments
 (0)