|
8 | 8 | import io.micronaut.http.HttpResponse; |
9 | 9 | import io.micronaut.http.HttpStatus; |
10 | 10 | import io.micronaut.http.client.HttpClient; |
| 11 | +import io.micronaut.http.client.exceptions.HttpClientResponseException; |
11 | 12 | import io.micronaut.http.client.annotation.Client; |
12 | 13 | import io.micronaut.security.authentication.UsernamePasswordCredentials; |
13 | 14 | import io.micronaut.security.token.render.BearerAccessRefreshToken; |
@@ -311,4 +312,22 @@ private String login(String username) { |
311 | 312 | BearerAccessRefreshToken bearer = rsp.body(); |
312 | 313 | return bearer.getAccessToken(); |
313 | 314 | } |
| 315 | + |
| 316 | + @Test |
| 317 | + void login_failsWithEmptyPassword() { |
| 318 | + UsernamePasswordCredentials creds = new UsernamePasswordCredentials("person1@test.io", ""); |
| 319 | + HttpRequest<?> request = HttpRequest.POST("/api/login", creds); |
| 320 | + HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> |
| 321 | + client.toBlocking().exchange(request, BearerAccessRefreshToken.class)); |
| 322 | + assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatus()); |
| 323 | + } |
| 324 | + |
| 325 | + @Test |
| 326 | + void login_failsWithEmptyUsername() { |
| 327 | + UsernamePasswordCredentials creds = new UsernamePasswordCredentials("", "test"); |
| 328 | + HttpRequest<?> request = HttpRequest.POST("/api/login", creds); |
| 329 | + HttpClientResponseException exception = assertThrows(HttpClientResponseException.class, () -> |
| 330 | + client.toBlocking().exchange(request, BearerAccessRefreshToken.class)); |
| 331 | + assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatus()); |
| 332 | + } |
314 | 333 | } |
0 commit comments