Search in sources :

Example 21 with KeyInfo

use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.

the class ClientsApiControllerIntegrationTest method getOrphans.

@Test
@WithMockUser(authorities = { "DELETE_CLIENT" })
public void getOrphans() {
    ClientId orphanClient = TestUtils.getClientId("FI:GOV:ORPHAN:SS1");
    KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.SIGNING).csr(new CertRequestInfoBuilder().clientId(orphanClient).build()).build();
    TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().key(keyInfo).build();
    doReturn(Collections.singletonList(tokenInfo)).when(tokenService).getAllTokens();
    ResponseEntity<OrphanInformation> orphanResponse = clientsApiController.getClientOrphans("FI:GOV:ORPHAN:SS1");
    assertEquals(HttpStatus.OK, orphanResponse.getStatusCode());
    assertEquals(true, orphanResponse.getBody().getOrphansExist());
    try {
        clientsApiController.getClientOrphans("FI:GOV:M1:SS777");
        fail("should not find orphans");
    } catch (ResourceNotFoundException expected) {
    }
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) OrphanInformation(org.niis.xroad.securityserver.restapi.openapi.model.OrphanInformation) ClientId(ee.ria.xroad.common.identifier.ClientId) TokenTestUtils(org.niis.xroad.securityserver.restapi.util.TokenTestUtils) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException) CertRequestInfoBuilder(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils.CertRequestInfoBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) WsdlValidatorTest(org.niis.xroad.securityserver.restapi.wsdl.WsdlValidatorTest) Test(org.junit.Test)

Example 22 with KeyInfo

use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.

the class ClientsApiControllerIntegrationTest method deleteOrphans.

@Test
@WithMockUser(authorities = { "DELETE_CLIENT", "DELETE_SIGN_KEY" })
public void deleteOrphans() throws Exception {
    ClientId orphanClient = TestUtils.getClientId("FI:GOV:ORPHAN:SS1");
    String orphanKeyId = "orphan-key";
    KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.SIGNING).id(orphanKeyId).csr(new CertRequestInfoBuilder().clientId(orphanClient).build()).build();
    TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().key(keyInfo).build();
    doReturn(Collections.singletonList(tokenInfo)).when(tokenService).getAllTokens();
    doReturn(tokenInfo).when(tokenService).getTokenForKeyId(any());
    ResponseEntity<Void> orphanResponse = clientsApiController.deleteOrphans("FI:GOV:ORPHAN:SS1");
    assertEquals(HttpStatus.NO_CONTENT, orphanResponse.getStatusCode());
    verify(signerProxyFacade, times(1)).deleteKey(orphanKeyId, true);
    verify(signerProxyFacade, times(1)).deleteKey(orphanKeyId, false);
    verifyNoMoreInteractions(signerProxyFacade);
    try {
        clientsApiController.deleteOrphans("FI:GOV:M1:SS777");
        fail("should not find orphans");
    } catch (ResourceNotFoundException expected) {
    }
}
Also used : KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) ClientId(ee.ria.xroad.common.identifier.ClientId) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) ResourceNotFoundException(org.niis.xroad.restapi.openapi.ResourceNotFoundException) CertRequestInfoBuilder(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils.CertRequestInfoBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) WsdlValidatorTest(org.niis.xroad.securityserver.restapi.wsdl.WsdlValidatorTest) Test(org.junit.Test)

Example 23 with KeyInfo

use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.

the class TokenCertificateConverterTest method convertWithPossibleActions.

@Test
public void convertWithPossibleActions() throws Exception {
    CertificateInfo certificateInfo = new CertificateTestUtils.CertificateInfoBuilder().build();
    KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().cert(certificateInfo).build();
    TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().key(keyInfo).build();
    TokenCertificate certificate = tokenCertificateConverter.convert(certificateInfo, keyInfo, tokenInfo);
    Collection<PossibleAction> actions = certificate.getPossibleActions();
    assertTrue(actions.contains(PossibleAction.ACTIVATE));
    assertEquals(1, actions.size());
}
Also used : PossibleAction(org.niis.xroad.securityserver.restapi.openapi.model.PossibleAction) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) CertificateTestUtils(org.niis.xroad.securityserver.restapi.util.CertificateTestUtils) CertificateInfo(ee.ria.xroad.signer.protocol.dto.CertificateInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) TokenCertificate(org.niis.xroad.securityserver.restapi.openapi.model.TokenCertificate) Test(org.junit.Test)

Example 24 with KeyInfo

use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.

the class TokenConverterTest method convert.

@Test
public void convert() throws Exception {
    Map<String, String> tokenInfos = new HashMap<>();
    tokenInfos.put("key1", "value1");
    tokenInfos.put("key2", "value2");
    // keyinfo not used, keyConverter mocked
    KeyInfo dummyKeyInfo = new TokenTestUtils.KeyInfoBuilder().build();
    TokenInfo tokenInfo = new TokenInfo(TokenInfo.SOFTWARE_MODULE_TYPE, "friendly-name", "id", false, true, true, "serial-number", "label", 123, TokenStatusInfo.OK, Collections.singletonList(dummyKeyInfo), tokenInfos);
    Token token = tokenConverter.convert(tokenInfo);
    assertEquals(true, token.getLoggedIn());
    assertEquals(true, token.getAvailable());
    assertEquals("id", token.getId());
    assertNotNull(token.getKeys());
    assertEquals(1, token.getKeys().size());
    assertEquals("friendly-name", token.getName());
    assertEquals(false, token.getReadOnly());
    assertEquals(false, token.getSavedToConfiguration());
    assertEquals("serial-number", token.getSerialNumber());
    assertEquals(TokenStatus.OK, token.getStatus());
    assertEquals(TokenType.SOFTWARE, token.getType());
    assertNotNull(token.getTokenInfos());
    assertEquals(2, token.getTokenInfos().size());
    assertTrue(token.getTokenInfos().contains(new KeyValuePair().key("key1").value("value1")));
    assertTrue(token.getTokenInfos().contains(new KeyValuePair().key("key2").value("value2")));
    // hsm
    tokenInfo = new TokenInfo("hsm-uid-1234", "friendly-name", "id", false, true, true, "serial-number", "label", 123, TokenStatusInfo.USER_PIN_COUNT_LOW, Collections.singletonList(dummyKeyInfo), tokenInfos);
    token = tokenConverter.convert(tokenInfo);
    assertEquals(TokenType.HARDWARE, token.getType());
    assertEquals(TokenStatus.USER_PIN_COUNT_LOW, token.getStatus());
}
Also used : KeyValuePair(org.niis.xroad.securityserver.restapi.openapi.model.KeyValuePair) HashMap(java.util.HashMap) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) Token(org.niis.xroad.securityserver.restapi.openapi.model.Token) TokenTestUtils(org.niis.xroad.securityserver.restapi.util.TokenTestUtils) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Test(org.junit.Test)

Example 25 with KeyInfo

use of ee.ria.xroad.signer.protocol.dto.KeyInfo in project X-Road by nordic-institute.

the class TokensApiControllerTest method setUp.

@Before
public void setUp() throws Exception {
    KeyInfo keyInfo = new TokenTestUtils.KeyInfoBuilder().build();
    TokenInfo activeTokenInfo = new TokenTestUtils.TokenInfoBuilder().id(GOOD_TOKEN_ID).key(keyInfo).build();
    KeyInfo inactiveKeyInfo = new TokenTestUtils.KeyInfoBuilder().id(NOT_ACTIVE_TOKEN_KEY_ID).build();
    TokenInfo inactiveTokenInfo = new TokenTestUtils.TokenInfoBuilder().id(NOT_ACTIVE_TOKEN_ID).active(false).key(inactiveKeyInfo).build();
    allTokens = Arrays.asList(new TokenInfo[] { activeTokenInfo, inactiveTokenInfo });
    doReturn(allTokens).when(tokenService).getAllTokens();
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String tokenId = (String) args[0];
        if (GOOD_TOKEN_ID.equals(tokenId)) {
            return activeTokenInfo;
        } else if (NOT_ACTIVE_TOKEN_ID.equals(tokenId)) {
            return inactiveTokenInfo;
        } else {
            throw new TokenNotFoundException(new RuntimeException());
        }
    }).when(tokenService).getToken(any());
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String keyId = (String) args[0];
        if (keyInfo.getId().equals(keyId)) {
            return activeTokenInfo;
        } else if (inactiveKeyInfo.getId().equals(keyId)) {
            return inactiveTokenInfo;
        } else {
            throw new TokenNotFoundException(new RuntimeException());
        }
    }).when(tokenService).getTokenForKeyId(any());
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String tokenId = (String) args[0];
        String keyLabel = (String) args[1];
        if (GOOD_TOKEN_ID.equals(tokenId)) {
            ReflectionTestUtils.setField(keyInfo, "label", keyLabel);
            return keyInfo;
        } else if (NOT_ACTIVE_TOKEN_ID.equals(tokenId)) {
            throw new CodedException.Fault(SIGNER_X + "." + X_TOKEN_NOT_ACTIVE, null);
        } else if (TOKEN_NOT_FOUND_TOKEN_ID.equals(tokenId)) {
            throw new CodedException.Fault(SIGNER_X + "." + X_TOKEN_NOT_FOUND, null);
        }
        throw new RuntimeException("given tokenId not supported in mocked method SignerProxyFacade#generateKey");
    }).when(signerProxyFacade).generateKey(any(), any());
}
Also used : TokenTestUtils(org.niis.xroad.securityserver.restapi.util.TokenTestUtils) TokenNotFoundException(org.niis.xroad.securityserver.restapi.service.TokenNotFoundException) CodedException(ee.ria.xroad.common.CodedException) KeyInfo(ee.ria.xroad.signer.protocol.dto.KeyInfo) TokenInfo(ee.ria.xroad.signer.protocol.dto.TokenInfo) Before(org.junit.Before)

Aggregations

KeyInfo (ee.ria.xroad.signer.protocol.dto.KeyInfo)58 TokenInfo (ee.ria.xroad.signer.protocol.dto.TokenInfo)32 CertificateInfo (ee.ria.xroad.signer.protocol.dto.CertificateInfo)17 Test (org.junit.Test)16 CodedException (ee.ria.xroad.common.CodedException)12 TokenTestUtils (org.niis.xroad.securityserver.restapi.util.TokenTestUtils)12 CertRequestInfo (ee.ria.xroad.signer.protocol.dto.CertRequestInfo)9 TokenInfoAndKeyId (ee.ria.xroad.signer.protocol.dto.TokenInfoAndKeyId)9 Before (org.junit.Before)9 ArrayList (java.util.ArrayList)7 ClientId (ee.ria.xroad.common.identifier.ClientId)6 DeviationAwareRuntimeException (org.niis.xroad.restapi.exceptions.DeviationAwareRuntimeException)6 SignerNotReachableException (org.niis.xroad.restapi.service.SignerNotReachableException)6 KeyUsageInfo (ee.ria.xroad.signer.protocol.dto.KeyUsageInfo)5 HashMap (java.util.HashMap)5 ResourceNotFoundException (org.niis.xroad.restapi.openapi.ResourceNotFoundException)5 AuthKeyInfo (ee.ria.xroad.signer.protocol.dto.AuthKeyInfo)4 TokenManager.getKeyInfo (ee.ria.xroad.signer.tokenmanager.TokenManager.getKeyInfo)4 CertificateTestUtils (org.niis.xroad.securityserver.restapi.util.CertificateTestUtils)4 GeneratedCertRequestInfo (ee.ria.xroad.commonui.SignerProxy.GeneratedCertRequestInfo)3