diff --git a/iam-login-service/src/main/java/it/infn/mw/iam/api/aup/AupSignatureController.java b/iam-login-service/src/main/java/it/infn/mw/iam/api/aup/AupSignatureController.java index 170ae7874..c2c24cb48 100644 --- a/iam-login-service/src/main/java/it/infn/mw/iam/api/aup/AupSignatureController.java +++ b/iam-login-service/src/main/java/it/infn/mw/iam/api/aup/AupSignatureController.java @@ -29,12 +29,14 @@ import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -43,6 +45,7 @@ import it.infn.mw.iam.api.aup.error.AupSignatureNotFoundError; import it.infn.mw.iam.api.aup.model.AupSignatureConverter; import it.infn.mw.iam.api.aup.model.AupSignatureDTO; +import it.infn.mw.iam.api.aup.model.AupSignaturePatchRequestDTO; import it.infn.mw.iam.api.common.ErrorDTO; import it.infn.mw.iam.audit.events.aup.AupSignatureDeletedEvent; import it.infn.mw.iam.audit.events.aup.AupSignedEvent; @@ -71,6 +74,7 @@ public class AupSignatureController { private final TimeProvider timeProvider; private final ApplicationEventPublisher eventPublisher; private final NotificationFactory notificationFactory; + public AupSignatureController(AupSignatureConverter conv, AccountUtils utils, IamAupSignatureRepository signatureRepo, IamAupRepository aupRepo, TimeProvider timeProvider, ApplicationEventPublisher publisher, NotificationFactory notificationFactory) { @@ -141,6 +145,7 @@ public AupSignatureDTO getSignatureForAccount(@PathVariable String accountId) @ResponseStatus(value = HttpStatus.CREATED) @PreAuthorize("#iam.hasScope('iam:admin.write') or #iam.hasDashboardRole('ROLE_ADMIN')") public AupSignatureDTO updateSignatureForAccount(@PathVariable String accountId, + @RequestBody(required = false) @Validated AupSignaturePatchRequestDTO dto, Authentication authentication) throws AccountNotFoundException { Optional updaterAccount = accountUtils.getAuthenticatedUserAccount(); @@ -148,9 +153,11 @@ public AupSignatureDTO updateSignatureForAccount(@PathVariable String accountId, IamAccount account = accountUtils.getByAccountId(accountId) .orElseThrow(accountNotFoundException(format(ACCOUNT_NOT_FOUND_FOR_ID_MESSAGE, accountId))); IamAup aup = aupRepo.findDefaultAup().orElseThrow(aupNotFoundException()); - Date now = new Date(timeProvider.currentTimeMillis()); - IamAupSignature signature = signatureRepo.createSignatureForAccount(aup, account, now); + Date signatureTime = + dto == null ? new Date(timeProvider.currentTimeMillis()) : dto.getSignatureTime(); + IamAupSignature signature = + signatureRepo.createSignatureForAccount(aup, account, signatureTime); String principal = null; diff --git a/iam-login-service/src/main/java/it/infn/mw/iam/api/aup/model/AupSignaturePatchRequestDTO.java b/iam-login-service/src/main/java/it/infn/mw/iam/api/aup/model/AupSignaturePatchRequestDTO.java new file mode 100644 index 000000000..f570d8dc1 --- /dev/null +++ b/iam-login-service/src/main/java/it/infn/mw/iam/api/aup/model/AupSignaturePatchRequestDTO.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package it.infn.mw.iam.api.aup.model; + +import java.util.Date; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import it.infn.mw.iam.api.scim.controller.utils.JsonDateSerializer; + +public class AupSignaturePatchRequestDTO { + + @JsonSerialize(using = JsonDateSerializer.class) + Date signatureTime; + + public AupSignaturePatchRequestDTO() { + // empty constructor + } + + public void setSignatureTime(Date signatureTime) { + this.signatureTime = signatureTime; + } + + + public Date getSignatureTime() { + return signatureTime; + } + +} diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/AupSignatureIntegrationTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/AupSignatureIntegrationTests.java index 67167bc02..3b24ebf01 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/AupSignatureIntegrationTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/api/aup/AupSignatureIntegrationTests.java @@ -15,6 +15,7 @@ */ package it.infn.mw.iam.test.api.aup; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.springframework.http.MediaType.APPLICATION_JSON; @@ -26,6 +27,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.time.Instant; +import java.util.Calendar; import java.util.Date; import java.util.NoSuchElementException; import java.util.Optional; @@ -42,9 +45,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; -import it.infn.mw.iam.api.aup.model.AccountDTO; -import it.infn.mw.iam.api.aup.model.AupConverter; import it.infn.mw.iam.api.aup.model.AupSignatureDTO; +import it.infn.mw.iam.api.aup.model.AupSignaturePatchRequestDTO; import it.infn.mw.iam.core.user.IamAccountService; import it.infn.mw.iam.persistence.model.IamAccount; import it.infn.mw.iam.persistence.model.IamAup; @@ -79,9 +81,6 @@ public class AupSignatureIntegrationTests extends AupTestSupport { @Autowired private IamAccountRepository accountRepo; - @Autowired - private AupConverter aupConverter; - @Autowired private MockMvc mvc; @@ -91,14 +90,38 @@ public class AupSignatureIntegrationTests extends AupTestSupport { @Autowired private MockTimeProvider mockTimeProvider; + private IamAup aup; + + private Date getCurrentDate() { + return Date.from(Instant.ofEpochMilli(mockTimeProvider.currentTimeMillis())); + } + + private void initCurrentDate() { + mockTimeProvider.setTime((new Date()).getTime()); + } + + private void addToCurrentDate(int milliSecs) { + mockTimeProvider.setTime(DateUtils.addMilliseconds(getCurrentDate(), milliSecs).getTime()); + } + + private Date getCurrentDateAdd(int field, int amount) { + Calendar calendar = Calendar.getInstance(); + calendar.add(field, amount); + return calendar.getTime(); + } + @Before public void setup() { mockOAuth2Filter.cleanupSecurityContext(); + initCurrentDate(); + aup = buildDefaultAup(); + aupRepo.save(aup); } @After public void cleanupOAuthUser() { mockOAuth2Filter.cleanupSecurityContext(); + aupRepo.delete(aup); } @Test @@ -114,6 +137,7 @@ public void signAupSignatureRequiresAuthenticatedUser() throws Exception { @Test @WithMockUser(username = "test", roles = {"USER"}) public void getAupSignatureWithUndefinedAupReturns404() throws Exception { + aupRepo.deleteAll(); mvc.perform(get("/iam/aup/signature")) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.error", equalTo("AUP is not defined for this organization"))); @@ -122,8 +146,6 @@ public void getAupSignatureWithUndefinedAupReturns404() throws Exception { @Test @WithMockUser(username = "test", roles = {"USER"}) public void getAupSignatureWithNoSignatureRecordReturns404() throws Exception { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); mvc.perform(get("/iam/aup/signature")) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.error", equalTo("AUP signature not found for user 'test'"))); @@ -132,13 +154,6 @@ public void getAupSignatureWithNoSignatureRecordReturns404() throws Exception { @Test @WithMockUser(username = "test", roles = {"USER"}) public void signatureCreationReturns204() throws Exception { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); - - Date now = new Date(); - - mockTimeProvider.setTime(now.getTime()); - mvc.perform(post("/iam/aup/signature")).andExpect(status().isCreated()); String sigString = mvc.perform(get("/iam/aup/signature")) @@ -153,10 +168,10 @@ public void signatureCreationReturns204() throws Exception { .getContentAsString(); AupSignatureDTO sig = mapper.readValue(sigString, AupSignatureDTO.class); - assertThat(sig.getSignatureTime(), new DateEqualModulo1Second(now)); + assertThat(sig.getSignatureTime(), new DateEqualModulo1Second(getCurrentDate())); - Date then = new Date(); - mockTimeProvider.setTime(then.getTime()); + addToCurrentDate(1000); + Date expectedDate = getCurrentDate(); mvc.perform(post("/iam/aup/signature")).andExpect(status().isCreated()); sigString = mvc.perform(get("/iam/aup/signature")) @@ -171,92 +186,114 @@ public void signatureCreationReturns204() throws Exception { .getContentAsString(); sig = mapper.readValue(sigString, AupSignatureDTO.class); - assertThat(sig.getSignatureTime(), new DateEqualModulo1Second(then)); + assertThat(sig.getSignatureTime(), equalTo(expectedDate)); + } + + @Test + @WithMockUser(username = "admin", roles = {"ADMIN", "USER"}) + public void signatureOnBehalfWithoutRequestBodyWorksWhenUserHasNoSignature() + throws Exception, NoSuchElementException { + + IamAccount testAccount = accountRepo.findByUsername("test").orElseThrow(); + + Optional signature = + aupSignatureRepo.findSignatureForAccount(aup, testAccount); + assertThat(signature.isPresent(), equalTo(false)); + + mvc.perform(patch("/iam/aup/signature/{accountId}", testAccount.getUuid())) + .andExpect(status().isCreated()); + assertThat(aupSignatureRepo.findSignatureForAccount(aup, testAccount).isPresent(), + equalTo(true)); + + AupSignatureDTO responseDTO = + mapper.readValue(mvc.perform(get("/iam/aup/signature/{accountId}", testAccount.getUuid())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.aup").exists()) + .andExpect(jsonPath("$.account.uuid").exists()) + .andExpect(jsonPath("$.account.uuid", equalTo(testAccount.getUuid()))) + .andExpect(jsonPath("$.account.username", equalTo(testAccount.getUsername()))) + .andExpect(jsonPath("$.account.name", equalTo(testAccount.getUserInfo().getName()))) + .andExpect(jsonPath("$.signatureTime").exists()) + .andReturn() + .getResponse() + .getContentAsString(), AupSignatureDTO.class); + + assertThat(responseDTO.getSignatureTime(), equalTo(getCurrentDate())); } @Test @WithMockUser(username = "admin", roles = {"ADMIN", "USER"}) - public void signatureOnBehalfWorks() throws Exception, NoSuchElementException { + public void signatureOnBehalfWithRequestBodyWorksWhenUserHasNoSignature() + throws Exception, NoSuchElementException { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); IamAccount testAccount = accountRepo.findByUsername("test").orElseThrow(); - Date now = new Date(); - mockTimeProvider.setTime(now.getTime()); Optional signature = aupSignatureRepo.findSignatureForAccount(aup, testAccount); - assertThat(signature.isEmpty(), equalTo(true)); + assertThat(signature.isPresent(), equalTo(false)); - AupSignatureDTO dto = new AupSignatureDTO(); - dto.setAup(aupConverter.dtoFromEntity(aup)); - AccountDTO accountDto = new AccountDTO(); - accountDto.setName(testAccount.getUserInfo().getName()); - accountDto.setUsername(testAccount.getUsername()); - accountDto.setUuid(testAccount.getUuid()); - dto.setAccount(accountDto); - dto.setSignatureTime(new Date()); + Date updatedSignature = getCurrentDateAdd(Calendar.HOUR, 2); + AupSignaturePatchRequestDTO dto = new AupSignaturePatchRequestDTO(); + dto.setSignatureTime(updatedSignature); mvc.perform(patch("/iam/aup/signature/{accountId}", testAccount.getUuid()) .content(mapper.writeValueAsString(dto)) .contentType(APPLICATION_JSON)).andExpect(status().isCreated()); - assertThat(aupSignatureRepo.findSignatureForAccount(aup, testAccount).isEmpty(), - equalTo(false)); - - mvc.perform(get("/iam/aup/signature/{accountId}", testAccount.getUuid())) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.aup").exists()) - .andExpect(jsonPath("$.account.uuid").exists()) - .andExpect(jsonPath("$.account.username", equalTo("test"))) - .andExpect(jsonPath("$.account.name", equalTo("Test User"))) - .andExpect(jsonPath("$.signatureTime").exists()); + assertThat(aupSignatureRepo.findSignatureForAccount(aup, testAccount).isPresent(), + equalTo(true)); + + AupSignatureDTO responseDTO = + mapper.readValue(mvc.perform(get("/iam/aup/signature/{accountId}", testAccount.getUuid())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.aup").exists()) + .andExpect(jsonPath("$.account.uuid").exists()) + .andExpect(jsonPath("$.account.uuid", equalTo(testAccount.getUuid()))) + .andExpect(jsonPath("$.account.username", equalTo(testAccount.getUsername()))) + .andExpect(jsonPath("$.account.name", equalTo(testAccount.getUserInfo().getName()))) + .andExpect(jsonPath("$.signatureTime").exists()) + .andReturn() + .getResponse() + .getContentAsString(), AupSignatureDTO.class); + assertThat(responseDTO.getSignatureTime(), equalTo(updatedSignature)); } @Test @WithMockOAuthUser(scopes = "iam:admin.write", clientId = "client-cred") - public void signatureOnBehalfWithClientCredentialsWorks() throws Exception, NoSuchElementException { + public void signatureOnBehalfWithClientCredentialsWorks() + throws Exception, NoSuchElementException { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); IamAccount testAccount = accountRepo.findByUsername("test").orElseThrow(); - Date now = new Date(); - mockTimeProvider.setTime(now.getTime()); Optional signature = aupSignatureRepo.findSignatureForAccount(aup, testAccount); - assertThat(signature.isEmpty(), equalTo(true)); + assertThat(signature.isPresent(), equalTo(false)); - AupSignatureDTO dto = new AupSignatureDTO(); - dto.setAup(aupConverter.dtoFromEntity(aup)); - AccountDTO accountDto = new AccountDTO(); - accountDto.setName(testAccount.getUserInfo().getName()); - accountDto.setUsername(testAccount.getUsername()); - accountDto.setUuid(testAccount.getUuid()); - dto.setAccount(accountDto); - dto.setSignatureTime(new Date()); + mvc.perform(patch("/iam/aup/signature/{accountId}", testAccount.getUuid())) + .andExpect(status().isCreated()); + + signature = aupSignatureRepo.findSignatureForAccount(aup, testAccount); + assertThat(signature.isPresent(), equalTo(true)); + + aupSignatureRepo.deleteById(signature.get().getId()); + + AupSignaturePatchRequestDTO dto = new AupSignaturePatchRequestDTO(); + dto.setSignatureTime(getCurrentDate()); mvc.perform(patch("/iam/aup/signature/{accountId}", testAccount.getUuid()) .content(mapper.writeValueAsString(dto)) .contentType(APPLICATION_JSON)).andExpect(status().isCreated()); - assertThat(aupSignatureRepo.findSignatureForAccount(aup, testAccount).isEmpty(), - equalTo(false)); + assertThat(aupSignatureRepo.findSignatureForAccount(aup, testAccount).isPresent(), + equalTo(true)); } @Test @WithMockUser(username = "admin", roles = {"ADMIN", "USER"}) public void aupRemovalForSingleUser() throws Exception { - IamAup aup = buildDefaultAup(); - - mvc - .perform( - post("/iam/aup").contentType(APPLICATION_JSON).content(mapper.writeValueAsString(aup))) - .andExpect(status().isCreated()); - mvc.perform(post("/iam/aup/signature")).andExpect(status().isCreated()); @@ -276,43 +313,23 @@ public void aupRemovalForSingleUser() throws Exception { @Test @WithMockOAuthUser(scopes = "iam:admin.write", clientId = "client-cred") public void aupRemovalForSingleUserWithClientCredentialsWorks() throws Exception { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); - IamAccount testAccount = accountRepo.findByUsername("test").orElseThrow(); - Date now = new Date(); - mockTimeProvider.setTime(now.getTime()); - Optional signature = - aupSignatureRepo.findSignatureForAccount(aup, testAccount); - assertThat(signature.isEmpty(), equalTo(true)); + IamAccount testAccount = accountRepo.findByUsername("test").orElseThrow(); - AupSignatureDTO dto = new AupSignatureDTO(); - dto.setAup(aupConverter.dtoFromEntity(aup)); - AccountDTO accountDto = new AccountDTO(); - accountDto.setName(testAccount.getUserInfo().getName()); - accountDto.setUsername(testAccount.getUsername()); - accountDto.setUuid(testAccount.getUuid()); - dto.setAccount(accountDto); - dto.setSignatureTime(new Date()); + Optional signature = aupSignatureRepo.findSignatureForAccount(aup, testAccount); + assertThat(signature.isPresent(), equalTo(false)); + aupSignatureRepo.createSignatureForAccount(aup, testAccount, getCurrentDate()); - mvc.perform(patch("/iam/aup/signature/{accountId}", testAccount.getUuid()) - .content(mapper.writeValueAsString(dto)) - .contentType(APPLICATION_JSON)).andExpect(status().isCreated()); mvc.perform(delete("/iam/aup/signature/" + testAccount.getUuid())) .andExpect(status().isNoContent()); + signature = aupSignatureRepo.findSignatureForAccount(aup, testAccount); + assertThat(signature.isPresent(), equalTo(false)); } @Test @WithMockUser(username = "admin", roles = {"ADMIN", "USER"}) public void aupRemovalRemovesSignatureRecords() throws Exception { - IamAup aup = buildDefaultAup(); - - mvc - .perform( - post("/iam/aup").contentType(APPLICATION_JSON).content(mapper.writeValueAsString(aup))) - .andExpect(status().isCreated()); - mvc.perform(post("/iam/aup/signature")).andExpect(status().isCreated()); mvc.perform(delete("/iam/aup")).andExpect(status().isNoContent()); @@ -325,39 +342,24 @@ public void aupRemovalRemovesSignatureRecords() throws Exception { mvc.perform(get("/iam/aup/signature")) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.error", equalTo("AUP is not defined for this organization"))); - } @Test @WithMockUser(username = "admin", roles = {"ADMIN", "USER"}) public void accountRemovalRemovesSignatureRecords() throws Exception { - IamAup aup = buildDefaultAup(); - - mvc - .perform( - post("/iam/aup").contentType(APPLICATION_JSON).content(mapper.writeValueAsString(aup))) - .andExpect(status().isCreated()); - mvc.perform(post("/iam/aup/signature")).andExpect(status().isCreated()); IamAccount account = accountRepo.findByUsername("admin") .orElseThrow(() -> new AssertionError("Expected admin account not found")); accountService.deleteAccount(account); - - // if we get this far, the persistence layer is working as expected } @Test @WithMockUser(username = "test", roles = {"USER"}) public void normalUserCannotSeeOtherUserAup() throws Exception { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); - - Date now = new Date(); - mockTimeProvider.setTime(now.getTime()); mvc.perform(post("/iam/aup/signature")).andExpect(status().isCreated()); mvc.perform(get("/iam/aup/signature")).andExpect(status().isOk()); mvc.perform(get("/iam/aup/signature/" + TEST_USER_UUID)).andExpect(status().isOk()); @@ -366,13 +368,7 @@ public void normalUserCannotSeeOtherUserAup() throws Exception { @Test public void adminUserCanSeeOtherUserAup() throws Exception { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); - - Date now = new Date(); - - mockTimeProvider.setTime(now.getTime()); mvc.perform(post("/iam/aup/signature").with(user("test").roles("USER"))) .andExpect(status().isCreated()); mvc.perform(get("/iam/aup/signature").with(user("test").roles("USER"))) @@ -388,50 +384,47 @@ public void adminUserCanSeeOtherUserAup() throws Exception { @Test @WithMockUser(username = "admin", roles = {"USER", "ADMIN"}) public void signAupOnBehalfOfUserThatHasAlreadyASignature() throws Exception { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); - IamAccount testAccount = accountRepo.findByUsername("test").orElseThrow(); - Date now = new Date(); - mockTimeProvider.setTime(now.getTime()); - - IamAupSignature signature = aupSignatureRepo.createSignatureForAccount(aup, testAccount, now); - - mockTimeProvider.setTime(DateUtils.addMilliseconds(now, 1000).getTime()); - mvc.perform(get("/iam/aup/signature/{accountId}", TEST_USER_UUID)) - .andExpect(status().isOk()); + IamAccount testAccount = accountRepo.findByUsername("test").orElseThrow(); + IamAupSignature signature = + aupSignatureRepo.createSignatureForAccount(aup, testAccount, getCurrentDate()); - AupSignatureDTO resignedSignature = + // patch with no body => set signature to current Date + AupSignatureDTO signatureResponse = mapper.readValue(mvc.perform(patch("/iam/aup/signature/{accountId}", TEST_USER_UUID)) .andExpect(CREATED) .andReturn() .getResponse() .getContentAsString(), AupSignatureDTO.class); - assertThat(signature.getSignatureTime().compareTo(resignedSignature.getSignatureTime()) < 0, equalTo(true)); + assertThat(signatureResponse.getSignatureTime().compareTo(signature.getSignatureTime()), is(0)); - mvc.perform(get("/iam/aup/signature/{accountId}", TEST_USER_UUID)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.aup").exists()) - .andExpect(jsonPath("$.account.uuid").exists()) - .andExpect(jsonPath("$.account.username", equalTo("test"))) - .andExpect(jsonPath("$.account.name", equalTo("Test User"))) - .andExpect(jsonPath("$.signatureTime").exists()); + AupSignatureDTO dto = new AupSignatureDTO(); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.HOUR, 2); + dto.setSignatureTime(calendar.getTime()); + + AupSignatureDTO updatedSignature = mapper.readValue(mvc + .perform(patch("/iam/aup/signature/{accountId}", TEST_USER_UUID) + .content(mapper.writeValueAsString(dto)) + .contentType(APPLICATION_JSON)) + .andExpect(CREATED) + .andReturn() + .getResponse() + .getContentAsString(), AupSignatureDTO.class); + + assertThat(updatedSignature.getSignatureTime().compareTo(dto.getSignatureTime()), is(0)); } - + @Test @WithMockUser(username = "admin", roles = {"USER", "ADMIN"}) public void signAupOnBehalfOfUserThatHasNoSignature() throws Exception { - IamAup aup = buildDefaultAup(); - aupRepo.save(aup); mvc.perform(get("/iam/aup/signature/{accountId}", TEST_USER_UUID)) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.error", equalTo("AUP signature not found for user 'test'"))); - mvc - .perform(patch("/iam/aup/signature/{accountId}", TEST_USER_UUID)) - .andExpect(CREATED); + mvc.perform(patch("/iam/aup/signature/{accountId}", TEST_USER_UUID)).andExpect(CREATED); mvc.perform(get("/iam/aup/signature/{accountId}", TEST_USER_UUID)) .andExpect(status().isOk()) @@ -441,8 +434,7 @@ public void signAupOnBehalfOfUserThatHasNoSignature() throws Exception { .andExpect(jsonPath("$.account.name", equalTo("Test User"))) .andExpect(jsonPath("$.signatureTime").exists()); - mvc.perform(get("/iam/aup/signature/{accountId}", TEST_USER_UUID)) - .andExpect(status().isOk()); + mvc.perform(get("/iam/aup/signature/{accountId}", TEST_USER_UUID)).andExpect(status().isOk()); } diff --git a/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamAupSignatureRepositoryTests.java b/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamAupSignatureRepositoryTests.java index 4ca6bc649..f8d932c63 100644 --- a/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamAupSignatureRepositoryTests.java +++ b/iam-login-service/src/test/java/it/infn/mw/iam/test/repository/IamAupSignatureRepositoryTests.java @@ -61,7 +61,7 @@ public void signatureCreationWorks() { IamAccount testAccount = findTestAccount(); Date now = new Date(); - repo.createSignatureForAccount(aup, testAccount, new Date()); + repo.createSignatureForAccount(aup, testAccount, now); IamAupSignature sig = repo.findSignatureForAccount(aup, testAccount) .orElseThrow(() -> new AssertionError("Expected signature not found in database"));