@@ -115,7 +115,31 @@ class GitTest : WordSpec({
115115
116116 val credentialProvider = CredentialsProvider .getDefault()
117117
118- credentialProvider.get(TestUri , userCredential, passwordCredential) shouldBe true
118+ credentialProvider.get(testUri, userCredential, passwordCredential) shouldBe true
119+
120+ verify {
121+ userCredential.value = user
122+ passwordCredential.value = password
123+ }
124+ }
125+
126+ " handle an invalid URL" {
127+ val user = " scott"
128+ val password = " tiger" .toCharArray()
129+ val userCredential = mockk<CredentialItem .Username >()
130+ val passwordCredential = mockk<CredentialItem .Password >()
131+ val invalidUri = URIish ("foo")
132+
133+ every { userCredential.value = any() } just runs
134+ every { passwordCredential.value = any() } just runs
135+ mockAuthentication(null)
136+ every {
137+ requestPasswordAuthentication("", invalidUri.port, "", null)
138+ } returns PasswordAuthentication (user, password)
139+
140+ val credentialProvider = CredentialsProvider .getDefault()
141+
142+ credentialProvider.get(invalidUri, userCredential, passwordCredential) shouldBe true
119143
120144 verify {
121145 userCredential.value = user
@@ -131,7 +155,7 @@ class GitTest : WordSpec({
131155
132156 val credentialProvider = CredentialsProvider .getDefault()
133157
134- credentialProvider.get(TestUri , userCredential, passwordCredential) shouldBe false
158+ credentialProvider.get(testUri , userCredential, passwordCredential) shouldBe false
135159 }
136160
137161 " throw for unsupported credential types" {
@@ -142,7 +166,7 @@ class GitTest : WordSpec({
142166 val credentialProvider = CredentialsProvider .getDefault()
143167
144168 shouldThrow<UnsupportedCredentialItem > {
145- credentialProvider.get(TestUri , otherCredential)
169+ credentialProvider.get(testUri , otherCredential)
146170 }
147171 }
148172
@@ -154,13 +178,16 @@ class GitTest : WordSpec({
154178 }
155179})
156180
157- private val TestUri = URIish (URI (" https://www.example.org:8080/foo" ).toURL())
181+ private val testUri = URIish (URI (" https://www.example.org:8080/foo" ).toURL())
182+ private val testUriAsUrl = URI .create(testUri.toString()).toURL()
158183
159184/* *
160185 * Mocks the utility function to query password authentication for the test URI. Return the [result] provided.
161186 */
162187private fun mockAuthentication (result : PasswordAuthentication ? ) {
163188 mockkStatic(" org.ossreviewtoolkit.utils.ort.UtilsKt" )
164189
165- every { requestPasswordAuthentication(TestUri .host, TestUri .port, TestUri .scheme) } returns result
190+ every {
191+ requestPasswordAuthentication(testUri.host, testUri.port, testUri.scheme, testUriAsUrl)
192+ } returns result
166193}
0 commit comments