Skip to content

Commit

Permalink
CP-51836: UT for restrict/check binary_url
Browse files Browse the repository at this point in the history
Signed-off-by: Bengang Yuan <[email protected]>
  • Loading branch information
BengangY committed Oct 31, 2024
1 parent 30ce0db commit 645e98c
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion ocaml/tests/test_repository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let test_introduce_duplicate_repo_name () =
let name_description_1 = "description1" in
let binary_url = "https://repo.example.com" in
let binary_url_1 = "https://repo1.example.com" in
let binary_url_2 = "https://1.1.1.1/repository/enabled" in
let source_url = "https://repo-src.example.com" in
let source_url_1 = "https://repo-src1.example.com" in
let gpgkey_path = "" in
Expand All @@ -42,6 +43,14 @@ let test_introduce_duplicate_repo_name () =
Repository.introduce_bundle ~__context ~name_label
~name_description:name_description_1
|> ignore
) ;
Alcotest.check_raises "test_introduce_duplicate_repo_name_3"
Api_errors.(Server_error (repository_already_exists, [Ref.string_of ref]))
(fun () ->
Repository.introduce_remote_pool ~__context ~name_label
~name_description:name_description_1 ~binary_url:binary_url_2
~certificate:""
|> ignore
)

let test_introduce_duplicate_binary_url () =
Expand All @@ -58,7 +67,7 @@ let test_introduce_duplicate_binary_url () =
Repository.introduce ~__context ~name_label ~name_description ~binary_url
~source_url ~update:true ~gpgkey_path
in
Alcotest.check_raises "test_introduce_duplicate_binary_url"
Alcotest.check_raises "test_introduce_duplicate_binary_url_1"
Api_errors.(Server_error (repository_already_exists, [Ref.string_of ref]))
(fun () ->
Repository.introduce ~__context ~binary_url ~name_label:name_label_1
Expand Down Expand Up @@ -110,6 +119,59 @@ let test_introduce_duplicate_bundle_repo () =
|> ignore
)

let test_introduce_invalid_remote_pool_repo_url () =
let __context = T.make_test_database () in
let name_label = "name" in
let name_description = "description" in
let invalid_url_1 = "http://1.1.1.1/repository/enabled" in
let invalid_url_2 = "https://1.1.1.257/repository/enabled" in
let invalid_url_3 = "https://test.com/repository/enabled" in
let invalid_url_4 = "https://1.1.1.1/other" in
let invalid_url_5 = "https://1.1.1.1" in
let invalid_url_6 = "non-url" in
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_1"
Api_errors.(Server_error (invalid_base_url, [invalid_url_1]))
(fun () ->
Repository.introduce_remote_pool ~__context ~name_label ~name_description
~binary_url:invalid_url_1 ~certificate:""
|> ignore
) ;
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_2"
Api_errors.(Server_error (invalid_base_url, [invalid_url_2]))
(fun () ->
Repository.introduce_remote_pool ~__context ~name_label ~name_description
~binary_url:invalid_url_2 ~certificate:""
|> ignore
) ;
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_3"
Api_errors.(Server_error (invalid_base_url, [invalid_url_3]))
(fun () ->
Repository.introduce_remote_pool ~__context ~name_label ~name_description
~binary_url:invalid_url_3 ~certificate:""
|> ignore
) ;
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_4"
Api_errors.(Server_error (invalid_base_url, [invalid_url_4]))
(fun () ->
Repository.introduce_remote_pool ~__context ~name_label ~name_description
~binary_url:invalid_url_4 ~certificate:""
|> ignore
) ;
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_5"
Api_errors.(Server_error (invalid_base_url, [invalid_url_5]))
(fun () ->
Repository.introduce_remote_pool ~__context ~name_label ~name_description
~binary_url:invalid_url_5 ~certificate:""
|> ignore
) ;
Alcotest.check_raises "test_introduce_invalid_remote_pool_repo_url_6"
Api_errors.(Server_error (invalid_base_url, [invalid_url_6]))
(fun () ->
Repository.introduce_remote_pool ~__context ~name_label ~name_description
~binary_url:invalid_url_6 ~certificate:""
|> ignore
)

let test =
[
( "test_introduce_duplicate_repo_name"
Expand All @@ -128,6 +190,10 @@ let test =
, `Quick
, test_introduce_duplicate_bundle_repo
)
; ( "test_introduce_invalid_remote_pool_repo_url"
, `Quick
, test_introduce_invalid_remote_pool_repo_url
)
]

let () =
Expand Down

0 comments on commit 645e98c

Please sign in to comment.