11package io.ably.lib.uts.integration.standard.realtime
22
3+ import io.ably.lib.realtime.AblyRealtime
34import io.ably.lib.realtime.ConnectionState
45import io.ably.lib.rest.Auth
56import io.ably.lib.uts.infra.awaitState
67import io.ably.lib.uts.infra.integration.SandboxApp
7- import io.ably.lib.uts.infra.unit.TestRealtimeClient
8+ import io.ably.lib.uts.infra.unit.ClientOptionsBuilder
89import io.ably.lib.uts.infra.unit.TestRestClient
910import kotlinx.coroutines.runBlocking
1011import kotlinx.coroutines.test.runTest
@@ -29,6 +30,14 @@ import kotlin.time.Duration.Companion.seconds
2930 * server. A REST client signs the TokenRequest; a separate realtime client exchanges it (through
3031 * its `authCallback`) for a token and connects, proving the server accepted it.
3132 *
33+ * The two clients deliberately sit on different sides of the seam. The **minting** client — the
34+ * RSA9 surface under test — goes through [TestRestClient], so on the server UTS leg it exercises
35+ * `createTokenRequest` through the server door, the shape a real server has: mint native tokens
36+ * for others. The **consuming** client models the device those tokens are minted for, so it is
37+ * always a plain core client: a client may not authenticate *itself* with a native token while
38+ * declaring the server side (realtime rejects that with 40167 — on token auth the side must come
39+ * from the signed x-ably-clientType claim, which the native token format cannot carry).
40+ *
3241 * Spec points: RSA9, RSA9a, RSA9g. Source spec: `realtime/integration/auth/token_request_test.md`.
3342 */
3443@TestInstance(TestInstance .Lifecycle .PER_CLASS )
@@ -46,6 +55,10 @@ class TokenRequestTest {
4655 if (::app.isInitialized) app.delete()
4756 }
4857
58+ /* * The token-consuming client — a plain core client on every leg; see the class doc. */
59+ private fun tokenConsumingClient (block : ClientOptionsBuilder .() -> Unit ): AblyRealtime =
60+ AblyRealtime (ClientOptionsBuilder ().apply (block))
61+
4962 /* *
5063 * @UTS realtime/integration/RSA9a/token-request-server-accepted-0
5164 * @UTS realtime/integration/RSA9g/token-request-server-accepted-0
@@ -59,7 +72,7 @@ class TokenRequestTest {
5972 }
6073
6174 // Client B connects using a TokenRequest produced by client A.
62- val client = TestRealtimeClient {
75+ val client = tokenConsumingClient {
6376 authCallback = Auth .TokenCallback { params -> creator.auth.createTokenRequest(params, null ) }
6477 realtimeHost = SandboxApp .sandboxHost
6578 restHost = SandboxApp .sandboxHost
@@ -94,7 +107,7 @@ class TokenRequestTest {
94107
95108 // The TokenRequest is signed with the specific clientId, producing a token that
96109 // authenticates the client with that identity.
97- val client = TestRealtimeClient {
110+ val client = tokenConsumingClient {
98111 authCallback = Auth .TokenCallback { params ->
99112 params.clientId = testClientId
100113 creator.auth.createTokenRequest(params, null )
0 commit comments