Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae6b9c5

Browse files
committed
Add token test
1 parenta0d581c commitae6b9c5

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎src/test/kotlin/com/coder/gateway/sdk/CoderRestClientTest.kt‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,42 @@ class CoderRestClientTest {
158158
}
159159
}
160160

161+
@Test
162+
funtestToken() {
163+
val user=DataGen.user()
164+
val (srv, url)= mockServer()
165+
srv.createContext(
166+
"/api/v2/users/me",
167+
BaseHttpHandler("GET") { exchange->
168+
if (exchange.requestHeaders.getFirst("Coder-Session-Token")!="token") {
169+
val response=Response("Unauthorized","You do not have permission to the requested resource")
170+
val body= moshi.adapter(Response::class.java).toJson(response).toByteArray()
171+
exchange.sendResponseHeaders(HttpURLConnection.HTTP_UNAUTHORIZED, body.size.toLong())
172+
exchange.responseBody.write(body)
173+
}else {
174+
val body= moshi.adapter(User::class.java).toJson(user).toByteArray()
175+
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, body.size.toLong())
176+
exchange.responseBody.write(body)
177+
}
178+
},
179+
)
180+
181+
val client=CoderRestClient(URL(url),"token")
182+
assertEquals(user.username, client.me().username)
183+
184+
val tests=listOf("invalid",null)
185+
tests.forEach { token->
186+
val ex=
187+
assertFailsWith(
188+
exceptionClass=APIResponseException::class,
189+
block= {CoderRestClient(URL(url), token).me() },
190+
)
191+
assertEquals(true, ex.isUnauthorized)
192+
}
193+
194+
srv.stop(0)
195+
}
196+
161197
@Test
162198
funtestGetsWorkspaces() {
163199
val tests=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp