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) {
}
}
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) {
}
}
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());
}
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());
}
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());
}
Aggregations