Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fossid-webapp): creatScan response can be polymorphic #8541

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/fossid-webapp/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ suspend fun FossIdRestService.createScan(
gitRepoUrl: String,
gitBranch: String,
comment: String = ""
): MapResponseBody<String> =
): PolymorphicResponseBody<String> =
createScan(
PostRequestBody(
"create",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ interface FossIdRestService {
suspend fun createProject(@Body body: PostRequestBody): MapResponseBody<String>

@POST("api.php")
suspend fun createScan(@Body body: PostRequestBody): MapResponseBody<String>
suspend fun createScan(@Body body: PostRequestBody): PolymorphicResponseBody<String>

@POST("api.php")
suspend fun runScan(@Body body: PostRequestBody): EntityResponseBody<Nothing>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id" : "a1163704-9a3b-492c-bfd8-44593eeb9b25",
"name" : "apiphp",
"request" : {
"url" : "/api.php",
"method" : "POST",
"bodyPatterns" : [ {
"equalToJson" : "{\"action\":\"create\",\"group\":\"scans\",\"data\":{\"username\":\"\",\"key\":\"\",\"scan_code\":\"semver4j_20201203_090342\",\"project_code\":\"semver4j\",\"git_repo_url\":\"git_repo_url\",\"git_branch\":\"develop\"}}",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
} ]
},
"response" : {
"status" : 200,
"body" : "{\"operation\":\"scans_create\", \"status\":\"0\", \"data\":[{\"code\": \"RequestData.Base.issue_with_executing_command\", \"message\":\"Field git_repo_url: there was an issue executing command: timeout 200 git ls-remote 'ssh git repo' 2>&1. Exit status: 128. Output: Repository not found The requested repository does not exist, or you do not have permission to access it. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.\", \"message_parameters\":{\"fieldname\":\"git_repo_url\", \"cmd\":\"timeout 200 git ls-remote 'ssh git repo' 2>&1\", \"exitStatus\":128, \"out\":\"Repository not found The requested repository does not exist, or you do not have permission to access it. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.\"} }], \"error\":\"RequestData.Base.issues_while_parsing_request\", \"message\":\"These issues were found while parsing the request:\", \"message_parameters\":[]}",
"headers" : {
"Content-Type" : "text/html; charset=UTF-8",
"Date" : "Thu, 03 Dec 2020 08:03:42 GMT",
"Server" : "Apache/2.4.38 (Debian)",
"Vary" : "Accept-Encoding"
}
},
"uuid" : "a1163704-9a3b-492c-bfd8-44593eeb9b25",
"persistent" : true,
"insertionIndex" : 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.collections.shouldContainExactly

Check warning on line 27 in clients/fossid-webapp/src/test/kotlin/FossIdClientNewProjectTest.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Unused import directive

Unused import directive

Check warning

Code scanning / detekt

Unused Imports are dead code and should be removed. Warning

The import 'io.kotest.matchers.collections.shouldContainExactly' is unused.
import io.kotest.matchers.collections.shouldHaveSingleElement
import io.kotest.matchers.maps.shouldContain
import io.kotest.matchers.nulls.beNull
import io.kotest.matchers.nulls.shouldNotBeNull
Expand Down Expand Up @@ -95,7 +97,7 @@
SCAN_CODE,
"https://github.com/gundy/semver4j.git",
"671aa533f7e33c773bf620b9f466650c3b9ab26e"
).shouldNotBeNull().data.shouldNotBeNull() shouldContain("scan_id" to "4920")
).shouldNotBeNull().data.shouldNotBeNull().shouldHaveSingleElement("4920")
}

"Download from Git can be triggered" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ class FossIdClientReturnTypeTest : StringSpec({
}
}

"When create scan returns an error, no exception is thrown" {
service.createScan(
"",
"",
PROJECT_CODE_1,
SCAN_CODE_1,
"git_repo_url",
"develop"
).shouldNotBeNull().run {
error shouldBe "Field git_repo_url: there was an issue executing command: timeout 200 git ls-remote 'ssh " +
"git repo' 2>&1. Exit status: 128. Output: Repository not found The requested repository does not " +
"exist, or you do not have permission to access it. fatal: Could not read from remote repository. " +
"Please make sure you have the correct access rights and the repository exists."
}
}

"A file can be marked as identified" {
service.markAsIdentified(
"",
Expand Down
2 changes: 1 addition & 1 deletion plugins/scanners/fossid/src/main/kotlin/FossId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ class FossId internal constructor(
reference
).checkResponse("create scan")

val scanId = response.data?.get("scan_id")
val scanId = response.data?.firstOrNull()

requireNotNull(scanId) { "Scan could not be created. The response was: ${response.message}." }

Expand Down
2 changes: 1 addition & 1 deletion plugins/scanners/fossid/src/test/kotlin/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.ossreviewtoolkit.clients.fossid.EntityResponseBody
import org.ossreviewtoolkit.clients.fossid.FossIdRestService
import org.ossreviewtoolkit.clients.fossid.FossIdServiceWithVersion
import org.ossreviewtoolkit.clients.fossid.MapResponseBody

Check warning on line 32 in plugins/scanners/fossid/src/test/kotlin/TestUtils.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Unused import directive

Unused import directive
import org.ossreviewtoolkit.clients.fossid.PolymorphicInt
import org.ossreviewtoolkit.clients.fossid.PolymorphicList
import org.ossreviewtoolkit.clients.fossid.PolymorphicResponseBody
Expand Down Expand Up @@ -549,7 +549,7 @@
): FossIdServiceWithVersion {
coEvery {
createScan(USER, API_KEY, projectCode, scanCode, vcsInfo.url, vcsInfo.revision, comment)
} returns MapResponseBody(status = 1, data = mapOf("scan_id" to SCAN_ID.toString()))
} returns PolymorphicResponseBody(status = 1, data = PolymorphicList(listOf(SCAN_ID.toString())))
return this
}

Expand Down
Loading