@Test public void validate() { String message = UUID.randomUUID().toString(); byte[] payload = message.getBytes(); PublicKey myKey = PublicKey.from("myKey".getBytes()); EncodedPayload encodedPayload = mock(EncodedPayload.class); when(encodedPayload.getRecipientKeys()).thenReturn(Collections.singletonList(myKey)); when(payloadEncoder.decode(payload)).thenReturn(encodedPayload); when(enclave.unencryptTransaction(encodedPayload, myKey)).thenReturn(message.getBytes()); Response result = partyInfoResource.validate(payload); assertThat(result.getStatus()).isEqualTo(200); assertThat(result.getEntity()).isEqualTo(message); verify(payloadEncoder).decode(payload); verify(enclave).unencryptTransaction(encodedPayload, myKey); }
@POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) public Response validate(byte[] payloadData) { final EncodedPayload payload = payloadEncoder.decode(payloadData); final PublicKey mykey = payload.getRecipientKeys().iterator().next(); final byte[] result = enclave.unencryptTransaction(payload, mykey); final String resultStr = new String(result); if (!isUUID(resultStr)) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.ok(new String(result)).build(); }
PartyInfoResource { @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) public Response validate(byte[] payloadData) { final EncodedPayload payload = payloadEncoder.decode(payloadData); final PublicKey mykey = payload.getRecipientKeys().iterator().next(); final byte[] result = enclave.unencryptTransaction(payload, mykey); final String resultStr = new String(result); if (!isUUID(resultStr)) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.ok(new String(result)).build(); } }
PartyInfoResource { @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) public Response validate(byte[] payloadData) { final EncodedPayload payload = payloadEncoder.decode(payloadData); final PublicKey mykey = payload.getRecipientKeys().iterator().next(); final byte[] result = enclave.unencryptTransaction(payload, mykey); final String resultStr = new String(result); if (!isUUID(resultStr)) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.ok(new String(result)).build(); } PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final PayloadEncoder payloadEncoder,
        final boolean enableKeyValidation,
        final PartyStore partyStore);  PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final boolean enableKeyValidation); }
PartyInfoResource { @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) public Response validate(byte[] payloadData) { final EncodedPayload payload = payloadEncoder.decode(payloadData); final PublicKey mykey = payload.getRecipientKeys().iterator().next(); final byte[] result = enclave.unencryptTransaction(payload, mykey); final String resultStr = new String(result); if (!isUUID(resultStr)) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.ok(new String(result)).build(); } PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final PayloadEncoder payloadEncoder,
        final boolean enableKeyValidation,
        final PartyStore partyStore);  PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final boolean enableKeyValidation); @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM) @ApiOperation(value = "Request key/url of other nodes") @ApiResponses({ @ApiResponse( code = 200, message = "Empty response if node is using remote key validation, else an encoded partyinfo containing only the local node's URL", response = byte[].class), @ApiResponse(code = 500, message = "If node is using remote key validation, indicates validation failed") }) Response partyInfo(
        @ApiParam(required = true) final byte[] payload,
        @HeaderParam(Constants.API_VERSION_HEADER) final List<String> headers); @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) Response getPartyInfo(); @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) Response validate(byte[] payloadData); }
PartyInfoResource { @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) public Response validate(byte[] payloadData) { final EncodedPayload payload = payloadEncoder.decode(payloadData); final PublicKey mykey = payload.getRecipientKeys().iterator().next(); final byte[] result = enclave.unencryptTransaction(payload, mykey); final String resultStr = new String(result); if (!isUUID(resultStr)) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.ok(new String(result)).build(); } PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final PayloadEncoder payloadEncoder,
        final boolean enableKeyValidation,
        final PartyStore partyStore);  PartyInfoResource(
        final Discovery discovery,
        final PartyInfoParser partyInfoParser,
        final Client restClient,
        final Enclave enclave,
        final boolean enableKeyValidation); @POST @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM) @ApiOperation(value = "Request key/url of other nodes") @ApiResponses({ @ApiResponse( code = 200, message = "Empty response if node is using remote key validation, else an encoded partyinfo containing only the local node's URL", response = byte[].class), @ApiResponse(code = 500, message = "If node is using remote key validation, indicates validation failed") }) Response partyInfo(
        @ApiParam(required = true) final byte[] payload,
        @HeaderParam(Constants.API_VERSION_HEADER) final List<String> headers); @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Fetch network/peer information") @ApiResponses({@ApiResponse(code = 200, message = "Peer/Network information", response = PartyInfo.class)}) Response getPartyInfo(); @POST @Path("validate") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value = "Processes the validation request data and returns the result.") @ApiResponses({ @ApiResponse( code = 200, message = "Validation request data successfully processed and returned", response = String.class), @ApiResponse(code = 400, message = "Validation request data is not a valid UUID") }) Response validate(byte[] payloadData);  }