Ejemplo n.º 1
0
        public async Task <ITrustedOrigin> CreateTrustedOrigin(CreateTrustedOriginOptions options,
                                                               CancellationToken cancellationToken = default(CancellationToken))
        {
            var requestUrl = _client.Configuration.BuildUrl("/api/v1/trustedOrigins");

            return(await _client.PostAsync <TrustedOrigin>(requestUrl.AbsoluteUri, options, cancellationToken));
        }
        public async Task CanCreatedATrustedOrigin()
        {
            //GIVEN A valid specifcation for a trusted origin
            var mockClient = new Mock <IOktaClient>();
            var client     = mockClient.Object;

            mockClient.Setup(x => x.Configuration)
            .Returns(new OktaClientConfiguration()
            {
                OktaDomain = ExampleOktaDomain
            });


            var createOptions = new CreateTrustedOriginOptions()
            {
                Name   = "Test origin",
                Origin = "https://mywebsite.trusted.com",
                Scopes = new List <ITrustedOriginScope>()
                {
                    new TrustedOriginScope()
                    {
                        Type = "CORS"
                    },
                    new TrustedOriginScope()
                    {
                        Type = "REDIRECT"
                    }
                }
            };

            mockClient.Setup(x => x.PostAsync <TrustedOrigin>($"{ExampleOktaDomain}/api/v1/trustedOrigins", It.IsAny <object>(),
                                                              It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new TrustedOrigin()
            {
                Id = "Example response"
            }));

            //WHEN A request is made to create a trusted origin

            var result = await client.TrustedOrigins().CreateTrustedOrigin(createOptions, CancellationToken.None);

            //THEN The okta client is invoked with the correct parameters

            Assert.That(result.Id, Is.EqualTo("Example response"),
                        "The returned object should be the mock expectation");

            mockClient.VerifyAll();
        }