def wrapper( request: HttpRequest, client_message: message.Message, client_public_key: bytes, *args: list, **kwargs: dict, ) -> Union[HttpResponse, JsonResponse]: if not is_given_golem_messages_version_supported_by_concent( request=request): log( logger, f'Wrong version of golem messages. Clients version is {request.META["HTTP_X_Golem_Messages"]}, ' f'Concent version is {settings.GOLEM_MESSAGES_VERSION}.', client_public_key=client_public_key, ) serialized_message = dump( message.concents.ServiceRefused( reason=message.concents.ServiceRefused.REASON. UnsupportedProtocolVersion, ), settings.CONCENT_PRIVATE_KEY, client_public_key, ) return HttpResponse(serialized_message, content_type='application/octet-stream') return view(request, client_message, client_public_key, *args, *kwargs)
def wrapper( request: HttpRequest, *args: list, **kwargs: dict, ) -> Union[HttpResponse, JsonResponse]: if not is_given_golem_messages_version_supported_by_concent(request=request): error_message = f"Unsupported protocol version. Client's version is {request.META['HTTP_X_GOLEM_MESSAGES']}, " \ f"Concent's version is {settings.GOLEM_MESSAGES_VERSION}." log(logger, error_message) return HttpResponse(error_message, status=404) return view(request, *args, *kwargs)
def wrapper( request: HttpRequest, *args: list, **kwargs: dict, ) -> JsonResponse: if not is_given_golem_messages_version_supported_by_concent( request=request): error_message = f"Unsupported protocol version. Client's version is {request.META['HTTP_X_GOLEM_MESSAGES']}, " \ f"Concent's version is {settings.GOLEM_MESSAGES_VERSION}." return gatekeeper_access_denied_response( error_message, FileTransferToken.Operation.download, ErrorCode.HEADER_PROTOCOL_VERSION_UNSUPPORTED, request.META['PATH_INFO'] if 'PATH_INFO' in request.META.keys() else '-path to file UNAVAILABLE-', ) return view(request, *args, *kwargs)
def wrapper( request: HttpRequest, *args: list, **kwargs: dict, ) -> JsonResponse: if not is_given_golem_messages_version_supported_by_concent( request=request): log( logger, f'Wrong version of golem messages. Clients version is {request.META["HTTP_X_Golem_Messages"]}, ' f'Concent version is {settings.GOLEM_MESSAGES_VERSION}.', ) return gatekeeper_access_denied_response( "Protocol version in request does not match protocol version in Concent", FileTransferToken.Operation.download, ErrorCode.HEADER_PROTOCOL_VERSION_UNSUPPORTED, request.META['PATH_INFO'] if 'PATH_INFO' in request.META.keys() else '-path to file UNAVAILABLE-', ) return view(request, *args, *kwargs)
def test_that_not_compatible_version_of_golem_message_should_return_false(self, protocol_version): self.request.META['HTTP_X_Golem_Messages'] = protocol_version with override_settings( GOLEM_MESSAGES_VERSION='2.15.0', ): assert not is_given_golem_messages_version_supported_by_concent(self.request)