use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class PossibleActionsRuleEngineTest method getPossibleCertificateActionUnregister.
@Test
public void getPossibleCertificateActionUnregister() {
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().build();
assertTrue(possibleActionsRuleEngine.getPossibleCertificateActions(tokenInfo, new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.AUTHENTICATION).build(), new CertificateTestUtils.CertificateInfoBuilder().certificateStatus(CertificateInfo.STATUS_REGINPROG).build()).contains(PossibleActionEnum.UNREGISTER));
assertFalse(possibleActionsRuleEngine.getPossibleCertificateActions(tokenInfo, new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.AUTHENTICATION).build(), new CertificateTestUtils.CertificateInfoBuilder().certificateStatus(CertificateInfo.STATUS_SAVED).build()).contains(PossibleActionEnum.UNREGISTER));
assertFalse(possibleActionsRuleEngine.getPossibleCertificateActions(tokenInfo, new TokenTestUtils.KeyInfoBuilder().keyUsageInfo(KeyUsageInfo.SIGNING).build(), new CertificateTestUtils.CertificateInfoBuilder().certificateStatus(CertificateInfo.STATUS_REGINPROG).build()).contains(PossibleActionEnum.UNREGISTER));
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenCertificateServiceTest method setup.
@Before
public void setup() throws Exception {
when(clientService.getLocalClientMemberIds()).thenReturn(new HashSet<>(Collections.singletonList(client)));
DnFieldDescription editableField = new DnFieldDescriptionImpl("O", "x", "default").setReadOnly(false);
when(certificateAuthorityService.getCertificateProfile(any(), any(), any(), anyBoolean())).thenReturn(new DnFieldTestCertificateProfileInfo(editableField, true));
// need lots of mocking
// construct some test keys, with csrs and certs
// make used finders return data from these items:
// keyService.getKey, signerProxyFacade.getKeyIdForCertHash,
// signerProxyFacade.getCertForHash
// mock delete-operations (deleteCertificate, deleteCsr)
CertRequestInfo goodCsr = new CertRequestInfo(GOOD_CSR_ID, null, null);
CertRequestInfo authCsr = new CertRequestInfo(GOOD_AUTH_CSR_ID, null, null);
CertRequestInfo signCsr = new CertRequestInfo(GOOD_SIGN_CSR_ID, null, null);
CertRequestInfo signerExceptionCsr = new CertRequestInfo(SIGNER_EXCEPTION_CSR_ID, null, null);
KeyInfo authKey = new TokenTestUtils.KeyInfoBuilder().id(AUTH_KEY_ID).keyUsageInfo(KeyUsageInfo.AUTHENTICATION).csr(authCsr).cert(authCert).build();
KeyInfo goodKey = new TokenTestUtils.KeyInfoBuilder().id(GOOD_KEY_ID).csr(goodCsr).csr(signerExceptionCsr).build();
KeyInfo signKey = new TokenTestUtils.KeyInfoBuilder().id(SIGN_KEY_ID).keyUsageInfo(KeyUsageInfo.SIGNING).csr(signCsr).cert(signCert).build();
TokenInfo tokenInfo = new TokenTestUtils.TokenInfoBuilder().friendlyName("fubar").build();
tokenInfo.getKeyInfo().add(authKey);
tokenInfo.getKeyInfo().add(signKey);
tokenInfo.getKeyInfo().add(goodKey);
mockGetTokenAndKeyIdForCertificateHash(authKey, goodKey, signKey, tokenInfo);
mockGetTokenAndKeyIdForCertificateRequestId(authKey, goodKey, signKey, tokenInfo);
mockGetKey(authKey, goodKey, signKey);
mockGetKeyIdForCertHash();
mockGetCertForHash();
mockDeleteCert();
mockDeleteCertRequest();
mockGetTokenForKeyId(tokenInfo);
// activate / deactivate
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
String hash = (String) args[0];
if (MISSING_CERTIFICATE_HASH.equals(hash)) {
throw new CodedException(TokenCertificateService.CERT_NOT_FOUND_FAULT_CODE);
}
return null;
}).when(signerProxyFacade).deactivateCert(any());
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
String hash = (String) args[0];
if (MISSING_CERTIFICATE_HASH.equals(hash)) {
throw new CodedException(TokenCertificateService.CERT_NOT_FOUND_FAULT_CODE);
}
return null;
}).when(signerProxyFacade).activateCert(eq("certID"));
// by default all actions are possible
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleTokenActions(any());
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleKeyActions(any(), any());
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCertificateActions(any(), any(), any());
doReturn(EnumSet.allOf(PossibleActionEnum.class)).when(possibleActionsRuleEngine).getPossibleCsrActions(any());
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenServiceTest method updateTokenFriendlyName.
@Test
public void updateTokenFriendlyName() throws Exception {
TokenInfo tokenInfo = tokenService.getToken(GOOD_TOKEN_ID);
assertEquals(GOOD_TOKEN_NAME, tokenInfo.getFriendlyName());
tokenInfo = tokenService.updateTokenFriendlyName(GOOD_TOKEN_ID, "friendly-neighborhood");
assertEquals("friendly-neighborhood", tokenInfo.getFriendlyName());
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokenServiceTest method getToken.
@Test
public void getToken() throws Exception {
try {
tokenService.getToken(TOKEN_NOT_FOUND_TOKEN_ID);
} catch (TokenNotFoundException expected) {
}
TokenInfo tokenInfo = tokenService.getToken(GOOD_TOKEN_ID);
assertEquals(GOOD_TOKEN_NAME, tokenInfo.getFriendlyName());
}
use of ee.ria.xroad.signer.protocol.dto.TokenInfo in project X-Road by nordic-institute.
the class TokensApiController method updateToken.
@PreAuthorize("hasAuthority('EDIT_TOKEN_FRIENDLY_NAME')")
@Override
@AuditEventMethod(event = RestApiAuditEvent.UPDATE_TOKEN_NAME)
public ResponseEntity<Token> updateToken(String id, TokenName tokenName) {
try {
TokenInfo tokenInfo = tokenService.updateTokenFriendlyName(id, tokenName.getName());
Token token = tokenConverter.convert(tokenInfo);
return new ResponseEntity<>(token, HttpStatus.OK);
} catch (TokenNotFoundException e) {
throw new ResourceNotFoundException(e);
} catch (ActionNotPossibleException e) {
throw new ConflictException(e);
}
}
Aggregations