2727PUB_PENDING_GIT_REPO = f"{ GIT_BASE_URL } /iib-pub-pending-index-configs.git"
2828PUB_PENDING_TOKEN_NAME = "iibpubpendingtoken"
2929PUB_PENDING_TOKEN_VALUE = "iibpubpendingabc123"
30+ TESTING_REPO = f"{ GIT_BASE_URL } /testing.git"
31+ TESTING_TOKEN_VALUE = "abcdef"
3032
3133
3234@pytest .fixture ()
3335def mock_gwc ():
3436 with mock .patch ('iib.workers.tasks.git_utils.get_worker_config' ) as mc :
3537 mc .return_value = {
3638 "iib_index_configs_gitlab_tokens_map" : {
37- PUB_GIT_REPO : (PUB_TOKEN_NAME , PUB_TOKEN_VALUE ),
38- PUB_PENDING_GIT_REPO : (PUB_PENDING_TOKEN_NAME , PUB_PENDING_TOKEN_VALUE ),
39+ PUB_GIT_REPO : f"{ PUB_TOKEN_NAME } :{ PUB_TOKEN_VALUE } " ,
40+ PUB_PENDING_GIT_REPO : f"{ PUB_PENDING_TOKEN_NAME } :{ PUB_PENDING_TOKEN_VALUE } " ,
41+ TESTING_REPO : f"{ TESTING_TOKEN_VALUE } :{ TESTING_TOKEN_VALUE } :" ,
3942 },
4043 }
4144 yield mc
@@ -73,6 +76,7 @@ def test_unmapped_git_token(mock_gwc):
7376 [
7477 (PUB_GIT_REPO , PUB_TOKEN_NAME , PUB_TOKEN_VALUE ),
7578 (PUB_PENDING_GIT_REPO , PUB_PENDING_TOKEN_NAME , PUB_PENDING_TOKEN_VALUE ),
79+ (TESTING_REPO , TESTING_TOKEN_VALUE , TESTING_TOKEN_VALUE ),
7680 ],
7781)
7882def test_get_git_token (repo_url , expected_token_name , expected_token_value , mock_gwc ):
@@ -81,6 +85,38 @@ def test_get_git_token(repo_url, expected_token_name, expected_token_value, mock
8185 assert git_token_value == expected_token_value
8286
8387
88+ @pytest .mark .parametrize (
89+ "repo_url, token_value, expected_err" ,
90+ [
91+ (
92+ TESTING_REPO ,
93+ TESTING_TOKEN_VALUE ,
94+ f"Invalid token format for '{ TESTING_REPO } ' in 'iib_index_configs_gitlab_tokens_map'. Expected 'token_name:token_value'." , # noqa: E501
95+ ),
96+ (
97+ TESTING_REPO ,
98+ "" ,
99+ f"Invalid token format for '{ TESTING_REPO } ' in 'iib_index_configs_gitlab_tokens_map'. Expected 'token_name:token_value'." , # noqa: E501
100+ ),
101+ (
102+ TESTING_REPO ,
103+ ":some_value" ,
104+ f"Invalid token format for '{ TESTING_REPO } ' in 'iib_index_configs_gitlab_tokens_map'. Expected 'token_name:token_value'." , # noqa: E501
105+ ),
106+ (
107+ TESTING_REPO ,
108+ "some_name:" ,
109+ f"Invalid token format for '{ TESTING_REPO } ' in 'iib_index_configs_gitlab_tokens_map'. Expected 'token_name:token_value'." , # noqa: E501
110+ ),
111+ ],
112+ )
113+ def test_get_git_token_missing_name_value (repo_url , token_value , expected_err , mock_gwc ):
114+ with mock .patch ('iib.workers.tasks.git_utils.get_worker_config' ) as mc :
115+ mc .return_value = {"iib_index_configs_gitlab_tokens_map" : {repo_url : token_value }}
116+ with pytest .raises (IIBError , match = expected_err ):
117+ git_utils .get_git_token (repo_url )
118+
119+
84120def test_unmapped_git_url (mock_gwc , gitlab_url_mapping , caplog ):
85121 # Setting the logging level via caplog.set_level is not sufficient. The flask
86122 # related settings from previous tests interfere with this.
0 commit comments