Example #1
0
        public void should_return_response_200_using_identity_server()
        {
            var configuration = new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamPathTemplate = _downstreamServicePath,
                        DownstreamPort         = _downstreamServicePort,
                        DownstreamHost         = _downstreamServiceHost,
                        DownstreamScheme       = _downstreamServiceScheme,
                        UpstreamPathTemplate   = "/",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        AuthenticationOptions = new FileAuthenticationOptions
                        {
                            AuthenticationProviderKey = "Test"
                        }
                    }
                }
            };

            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", "api2", AccessTokenType.Jwt))
            .And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 200, "Hello from Laura"))
            .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
            .And(x => _steps.GivenThereIsAConfiguration(configuration))
            .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
            .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
            .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
            .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
            .BDDfy();
        }
        public void should_return_response_200_authorising_route()
        {
            int port = 52875;

            var configuration = new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamPathTemplate = "/",
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "localhost",
                                Port = port,
                            }
                        },
                        DownstreamScheme     = "http",
                        UpstreamPathTemplate = "/",
                        UpstreamHttpMethod   = new List <string> {
                            "Get"
                        },
                        AuthenticationOptions = new FileAuthenticationOptions
                        {
                            AuthenticationProviderKey = "Test"
                        },
                        AddHeadersToRequest =
                        {
                            { "CustomerId", "Claims[CustomerId] > value" },
                            { "LocationId", "Claims[LocationId] > value" },
                            { "UserType",   "Claims[sub] > value[0] > |" },
                            { "UserId",     "Claims[sub] > value[1] > |" }
                        },
                        AddClaimsToRequest =
                        {
                            { "CustomerId", "Claims[CustomerId] > value" },
                            { "UserType",   "Claims[sub] > value[0] > |" },
                            { "UserId",     "Claims[sub] > value[1] > |" }
                        },
                        RouteClaimsRequirement =
                        {
                            { "UserType", "registered" }
                        }
                    }
                }
            };

            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
            .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura"))
            .And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
            .And(x => _steps.GivenThereIsAConfiguration(configuration))
            .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
            .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
            .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
            .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
            .BDDfy();
        }
Example #3
0
        public void should_return_response_200_authorising_route()
        {
            var configuration = new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamPathTemplate = "/",
                        DownstreamPort         = 51876,
                        DownstreamScheme       = "http",
                        DownstreamHost         = "localhost",
                        UpstreamPathTemplate   = "/",
                        UpstreamHttpMethod     = new List <string> {
                            "Get"
                        },
                        AuthenticationOptions = new FileAuthenticationOptions
                        {
                            AllowedScopes        = new List <string>(),
                            Provider             = "IdentityServer",
                            IdentityServerConfig = new FileIdentityServerConfig {
                                ProviderRootUrl = "http://localhost:51888",
                                RequireHttps    = false,
                                ApiName         = "api",
                                ApiSecret       = "secret"
                            }
                        },
                        AddHeadersToRequest =
                        {
                            { "CustomerId", "Claims[CustomerId] > value" },
                            { "LocationId", "Claims[LocationId] > value" },
                            { "UserType",   "Claims[sub] > value[0] > |" },
                            { "UserId",     "Claims[sub] > value[1] > |" }
                        },
                        AddClaimsToRequest =
                        {
                            { "CustomerId", "Claims[CustomerId] > value" },
                            { "UserType",   "Claims[sub] > value[0] > |" },
                            { "UserId",     "Claims[sub] > value[1] > |" }
                        },
                        RouteClaimsRequirement =
                        {
                            { "UserType", "registered" }
                        }
                    }
                }
            };

            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt))
            .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura"))
            .And(x => _steps.GivenIHaveAToken("http://localhost:51888"))
            .And(x => _steps.GivenThereIsAConfiguration(configuration))
            .And(x => _steps.GivenOcelotIsRunning())
            .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
            .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
            .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
            .BDDfy();
        }
Example #4
0
        public void should_return_response_200_and_foward_claim_as_header()
        {
            var user = new TestUser()
            {
                Username  = "******",
                Password  = "******",
                SubjectId = "registered|1231231",
                Claims    = new List <Claim>
                {
                    new Claim("CustomerId", "123"),
                    new Claim("LocationId", "1")
                }
            };

            var configuration = new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamPathTemplate = "/",
                        DownstreamPort         = 52876,
                        DownstreamScheme       = "http",
                        DownstreamHost         = "localhost",
                        UpstreamTemplate       = "/",
                        UpstreamHttpMethod     = "Get",
                        AuthenticationOptions  = new FileAuthenticationOptions
                        {
                            AdditionalScopes = new List <string>
                            {
                                "openid", "offline_access"
                            },
                            Provider        = "IdentityServer",
                            ProviderRootUrl = "http://localhost:52888",
                            RequireHttps    = false,
                            ScopeName       = "api",
                            ScopeSecret     = "secret",
                        },
                        AddHeadersToRequest =
                        {
                            { "CustomerId", "Claims[CustomerId] > value" },
                            { "LocationId", "Claims[LocationId] > value" },
                            { "UserType",   "Claims[sub] > value[0] > |" },
                            { "UserId",     "Claims[sub] > value[1] > |" }
                        }
                    }
                }
            };

            this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:52888", "api", AccessTokenType.Jwt, user))
            .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:52876", 200))
            .And(x => _steps.GivenIHaveAToken("http://localhost:52888"))
            .And(x => _steps.GivenThereIsAConfiguration(configuration))
            .And(x => _steps.GivenOcelotIsRunning())
            .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
            .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
            .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231"))
            .BDDfy();
        }
        public void should_return_200_and_change_downstream_path()
        {
            var user = new TestUser()
            {
                Username  = "******",
                Password  = "******",
                SubjectId = "registered|1231231",
            };

            int port = RandomPortFinder.GetRandomPort();

            var configuration = new FileConfiguration
            {
                Routes = new List <FileRoute>
                {
                    new FileRoute
                    {
                        DownstreamPathTemplate = "/users/{userId}",
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "localhost",
                                Port = port,
                            },
                        },
                        DownstreamScheme     = "http",
                        UpstreamPathTemplate = "/users",
                        UpstreamHttpMethod   = new List <string> {
                            "Get"
                        },
                        AuthenticationOptions = new FileAuthenticationOptions
                        {
                            AuthenticationProviderKey = "Test",
                            AllowedScopes             = new List <string>
                            {
                                "openid", "offline_access", "api",
                            },
                        },
                        ChangeDownstreamPathTemplate =
                        {
                            { "userId", "Claims[sub] > value[1] > |" },
                        },
                    },
                },
            };

            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, user))
            .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200))
            .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
            .And(x => _steps.GivenThereIsAConfiguration(configuration))
            .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
            .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
            .When(x => _steps.WhenIGetUrlOnTheApiGateway("/users"))
            .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(x => _steps.ThenTheResponseBodyShouldBe("UserId: 1231231"))
            .And(x => _downstreamFinalPath.ShouldBe("/users/1231231"))
            .BDDfy();
        }
        public void should_return_response_200_and_foward_claim_as_query_string()
        {
            var user = new TestUser()
            {
                Username  = "******",
                Password  = "******",
                SubjectId = "registered|1231231",
                Claims    = new List <Claim>
                {
                    new Claim("CustomerId", "123"),
                    new Claim("LocationId", "1")
                }
            };

            int port = RandomPortFinder.GetRandomPort();

            var configuration = new FileConfiguration
            {
                ReRoutes = new List <FileReRoute>
                {
                    new FileReRoute
                    {
                        DownstreamPathTemplate = "/",
                        DownstreamHostAndPorts = new List <FileHostAndPort>
                        {
                            new FileHostAndPort
                            {
                                Host = "localhost",
                                Port = port,
                            }
                        },
                        DownstreamScheme     = "http",
                        UpstreamPathTemplate = "/",
                        UpstreamHttpMethod   = new List <string> {
                            "Get"
                        },
                        AuthenticationOptions = new FileAuthenticationOptions
                        {
                            AuthenticationProviderKey = "Test",
                            AllowedScopes             = new List <string>
                            {
                                "openid", "offline_access", "api"
                            },
                        },
                        AddQueriesToRequest =
                        {
                            { "CustomerId", "Claims[CustomerId] > value" },
                            { "LocationId", "Claims[LocationId] > value" },
                            { "UserType",   "Claims[sub] > value[0] > |" },
                            { "UserId",     "Claims[sub] > value[1] > |" }
                        }
                    }
                }
            };

            this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, user))
            .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200))
            .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
            .And(x => _steps.GivenThereIsAConfiguration(configuration))
            .And(x => _steps.GivenOcelotIsRunning(_options, "Test"))
            .And(x => _steps.GivenIHaveAddedATokenToMyRequest())
            .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
            .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
            .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231"))
            .BDDfy();
        }