mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
Android agent to always send the platform field on enrollment (#43809)
This commit is contained in:
parent
7fc259c895
commit
5d0a69f276
3 changed files with 13 additions and 2 deletions
|
|
@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlinx.serialization.EncodeDefault
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
@ -438,6 +439,9 @@ object ApiClient : CertificateApiClient {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @EncodeDefault is marked @ExperimentalSerializationApi, but it has shipped in kotlinx.serialization since 1.3 (2022)
|
||||||
|
// and is widely used and reliable in production. The opt-in only acknowledges that the API shape could change in a future version.
|
||||||
|
@OptIn(kotlinx.serialization.ExperimentalSerializationApi::class)
|
||||||
@Serializable
|
@Serializable
|
||||||
data class EnrollRequest(
|
data class EnrollRequest(
|
||||||
@SerialName("enroll_secret")
|
@SerialName("enroll_secret")
|
||||||
|
|
@ -446,6 +450,7 @@ data class EnrollRequest(
|
||||||
val hardwareUUID: String,
|
val hardwareUUID: String,
|
||||||
@SerialName("hardware_serial")
|
@SerialName("hardware_serial")
|
||||||
val hardwareSerial: String,
|
val hardwareSerial: String,
|
||||||
|
@EncodeDefault(EncodeDefault.Mode.ALWAYS)
|
||||||
@SerialName("platform")
|
@SerialName("platform")
|
||||||
val platform: String = "android",
|
val platform: String = "android",
|
||||||
@SerialName("computer_name")
|
@SerialName("computer_name")
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,15 @@ class ApiClientReenrollTest {
|
||||||
assertTrue("First call should succeed", firstResult.isSuccess)
|
assertTrue("First call should succeed", firstResult.isSuccess)
|
||||||
assertEquals(2, mockWebServer.requestCount) // enroll + config
|
assertEquals(2, mockWebServer.requestCount) // enroll + config
|
||||||
|
|
||||||
// Verify first enrollment used the enroll secret
|
// Verify first enrollment used the enroll secret and sent platform="android" on the wire
|
||||||
val firstEnroll = mockWebServer.takeRequest()
|
val firstEnroll = mockWebServer.takeRequest()
|
||||||
assertEquals("/api/fleet/orbit/enroll", firstEnroll.path)
|
assertEquals("/api/fleet/orbit/enroll", firstEnroll.path)
|
||||||
assertTrue(firstEnroll.body.readUtf8().contains("test-enroll-secret"))
|
val firstEnrollBody = firstEnroll.body.readUtf8()
|
||||||
|
assertTrue(firstEnrollBody.contains("test-enroll-secret"))
|
||||||
|
assertTrue(
|
||||||
|
"Expected platform=\"android\" in enroll body, got: $firstEnrollBody",
|
||||||
|
firstEnrollBody.contains("\"platform\":\"android\""),
|
||||||
|
)
|
||||||
|
|
||||||
// Verify first config used first-node-key
|
// Verify first config used first-node-key
|
||||||
val firstConfig = mockWebServer.takeRequest()
|
val firstConfig = mockWebServer.takeRequest()
|
||||||
|
|
|
||||||
1
android/changes/43807-android-enroll-platform
Normal file
1
android/changes/43807-android-enroll-platform
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
- Fixed Android agent to always send the `platform` field on enrollment so the device is registered with the correct platform.
|
||||||
Loading…
Reference in a new issue