Skip to content

Commit 645e98c

Browse files
committed
CP-51836: UT for restrict/check binary_url
Signed-off-by: Bengang Yuan <[email protected]>
1 parent 30ce0db commit 645e98c

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

ocaml/tests/test_repository.ml

Lines changed: 67 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,59 @@ 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_description = "description" in
126+
let invalid_url_1 = "http://1.1.1.1/repository/enabled" in
127+
let invalid_url_2 = "https://1.1.1.257/repository/enabled" in
128+
let invalid_url_3 = "https://test.com/repository/enabled" in
129+
let invalid_url_4 = "https://1.1.1.1/other" in
130+
let invalid_url_5 = "https://1.1.1.1" in
131+
let invalid_url_6 = "non-url" in
132+
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_1"
133+
Api_errors.(Server_error (invalid_base_url, [invalid_url_1]))
134+
(fun () ->
135+
Repository.introduce_remote_pool ~__context ~name_label ~name_description
136+
~binary_url:invalid_url_1 ~certificate:""
137+
|> ignore
138+
) ;
139+
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_2"
140+
Api_errors.(Server_error (invalid_base_url, [invalid_url_2]))
141+
(fun () ->
142+
Repository.introduce_remote_pool ~__context ~name_label ~name_description
143+
~binary_url:invalid_url_2 ~certificate:""
144+
|> ignore
145+
) ;
146+
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_3"
147+
Api_errors.(Server_error (invalid_base_url, [invalid_url_3]))
148+
(fun () ->
149+
Repository.introduce_remote_pool ~__context ~name_label ~name_description
150+
~binary_url:invalid_url_3 ~certificate:""
151+
|> ignore
152+
) ;
153+
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_4"
154+
Api_errors.(Server_error (invalid_base_url, [invalid_url_4]))
155+
(fun () ->
156+
Repository.introduce_remote_pool ~__context ~name_label ~name_description
157+
~binary_url:invalid_url_4 ~certificate:""
158+
|> ignore
159+
) ;
160+
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_5"
161+
Api_errors.(Server_error (invalid_base_url, [invalid_url_5]))
162+
(fun () ->
163+
Repository.introduce_remote_pool ~__context ~name_label ~name_description
164+
~binary_url:invalid_url_5 ~certificate:""
165+
|> ignore
166+
) ;
167+
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_6"
168+
Api_errors.(Server_error (invalid_base_url, [invalid_url_6]))
169+
(fun () ->
170+
Repository.introduce_remote_pool ~__context ~name_label ~name_description
171+
~binary_url:invalid_url_6 ~certificate:""
172+
|> ignore
173+
)
174+
113175
let test =
114176
[
115177
( "test_introduce_duplicate_repo_name"
@@ -128,6 +190,10 @@ let test =
128190
, `Quick
129191
, test_introduce_duplicate_bundle_repo
130192
)
193+
; ( "test_introduce_invalid_remote_pool_repo_url"
194+
, `Quick
195+
, test_introduce_invalid_remote_pool_repo_url
196+
)
131197
]
132198

133199
let () =

0 commit comments

Comments
 (0)