Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Fixed

- fix class cast exception during signature verification
- the correct CLI signature for Windows is now downloaded

## 0.5.1 - 2025-07-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=0.5.1
version=0.5.2
group=com.coder.toolbox
name=coder-toolbox
12 changes: 6 additions & 6 deletions src/main/kotlin/com/coder/toolbox/cli/CoderCLIManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ class CoderCLIManager(
}

else -> {
UnsignedBinaryExecutionDeniedException((result as Failed).error.message)
val failure = result as DownloadResult.Failed
val failure = result as Failed
UnsignedBinaryExecutionDeniedException(result.error.message)
context.logger.error(failure.error, "Failed to verify signature for ${cliResult.dst}")
}
}
Expand Down Expand Up @@ -467,7 +467,7 @@ class CoderCLIManager(
*/
private fun writeSSHConfig(contents: String?) {
if (contents != null) {
if (!context.settingsStore.sshConfigPath.isNullOrBlank()) {
if (context.settingsStore.sshConfigPath.isNotBlank()) {
val sshConfPath = Path.of(context.settingsStore.sshConfigPath)
sshConfPath.parent.toFile().mkdirs()
sshConfPath.toFile().writeText(contents)
Expand All @@ -492,9 +492,9 @@ class CoderCLIManager(
throw MissingVersionException("No version found in output")
}
return SemVer.parse(json.version)
} catch (exception: JsonDataException) {
} catch (_: JsonDataException) {
throw MissingVersionException("No version found in output")
} catch (exception: EOFException) {
} catch (_: EOFException) {
throw MissingVersionException("No version found in output")
}
}
Expand Down Expand Up @@ -532,7 +532,7 @@ class CoderCLIManager(
val buildVersion =
try {
SemVer.parse(rawBuildVersion)
} catch (e: InvalidVersionException) {
} catch (_: InvalidVersionException) {
context.logger.info("Got invalid build version: $rawBuildVersion")
return null
}
Expand Down
56 changes: 17 additions & 39 deletions src/main/kotlin/com/coder/toolbox/store/CoderSettingsStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -250,42 +250,17 @@ class CoderSettingsStore(
/**
* Return the name of the binary (with extension) for the provided OS and architecture.
*/
private fun getCoderCLIForOS(
os: OS?,
arch: Arch?,
): String {
private fun getCoderCLIForOS(os: OS?, arch: Arch?): String {
logger.debug("Resolving binary for $os $arch")
return buildCoderFileName(os, arch)
}

/**
* Return the name of the signature file (.asc) for the provided OS and architecture.
*/
private fun getCoderSignatureForOS(
os: OS?,
arch: Arch?,
): String {
logger.debug("Resolving signature for $os $arch")
return buildCoderFileName(os, arch, true)
}

/**
* Build the coder file name based on OS, architecture, and whether it's a signature file.
*/
private fun buildCoderFileName(
os: OS?,
arch: Arch?,
isSignature: Boolean = false
): String {
if (os == null) {
logger.error("Could not resolve client OS and architecture, defaulting to WINDOWS AMD64")
return if (isSignature) "coder-windows-amd64.asc" else "coder-windows-amd64.exe"
}

val osName = when (os) {
OS.WINDOWS -> "windows"
OS.LINUX -> "linux"
OS.MAC -> "darwin"
val (osName, extension) = when (os) {
OS.WINDOWS -> "windows" to ".exe"
OS.LINUX -> "linux" to ""
OS.MAC -> "darwin" to ""
null -> {
logger.error("Could not resolve client OS and architecture, defaulting to WINDOWS AMD64")
return "coder-windows-amd64.exe"
}
}

val archName = when (arch) {
Expand All @@ -295,14 +270,17 @@ class CoderSettingsStore(
else -> "amd64" // default fallback
}

val extension = if (isSignature) ".asc" else when (os) {
OS.WINDOWS -> ".exe"
OS.LINUX, OS.MAC -> ""
}

return "coder-$osName-$archName$extension"
}

/**
* Return the name of the signature file (.asc) for the provided OS and architecture.
*/
private fun getCoderSignatureForOS(os: OS?, arch: Arch?): String {
logger.debug("Resolving signature for $os $arch")
return "${getCoderCLIForOS(os, arch)}.asc"
}

/**
* Append the host to the path. For example, foo/bar could become
* foo/bar/dev.coder.com-8080.
Expand Down
14 changes: 3 additions & 11 deletions src/test/kotlin/com/coder/toolbox/store/CoderSettingsStoreTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ class CoderSettingsStoreTest {

@Test
fun `Default CLI and signature for Windows AMD64`() =
assertBinaryAndSignature("Windows 10", "amd64", "coder-windows-amd64.exe", "coder-windows-amd64.asc")
assertBinaryAndSignature("Windows 10", "amd64", "coder-windows-amd64.exe", "coder-windows-amd64.exe.asc")

@Test
fun `Default CLI and signature for Windows ARM64`() =
assertBinaryAndSignature("Windows 10", "aarch64", "coder-windows-arm64.exe", "coder-windows-arm64.asc")

@Test
fun `Default CLI and signature for Windows ARMV7`() =
assertBinaryAndSignature("Windows 10", "armv7l", "coder-windows-armv7.exe", "coder-windows-armv7.asc")
assertBinaryAndSignature("Windows 10", "aarch64", "coder-windows-arm64.exe", "coder-windows-arm64.exe.asc")

@Test
fun `Default CLI and signature for Linux AMD64`() =
Expand All @@ -65,13 +61,9 @@ class CoderSettingsStoreTest {
fun `Default CLI and signature for Mac ARM64`() =
assertBinaryAndSignature("Mac OS X", "aarch64", "coder-darwin-arm64", "coder-darwin-arm64.asc")

@Test
fun `Default CLI and signature for Mac ARMV7`() =
assertBinaryAndSignature("Mac OS X", "armv7l", "coder-darwin-armv7", "coder-darwin-armv7.asc")

@Test
fun `Default CLI and signature for unknown OS and Arch`() =
assertBinaryAndSignature(null, null, "coder-windows-amd64.exe", "coder-windows-amd64.asc")
assertBinaryAndSignature(null, null, "coder-windows-amd64.exe", "coder-windows-amd64.exe.asc")

@Test
fun `Default CLI and signature for unknown Arch fallback on Linux`() =
Expand Down
Loading