Skip to content
Snippets Groups Projects
Commit 893241e6 authored by Martin Weise's avatar Martin Weise
Browse files

Merge branch 'dev' into 'master'

Fixed the sync

See merge request !377
parents 616e4a7b 12057328
No related branches found
No related tags found
3 merge requests!380Master,!378Master,!377Fixed the sync
No preview for this file type
......@@ -2,6 +2,7 @@ package at.tuwien.handlers;
import at.tuwien.api.error.ApiErrorDto;
import at.tuwien.exception.*;
import com.auth0.jwt.exceptions.TokenExpiredException;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpHeaders;
......@@ -16,6 +17,20 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep
@ControllerAdvice
public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
@Hidden
@ResponseStatus(code = HttpStatus.UNAUTHORIZED)
@ExceptionHandler(TokenExpiredException.class)
public ResponseEntity<ApiErrorDto> handle(TokenExpiredException e) {
final HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/problem+json");
final ApiErrorDto response = ApiErrorDto.builder()
.status(HttpStatus.UNAUTHORIZED)
.message(e.getLocalizedMessage())
.code("error.token.expired")
.build();
return new ResponseEntity<>(response, headers, response.getStatus());
}
@Hidden
@ResponseStatus(code = HttpStatus.NOT_FOUND)
@ExceptionHandler(AccessNotFoundException.class)
......@@ -471,7 +486,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
final ApiErrorDto response = ApiErrorDto.builder()
.status(annotation.code())
.message(message)
.code(annotation.reason())
.code(exceptionClass.getAnnotation(ResponseStatus.class).reason())
.build();
return new ResponseEntity<>(response, headers, response.getStatus());
}
......
......@@ -3,6 +3,7 @@ package at.tuwien.handlers;
import at.tuwien.api.error.ApiErrorDto;
import at.tuwien.exception.*;
import at.tuwien.test.AbstractUnitTest;
import com.auth0.jwt.exceptions.TokenExpiredException;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
......@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import java.io.IOException;
import java.lang.reflect.Method;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
......@@ -55,6 +57,19 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
}
}
@Test
public void handle_tokenExpiredException_succeeds() {
/* test */
final ResponseEntity<ApiErrorDto> response = apiExceptionHandler.handle(new TokenExpiredException("msg", Instant.now()));
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
final ApiErrorDto body = response.getBody();
assertNotNull(body);
assertNotNull(body.getMessage());
assertEquals(HttpStatus.UNAUTHORIZED, body.getStatus());
assertEquals("error.token.expired", body.getCode());
}
@Test
public void handle_accessNotFoundException_succeeds() {
......@@ -68,7 +83,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.access.missing", body.getCode());
}
@Test
public void handle_accountNotSetupException_succeeds() {
......@@ -82,7 +96,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.user.setup", body.getCode());
}
@Test
public void handle_analyseServiceException_succeeds() {
......@@ -96,7 +109,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.analyse.invalid", body.getCode());
}
@Test
public void handle_authServiceConnectionException_succeeds() {
......@@ -110,7 +122,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.auth.connection", body.getCode());
}
@Test
public void handle_authServiceException_succeeds() {
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -141,23 +141,6 @@
</v-form>
<v-main>
<v-container>
<div
v-cloak>
<v-alert
v-if="isNotFinishedAccountSetup"
border="start"
color="info"
class="mb-4">
{{ $t('pages.settings.subpages.authentication.setup.text') }}
<v-btn
variant="flat"
size="small"
to="/user/authentication">
{{ $t('pages.settings.subpages.authentication.setup.action') }}
</v-btn>
.
</v-alert>
</div>
<JumboBox
v-if="error"
:title="$t(errorCodeKey(error).title, { resource })"
......@@ -269,15 +252,6 @@ export default {
commitShort () {
return this.$config.public.commit.substr(0, 8)
},
isNotFinishedAccountSetup () {
if (!this.cacheUser) {
return false
}
if (!('setup_finished' in this.cacheUser)) {
return true
}
return this.cacheUser.setup_finished === false
},
error () {
if (this.identifier) {
return null
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment