private void ValidateReferenceRequest(string reference, GpConnectInteraction interaction)
        {
            if (reference.StartsWith("Location/"))
            {
                var location = _httpSteps.GetResourceForRelativeUrl(GpConnectInteraction.LocationRead, reference);

                location.ShouldNotBeNull(
                    $"The Reference {reference} returned a null Location.");
                location.GetType()
                .ShouldBe(typeof(Location),
                          $"The reference {reference} returned a {location.GetType().ToString()}.");
            }
            else if (reference.StartsWith("Organization/"))
            {
                var organization = _httpSteps.GetResourceForRelativeUrl(GpConnectInteraction.OrganizationRead, reference);

                organization.ShouldNotBeNull(
                    $"The Reference {reference} returned a null Location.");
                organization.GetType()
                .ShouldBe(typeof(Location),
                          $"The reference {reference} returned a {organization.GetType().ToString()}.");
            }
            else if (reference.StartsWith("Practitioner/"))
            {
                var practitioner = _httpSteps.GetResourceForRelativeUrl(GpConnectInteraction.PractitionerRead, reference);

                practitioner.ShouldNotBeNull(
                    $"The Reference {reference} returned a null Location.");
                practitioner.GetType()
                .ShouldBe(typeof(Location),
                          $"The reference {reference} returned a {practitioner.GetType().ToString()}.");
            }
        }
 public HttpRequestConfigurationFactory(GpConnectInteraction gpConnectInteraction, HttpRequestConfiguration httpRequestConfiguration)
 {
     _gpConnectInteraction     = gpConnectInteraction;
     _httpRequestConfiguration = httpRequestConfiguration;
     _httpRequestConfiguration.LoadAppConfig();
     _httpRequestConfiguration.SetDefaultHeaders();
 }
        public void ConfigureRequestDefaultMetaDataRequestWithOldURL(GpConnectInteraction interaction)
        {
            _httpContext.SetDefaults();

            _httpContext.HttpRequestConfiguration = GetHttpRequestConfiguration(interaction, _httpContext.HttpRequestConfiguration);
            jwtHelper = GetJwtHelper(interaction, jwtHelper);

            _securitySteps.ConfigureServerCertificatesAndSsl();
        }
Ejemplo n.º 4
0
        public void ConfigureRequest(GpConnectInteraction interaction)
        {
            _httpContext.SetDefaults();

            _httpContext.HttpRequestConfiguration = _httpSteps.GetHttpRequestConfiguration(interaction, _httpContext.HttpRequestConfiguration);

            _jwtHelper = _httpSteps.GetJwtHelper(interaction, _jwtHelper);

            _securitySteps.ConfigureServerCertificatesAndSsl();
        }
        public void MakeRequestWithDepricatedURLs(GpConnectInteraction interaction)
        {
            _httpContext.HttpRequestConfiguration = GetRequestBody(interaction, _httpContext.HttpRequestConfiguration);

            _httpContext.HttpRequestConfiguration.RequestHeaders.ReplaceHeader(HttpConst.Headers.kAuthorization, jwtHelper.GetBearerToken());

            var httpRequest = new HttpContextRequest(_httpContext, _securityContext);

            httpRequest.MakeRequest();
        }
        public HttpRequestConfiguration GetHttpRequestConfiguration(GpConnectInteraction interaction, HttpRequestConfiguration httpRequestConfiguration = null)
        {
            if (httpRequestConfiguration == null)
            {
                httpRequestConfiguration = new HttpRequestConfiguration();
            }

            var httpRequestConfigurationFactory = new HttpRequestConfigurationFactory(interaction, httpRequestConfiguration);

            return(httpRequestConfigurationFactory.GetHttpRequestConfiguration());
        }
        public void MakeRequestWithAdditionalFieldInParameterResource(GpConnectInteraction interaction)
        {
            var requestFactory = new RequestFactory(interaction, _fhirResourceRepository);

            requestFactory.ConfigureBody(_httpContext.HttpRequestConfiguration);
            requestFactory.ConfigureParameterResourceWithAdditionalField(_httpContext.HttpRequestConfiguration);
            _httpContext.HttpRequestConfiguration.RequestHeaders.ReplaceHeader(HttpConst.Headers.kAuthorization, jwtHelper.GetBearerToken());

            var httpRequest = new HttpContextRequest(_httpContext, _securityContext);

            httpRequest.MakeRequest();
        }
        public void MakeRequestWithAnUnencodedJwtBearerToken(GpConnectInteraction interaction)
        {
            var requestFactory = new RequestFactory(interaction, _fhirResourceRepository);

            requestFactory.ConfigureBody(_httpContext.HttpRequestConfiguration);

            _httpContext.HttpRequestConfiguration.RequestHeaders.ReplaceHeader(HttpConst.Headers.kAuthorization, jwtHelper.GetBearerTokenWithoutEncoding());

            var httpRequest = new HttpContextRequest(_httpContext, _securityContext);

            httpRequest.MakeRequest();
        }
        public void MakeRequestWithMissingHeader(GpConnectInteraction interaction, string headerKey)
        {
            _httpContext.HttpRequestConfiguration = GetRequestBody(interaction, _httpContext.HttpRequestConfiguration);

            _httpContext.HttpRequestConfiguration.RequestHeaders.ReplaceHeader(HttpConst.Headers.kAuthorization, jwtHelper.GetBearerToken());

            _httpContext.HttpRequestConfiguration.RequestHeaders.RemoveHeader(headerKey);

            var httpRequest = new HttpContextRequest(_httpContext, _securityContext);

            httpRequest.MakeRequest();
        }
        public HttpRequestConfiguration GetRequestBody(GpConnectInteraction interaction, HttpRequestConfiguration httpRequestConfiguration = null)
        {
            if (httpRequestConfiguration == null)
            {
                httpRequestConfiguration = new HttpRequestConfiguration();
            }

            var requestFactory = new RequestFactory(interaction, _fhirResourceRepository);

            requestFactory.ConfigureBody(httpRequestConfiguration);

            return(httpRequestConfiguration);
        }
        public JwtHelper GetJwtHelper(GpConnectInteraction interaction, JwtHelper jwtHelper = null)
        {
            if (jwtHelper == null)
            {
                jwtHelper = new JwtHelper();
            }

            var jwtFactory = new JwtFactory(interaction);

            jwtFactory.ConfigureJwt(jwtHelper);

            return(jwtHelper);
        }
        public void MakeRequest(GpConnectInteraction interaction)
        {
            if (interaction.Equals(GpConnectInteraction.AppointmentCreate))
            {
                TeardownSteps.AppointmentCreated();
            }

            _httpContext.HttpRequestConfiguration = GetRequestBody(interaction, _httpContext.HttpRequestConfiguration);

            _httpContext.HttpRequestConfiguration.RequestHeaders.ReplaceHeader(HttpConst.Headers.kAuthorization, jwtHelper.GetBearerToken());

            var httpRequest = new HttpContextRequest(_httpContext, _securityContext);

            httpRequest.MakeRequest();
        }
        public Resource GetResourceForRelativeUrl(GpConnectInteraction gpConnectInteraction, string relativeUrl)
        {
            var httpRequestConfiguration = new HttpRequestConfiguration();

            var httpContextFactory = new HttpRequestConfigurationFactory(gpConnectInteraction, httpRequestConfiguration);

            httpContextFactory.GetHttpRequestConfiguration();

            var jwtHelper  = new JwtHelper();
            var jwtFactory = new JwtFactory(gpConnectInteraction);

            jwtFactory.ConfigureJwt(jwtHelper);

            if (relativeUrl.Contains("Patient"))
            {
                var patient = relativeUrl.ToLower().Replace("/", string.Empty);
                try
                {
                    jwtHelper.RequestedPatientNHSNumber = GlobalContext.PatientNhsNumberMap[patient];
                }
                catch (Exception)
                {
                    Patient patientResource = _fhirResourceRepository.Patient;
                    var     nhsNumber       = patientResource.Identifier[0].Value;
                    jwtHelper.RequestedPatientNHSNumber = nhsNumber;
                }
            }

            if (relativeUrl.Contains("Organization"))
            {
                var organizationId = relativeUrl.Split('/')[1];
                jwtHelper.RequestedOrganizationId = organizationId;
            }

            httpRequestConfiguration.RequestUrl = relativeUrl;

            _securitySteps.ConfigureServerCertificatesAndSsl();

            var requestFactory = new RequestFactory(gpConnectInteraction, _fhirResourceRepository);

            requestFactory.ConfigureBody(httpRequestConfiguration);

            httpRequestConfiguration.RequestHeaders.ReplaceHeader(HttpConst.Headers.kAuthorization, jwtHelper.GetBearerToken());

            var httpRequest = new HttpResourceRequest(httpRequestConfiguration, _securityContext);

            return(httpRequest.MakeRequest().Resource);
        }
Ejemplo n.º 14
0
        public void MakeTheCurlRequestWithCipher(GpConnectInteraction interaction)
        {
            _httpContext.HttpRequestConfiguration = _httpSteps.GetRequestBody(interaction, _httpContext.HttpRequestConfiguration);

            _httpContext.HttpRequestConfiguration.RequestHeaders.ReplaceHeader(HttpConst.Headers.kAuthorization, _jwtHelper.GetBearerToken());

            var headers = _httpContext.HttpRequestConfiguration.RequestHeaders;
            var url     = _httpContext.HttpRequestConfiguration.EndpointAddress + '/' + _httpContext.HttpRequestConfiguration.RequestUrl;
            var cipher  = _securityContext.Cipher;

            Curl.GlobalInit(CurlInitFlag.All);

            var curlHeaders = GetHeaders(headers);

            var curlEasy = GetCurlEasy(url, cipher, curlHeaders);

            MakeCurlRequest(curlEasy);
        }
Ejemplo n.º 15
0
 public JwtFactory(GpConnectInteraction gpConnectInteraction)
 {
     _gpConnectInteraction = gpConnectInteraction;
 }
 public RequestFactory(GpConnectInteraction gpConnectInteraction, IFhirResourceRepository fhirResourceRepository)
 {
     _gpConnectInteraction   = gpConnectInteraction;
     _fhirResourceRepository = fhirResourceRepository;
 }