@Test public void getAddress_testUnsignedRequestFromFullNode_shouldFailInValidation() { GetHistoryAddressesRequest getHistoryAddressesRequest = new GetHistoryAddressesRequest(new ArrayList<>()); ResponseEntity<IResponse> expectedResponse = ResponseEntity .status(HttpStatus.UNAUTHORIZED) .body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); Assert.assertEquals(expectedResponse, addressService.getAddresses(getHistoryAddressesRequest)); getHistoryAddressesRequest.setSignature(new SignatureData("a", "b")); Assert.assertEquals(expectedResponse, addressService.getAddresses(getHistoryAddressesRequest)); getHistoryAddressesRequest.setSignerHash(new Hash(1)); Assert.assertEquals(expectedResponse, addressService.getAddresses(getHistoryAddressesRequest)); }
public ResponseEntity<IResponse> getAddresses(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } List<Hash> addressesHashesToGetFromStorage = new ArrayList<>(getHistoryAddressesRequest.getAddressHashes()); HashMap<Hash, AddressData> addressToAddressDataFromDB = populateAndRemoveFoundAddresses(addressesHashesToGetFromStorage); Map<Hash, AddressData> getHistoryAddressesResponseMap; if (!addressesHashesToGetFromStorage.isEmpty()) { GetHistoryAddressesResponse getHistoryAddressesResponseFromStorageNode = getAddressesFromStorage(addressesHashesToGetFromStorage); Optional<ResponseEntity<IResponse>> responseValidationResult = validateStorageResponse(getHistoryAddressesResponseFromStorageNode); if (responseValidationResult.isPresent()) { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } else { Map<Hash, AddressData> addressHashesToAddressesFromStorage = getHistoryAddressesResponseFromStorageNode.getAddressHashesToAddresses(); getHistoryAddressesResponseMap = reorderHashResponses(getHistoryAddressesRequest.getAddressHashes(), addressToAddressDataFromDB, addressHashesToAddressesFromStorage); } } else { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } GetHistoryAddressesResponse getHistoryAddressesResponseToFullNode = new GetHistoryAddressesResponse(getHistoryAddressesResponseMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponseToFullNode); return ResponseEntity. status(HttpStatus.OK). body(getHistoryAddressesResponseToFullNode); } catch (HttpClientErrorException | HttpServerErrorException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(String.format(STORAGE_ADDRESS_ERROR, ((SerializableResponse) jacksonSerializer.deserialize(e.getResponseBodyAsByteArray())).getMessage()), STATUS_ERROR)); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }
AddressService extends BaseNodeAddressService { public ResponseEntity<IResponse> getAddresses(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } List<Hash> addressesHashesToGetFromStorage = new ArrayList<>(getHistoryAddressesRequest.getAddressHashes()); HashMap<Hash, AddressData> addressToAddressDataFromDB = populateAndRemoveFoundAddresses(addressesHashesToGetFromStorage); Map<Hash, AddressData> getHistoryAddressesResponseMap; if (!addressesHashesToGetFromStorage.isEmpty()) { GetHistoryAddressesResponse getHistoryAddressesResponseFromStorageNode = getAddressesFromStorage(addressesHashesToGetFromStorage); Optional<ResponseEntity<IResponse>> responseValidationResult = validateStorageResponse(getHistoryAddressesResponseFromStorageNode); if (responseValidationResult.isPresent()) { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } else { Map<Hash, AddressData> addressHashesToAddressesFromStorage = getHistoryAddressesResponseFromStorageNode.getAddressHashesToAddresses(); getHistoryAddressesResponseMap = reorderHashResponses(getHistoryAddressesRequest.getAddressHashes(), addressToAddressDataFromDB, addressHashesToAddressesFromStorage); } } else { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } GetHistoryAddressesResponse getHistoryAddressesResponseToFullNode = new GetHistoryAddressesResponse(getHistoryAddressesResponseMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponseToFullNode); return ResponseEntity. status(HttpStatus.OK). body(getHistoryAddressesResponseToFullNode); } catch (HttpClientErrorException | HttpServerErrorException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(String.format(STORAGE_ADDRESS_ERROR, ((SerializableResponse) jacksonSerializer.deserialize(e.getResponseBodyAsByteArray())).getMessage()), STATUS_ERROR)); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } } }
AddressService extends BaseNodeAddressService { public ResponseEntity<IResponse> getAddresses(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } List<Hash> addressesHashesToGetFromStorage = new ArrayList<>(getHistoryAddressesRequest.getAddressHashes()); HashMap<Hash, AddressData> addressToAddressDataFromDB = populateAndRemoveFoundAddresses(addressesHashesToGetFromStorage); Map<Hash, AddressData> getHistoryAddressesResponseMap; if (!addressesHashesToGetFromStorage.isEmpty()) { GetHistoryAddressesResponse getHistoryAddressesResponseFromStorageNode = getAddressesFromStorage(addressesHashesToGetFromStorage); Optional<ResponseEntity<IResponse>> responseValidationResult = validateStorageResponse(getHistoryAddressesResponseFromStorageNode); if (responseValidationResult.isPresent()) { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } else { Map<Hash, AddressData> addressHashesToAddressesFromStorage = getHistoryAddressesResponseFromStorageNode.getAddressHashesToAddresses(); getHistoryAddressesResponseMap = reorderHashResponses(getHistoryAddressesRequest.getAddressHashes(), addressToAddressDataFromDB, addressHashesToAddressesFromStorage); } } else { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } GetHistoryAddressesResponse getHistoryAddressesResponseToFullNode = new GetHistoryAddressesResponse(getHistoryAddressesResponseMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponseToFullNode); return ResponseEntity. status(HttpStatus.OK). body(getHistoryAddressesResponseToFullNode); } catch (HttpClientErrorException | HttpServerErrorException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(String.format(STORAGE_ADDRESS_ERROR, ((SerializableResponse) jacksonSerializer.deserialize(e.getResponseBodyAsByteArray())).getMessage()), STATUS_ERROR)); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  }
AddressService extends BaseNodeAddressService { public ResponseEntity<IResponse> getAddresses(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } List<Hash> addressesHashesToGetFromStorage = new ArrayList<>(getHistoryAddressesRequest.getAddressHashes()); HashMap<Hash, AddressData> addressToAddressDataFromDB = populateAndRemoveFoundAddresses(addressesHashesToGetFromStorage); Map<Hash, AddressData> getHistoryAddressesResponseMap; if (!addressesHashesToGetFromStorage.isEmpty()) { GetHistoryAddressesResponse getHistoryAddressesResponseFromStorageNode = getAddressesFromStorage(addressesHashesToGetFromStorage); Optional<ResponseEntity<IResponse>> responseValidationResult = validateStorageResponse(getHistoryAddressesResponseFromStorageNode); if (responseValidationResult.isPresent()) { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } else { Map<Hash, AddressData> addressHashesToAddressesFromStorage = getHistoryAddressesResponseFromStorageNode.getAddressHashesToAddresses(); getHistoryAddressesResponseMap = reorderHashResponses(getHistoryAddressesRequest.getAddressHashes(), addressToAddressDataFromDB, addressHashesToAddressesFromStorage); } } else { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } GetHistoryAddressesResponse getHistoryAddressesResponseToFullNode = new GetHistoryAddressesResponse(getHistoryAddressesResponseMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponseToFullNode); return ResponseEntity. status(HttpStatus.OK). body(getHistoryAddressesResponseToFullNode); } catch (HttpClientErrorException | HttpServerErrorException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(String.format(STORAGE_ADDRESS_ERROR, ((SerializableResponse) jacksonSerializer.deserialize(e.getResponseBodyAsByteArray())).getMessage()), STATUS_ERROR)); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  ResponseEntity<IResponse> getAddresses(GetHistoryAddressesRequest getHistoryAddressesRequest); @Override boolean validateRequestedAddressHashExistsAndRelevant(RequestedAddressHashData requestedAddressHashData); }
AddressService extends BaseNodeAddressService { public ResponseEntity<IResponse> getAddresses(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } List<Hash> addressesHashesToGetFromStorage = new ArrayList<>(getHistoryAddressesRequest.getAddressHashes()); HashMap<Hash, AddressData> addressToAddressDataFromDB = populateAndRemoveFoundAddresses(addressesHashesToGetFromStorage); Map<Hash, AddressData> getHistoryAddressesResponseMap; if (!addressesHashesToGetFromStorage.isEmpty()) { GetHistoryAddressesResponse getHistoryAddressesResponseFromStorageNode = getAddressesFromStorage(addressesHashesToGetFromStorage); Optional<ResponseEntity<IResponse>> responseValidationResult = validateStorageResponse(getHistoryAddressesResponseFromStorageNode); if (responseValidationResult.isPresent()) { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } else { Map<Hash, AddressData> addressHashesToAddressesFromStorage = getHistoryAddressesResponseFromStorageNode.getAddressHashesToAddresses(); getHistoryAddressesResponseMap = reorderHashResponses(getHistoryAddressesRequest.getAddressHashes(), addressToAddressDataFromDB, addressHashesToAddressesFromStorage); } } else { getHistoryAddressesResponseMap = addressToAddressDataFromDB; } GetHistoryAddressesResponse getHistoryAddressesResponseToFullNode = new GetHistoryAddressesResponse(getHistoryAddressesResponseMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponseToFullNode); return ResponseEntity. status(HttpStatus.OK). body(getHistoryAddressesResponseToFullNode); } catch (HttpClientErrorException | HttpServerErrorException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(String.format(STORAGE_ADDRESS_ERROR, ((SerializableResponse) jacksonSerializer.deserialize(e.getResponseBodyAsByteArray())).getMessage()), STATUS_ERROR)); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  ResponseEntity<IResponse> getAddresses(GetHistoryAddressesRequest getHistoryAddressesRequest); @Override boolean validateRequestedAddressHashExistsAndRelevant(RequestedAddressHashData requestedAddressHashData);  }