Search in sources :

Example 1 with CerberusPrincipal

use of com.nike.cerberus.security.CerberusPrincipal in project cerberus by Nike-Inc.

the class SecureDataControllerTest method testWriteSecureData.

@Test
public void testWriteSecureData() {
    Mockito.when(sdbAccessRequest.getSdbId()).thenReturn("sdbId");
    Mockito.when(sdbAccessRequest.getPath()).thenReturn("path");
    CerberusPrincipal cerberusPrincipal = Mockito.mock(CerberusPrincipal.class);
    Mockito.when(sdbAccessRequest.getPrincipal()).thenReturn(cerberusPrincipal);
    Mockito.when(cerberusPrincipal.getName()).thenReturn("name");
    HttpEntity<String> httpEntity = new HttpEntity<>("body");
    secureDataController.writeSecureData(httpEntity);
    Mockito.verify(secureDataService).writeSecret("sdbId", "path", "body", "name");
}
Also used : HttpEntity(org.springframework.http.HttpEntity) CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) Test(org.junit.Test)

Example 2 with CerberusPrincipal

use of com.nike.cerberus.security.CerberusPrincipal in project cerberus by Nike-Inc.

the class SafeDepositBoxControllerV2Test method testGetSafeDepositBoxes.

@Test
public void testGetSafeDepositBoxes() {
    CerberusPrincipal cerberusPrincipal = Mockito.mock(CerberusPrincipal.class);
    SafeDepositBoxSummary safeDepositBoxSummary = Mockito.mock(SafeDepositBoxSummary.class);
    List<SafeDepositBoxSummary> safeDepositBoxSummaries = new ArrayList<>();
    safeDepositBoxSummaries.add(safeDepositBoxSummary);
    Mockito.when(safeDepositBoxService.getAssociatedSafeDepositBoxes(cerberusPrincipal)).thenReturn(safeDepositBoxSummaries);
    List<SafeDepositBoxSummary> actualSafeDepositBoSummaries = safeDepositBoxControllerV2.getSafeDepositBoxes(cerberusPrincipal);
    Assert.assertSame(safeDepositBoxSummaries, actualSafeDepositBoSummaries);
    Assert.assertEquals(safeDepositBoxSummaries, actualSafeDepositBoSummaries);
}
Also used : ArrayList(java.util.ArrayList) SafeDepositBoxSummary(com.nike.cerberus.domain.SafeDepositBoxSummary) CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) Test(org.junit.Test)

Example 3 with CerberusPrincipal

use of com.nike.cerberus.security.CerberusPrincipal in project cerberus by Nike-Inc.

the class RevokeAuthenticationControllerTest method testRevokeAuthentication.

@Test
public void testRevokeAuthentication() {
    OffsetDateTime now = OffsetDateTime.now();
    CerberusPrincipal cerberusPrincipal = Mockito.mock(CerberusPrincipal.class);
    Mockito.when(cerberusPrincipal.getTokenExpires()).thenReturn(now);
    revokeAuthenticationController.revokeAuthentication(cerberusPrincipal);
    Mockito.verify(authenticationService).revoke(cerberusPrincipal, now);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) Test(org.junit.Test)

Example 4 with CerberusPrincipal

use of com.nike.cerberus.security.CerberusPrincipal in project cerberus by Nike-Inc.

the class UserAuthenticationControllerTest method testRefreshToken.

@Test
public void testRefreshToken() {
    CerberusPrincipal cerberusPrincipal = Mockito.mock(CerberusPrincipal.class);
    userAuthenticationController.refreshToken(cerberusPrincipal);
    Mockito.verify(authenticationService).refreshUserToken(cerberusPrincipal);
}
Also used : CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) Test(org.junit.Test)

Example 5 with CerberusPrincipal

use of com.nike.cerberus.security.CerberusPrincipal in project cerberus by Nike-Inc.

the class SecureDataController method writeSecureData.

@PrincipalHasWritePermsForPath
@RequestMapping(value = "/**", method = { POST, PUT }, consumes = ALL_VALUE)
public void writeSecureData(HttpEntity<String> httpEntity) {
    CerberusPrincipal principal = sdbAccessRequest.getPrincipal();
    secureDataService.writeSecret(sdbAccessRequest.getSdbId(), sdbAccessRequest.getPath(), Optional.ofNullable(httpEntity.getBody()).orElseThrow(() -> new RuntimeException("The body must not be null")), principal.getName());
}
Also used : CerberusPrincipal(com.nike.cerberus.security.CerberusPrincipal) PrincipalHasWritePermsForPath(com.nike.cerberus.security.PrincipalHasWritePermsForPath) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CerberusPrincipal (com.nike.cerberus.security.CerberusPrincipal)33 Test (org.junit.Test)27 HashSet (java.util.HashSet)11 SafeDepositBoxV2 (com.nike.cerberus.domain.SafeDepositBoxV2)7 ApiException (com.nike.backstopper.exception.ApiException)4 UserGroupPermission (com.nike.cerberus.domain.UserGroupPermission)4 SafeDepositBoxSummary (com.nike.cerberus.domain.SafeDepositBoxSummary)3 RequestAttributes (org.springframework.web.context.request.RequestAttributes)3 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 SafeDepositBoxRecord (com.nike.cerberus.record.SafeDepositBoxRecord)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 OffsetDateTime (java.time.OffsetDateTime)2 IsInstanceOf (org.hamcrest.core.IsInstanceOf)2 PrincipalType (com.nike.cerberus.PrincipalType)1 AuthResponse (com.nike.cerberus.auth.connector.AuthResponse)1 CerberusAuthToken (com.nike.cerberus.domain.CerberusAuthToken)1 PrincipalHasWritePermsForPath (com.nike.cerberus.security.PrincipalHasWritePermsForPath)1 ArrayList (java.util.ArrayList)1 HttpEntity (org.springframework.http.HttpEntity)1