Skip to content

Commit 5733c0e

Browse files
committed
chore: add UTs for token authentication
1 parent ae7ed67 commit 5733c0e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/test/kotlin/com/coder/toolbox/sdk/CoderRestClientTest.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class CoderRestClientTest {
225225
val client = CoderRestClient(context, URL(url), "token")
226226
assertEquals(user.username, runBlocking { client.me() }.username)
227227

228-
val tests = listOf("invalid", null)
228+
val tests = listOf("invalid")
229229
tests.forEach { token ->
230230
val ex =
231231
assertFailsWith(
@@ -238,6 +238,26 @@ class CoderRestClientTest {
238238
srv.stop(0)
239239
}
240240

241+
@Test
242+
fun `exception is raised when token is required for authentication and token value is null or empty`() {
243+
listOf("", null).forEach { token ->
244+
val ex =
245+
assertFailsWith(
246+
exceptionClass = IllegalStateException::class,
247+
block = {
248+
runBlocking {
249+
CoderRestClient(
250+
context,
251+
URI.create("https://coder.com").toURL(),
252+
token
253+
).me()
254+
}
255+
},
256+
)
257+
assertEquals(ex.message, "Token is required for https://coder.com deployment")
258+
}
259+
}
260+
241261
@Test
242262
fun testGetsWorkspaces() {
243263
val tests =

0 commit comments

Comments
 (0)