Ejemplo n.º 1
0
        private async Task <IdentityResourceDetails> GetIdentityResource(String identityResourceName,
                                                                         CancellationToken cancellationToken)
        {
            IdentityResourceDetails identityResourceDetails = await this.TestingContext.DockerHelper.SecurityServiceClient.GetIdentityResource(identityResourceName, cancellationToken).ConfigureAwait(false);

            return(identityResourceDetails);
        }
Ejemplo n.º 2
0
        public async Task WhenIGetTheIdentityResourcesIdentityResourceDetailsAreReturnedAsFollows(Int32 numberOfIdentityResources, Table table)
        {
            List <IdentityResourceDetails> identityResourceDetailsList = await this.GetIdentityResources(CancellationToken.None).ConfigureAwait(false);

            identityResourceDetailsList.Count.ShouldBe(numberOfIdentityResources);
            foreach (TableRow tableRow in table.Rows)
            {
                String identityResourceName = SpecflowTableHelper.GetStringRowValue(tableRow, "Name");
                IdentityResourceDetails identityResourceDetails = identityResourceDetailsList.SingleOrDefault(u => u.Name == identityResourceName);

                String userClaims = SpecflowTableHelper.GetStringRowValue(tableRow, "UserClaims");

                identityResourceDetails.Description.ShouldBe(SpecflowTableHelper.GetStringRowValue(tableRow, "Description"));
                identityResourceDetails.Name.ShouldBe(SpecflowTableHelper.GetStringRowValue(tableRow, "Name"));
                identityResourceDetails.DisplayName.ShouldBe(SpecflowTableHelper.GetStringRowValue(tableRow, "DisplayName"));

                if (string.IsNullOrEmpty(userClaims))
                {
                    identityResourceDetails.Claims.ShouldBeEmpty();
                }
                else
                {
                    identityResourceDetails.Claims.ShouldBe(userClaims.Split(",").ToList());
                }
            }
        }
        /// <summary>
        /// Gets the identity resource.
        /// </summary>
        /// <param name="identityResourceName">Name of the identity resource.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <IdentityResourceDetails> GetIdentityResource(String identityResourceName,
                                                                        CancellationToken cancellationToken)
        {
            IdentityResourceDetails response = null;
            String requestUri = this.BuildRequestUrl($"/api/identityresources/{identityResourceName}");

            try
            {
                // Add the access token to the client headers
                //this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful so now deserialise the body to the response object
                response = JsonConvert.DeserializeObject <IdentityResourceDetails>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error getting identity resource {identityResourceName}.", ex);

                throw exception;
            }

            return(response);
        }
Ejemplo n.º 4
0
        public void ModelFactory_ConvertFrom_IdentityResource_ModelIsNull_NullReturned()
        {
            IModelFactory modelFactory = new ModelFactory();

            IdentityResource identityResourceModel = null;

            IdentityResourceDetails identityResourceDto = modelFactory.ConvertFrom(identityResourceModel);

            identityResourceDto.ShouldBeNull();
        }
Ejemplo n.º 5
0
        public void ModelFactory_ConvertFrom_IdentityResource_ModelConverted()
        {
            IModelFactory modelFactory = new ModelFactory();

            IdentityResource identityResourceModel = new IdentityResource
            {
                Description             = SecurityServiceManagerTestData.IdentityResourceDescription,
                DisplayName             = SecurityServiceManagerTestData.IdentityResourceDisplayName,
                UserClaims              = SecurityServiceManagerTestData.IdentityResourceUserClaims,
                Emphasize               = true,
                ShowInDiscoveryDocument = true,
                Required = true
            };

            IdentityResourceDetails identityResourceDto = modelFactory.ConvertFrom(identityResourceModel);

            identityResourceDto.Description.ShouldBe(SecurityServiceManagerTestData.IdentityResourceDescription);
            identityResourceDto.DisplayName.ShouldBe(SecurityServiceManagerTestData.IdentityResourceDisplayName);
            identityResourceDto.Claims.ShouldBe(SecurityServiceManagerTestData.IdentityResourceUserClaims);
            identityResourceDto.Emphasize.ShouldBeTrue();
            identityResourceDto.ShowInDiscoveryDocument.ShouldBeTrue();
            identityResourceDto.Required.ShouldBeTrue();
        }
Ejemplo n.º 6
0
        public async Task WhenIGetTheIdentityResourceWithNameTheIdentityResourceDetailsAreReturnedAsFollows(String identityResourceName, Table table)
        {
            IdentityResourceDetails identityResourceDetails = await this.GetIdentityResource(identityResourceName, CancellationToken.None).ConfigureAwait(false);

            table.Rows.Count.ShouldBe(1);
            TableRow tableRow = table.Rows.First();

            identityResourceDetails.ShouldNotBeNull();

            String userClaims = SpecflowTableHelper.GetStringRowValue(tableRow, "UserClaims");

            identityResourceDetails.Description.ShouldBe(SpecflowTableHelper.GetStringRowValue(tableRow, "Description"));
            identityResourceDetails.Name.ShouldBe(SpecflowTableHelper.GetStringRowValue(tableRow, "Name"));
            identityResourceDetails.DisplayName.ShouldBe(SpecflowTableHelper.GetStringRowValue(tableRow, "DisplayName"));

            if (string.IsNullOrEmpty(userClaims))
            {
                identityResourceDetails.Claims.ShouldBeEmpty();
            }
            else
            {
                identityResourceDetails.Claims.ShouldBe(userClaims.Split(",").ToList());
            }
        }