-
Notifications
You must be signed in to change notification settings - Fork 857
Reuse prepared cache write on redirected request #11542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tests/gold_tests/redirect/redirect_to_same_origin_on_cache.replay.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| meta: | ||
| version: "1.0" | ||
|
|
||
| sessions: | ||
| - protocol: | ||
| - name: http | ||
| version: 1 | ||
| - name: tcp | ||
| - name: ip | ||
|
|
||
| transactions: | ||
| - client-request: | ||
| method: "GET" | ||
| version: "1.1" | ||
| url: /a/path/resource | ||
| headers: | ||
| fields: | ||
| - [ Host, oof.com ] | ||
| - [ Connection, keep-alive ] | ||
| - [ Content-Length, 0 ] | ||
|
|
||
| server-response: | ||
| status: 307 | ||
| headers: | ||
| fields: | ||
| - [ location, /a/new/path/resource ] | ||
| - [ content-length, 0 ] | ||
|
|
||
| proxy-response: | ||
| status: 200 | ||
| - client-request: | ||
| method: "GET" | ||
| version: "1.1" | ||
| url: /a/new/path/resource | ||
| headers: | ||
| fields: | ||
| - [ Host, oof.com ] | ||
| - [ Connection, keep-alive ] | ||
| - [ Content-Length, 0 ] | ||
|
|
||
| server-response: | ||
| status: 200 | ||
| reason: OK | ||
| headers: | ||
| fields: | ||
| - [ content-length, 16 ] | ||
|
|
||
| proxy-response: | ||
| status: 200 |
140 changes: 140 additions & 0 deletions
140
tests/gold_tests/redirect/redirect_to_same_origin_on_cache.test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import functools | ||
| from typing import Any, Callable, Dict, Optional | ||
|
|
||
| from ports import get_port | ||
|
|
||
| Test.Summary = 'Tests SNI port-based routing' | ||
|
|
||
| TestParams = Dict[str, Any] | ||
|
|
||
|
|
||
| class TestRedirectToSameOriginOnCache: | ||
| """Configure a test for reproducing #9275.""" | ||
|
|
||
| replay_filepath_one: str = "redirect_to_same_origin_on_cache.replay.yaml" | ||
| client_counter: int = 0 | ||
| server_counter: int = 0 | ||
| ts_counter: int = 0 | ||
|
|
||
| def __init__(self, name: str, /, autorun) -> None: | ||
| """Initialize the test. | ||
|
|
||
| :param name: The name of the test. | ||
| """ | ||
| self.name = name | ||
| self.autorun = autorun | ||
|
|
||
| def _init_run(self) -> "TestRun": | ||
| """Initialize processes for the test run.""" | ||
|
|
||
| tr = Test.AddTestRun(self.name) | ||
| server_one = TestRedirectToSameOriginOnCache.configure_server(tr, "oof.com") | ||
| self._configure_traffic_server(tr, server_one) | ||
| dns = TestRedirectToSameOriginOnCache.configure_dns(tr, server_one, self._dns_port) | ||
|
|
||
| tr.Processes.Default.StartBefore(server_one) | ||
| tr.Processes.Default.StartBefore(dns) | ||
| tr.Processes.Default.StartBefore(self._ts) | ||
|
|
||
| return { | ||
| "tr": tr, | ||
| "ts": self._ts, | ||
| "server_one": server_one, | ||
| "port_one": self._port_one, | ||
| } | ||
|
|
||
| @classmethod | ||
| def runner(cls, name: str, autorun: bool = True) -> Optional[Callable]: | ||
| """Create a runner for a test case. | ||
|
|
||
| :param autorun: Run the test case once it's set up. Default is True. | ||
| """ | ||
| test = cls(name, autorun=autorun)._prepare_test_case | ||
| return test | ||
|
|
||
| def _prepare_test_case(self, func: Callable) -> Callable: | ||
| """Set up a test case and possibly run it. | ||
|
|
||
| :param func: The test case to set up. | ||
| """ | ||
| functools.wraps(func) | ||
| test_params = self._init_run() | ||
|
|
||
| def wrapper(*args, **kwargs) -> Any: | ||
| return func(test_params, *args, **kwargs) | ||
|
|
||
| if self.autorun: | ||
| wrapper() | ||
| return wrapper | ||
|
|
||
| @staticmethod | ||
| def configure_server(tr: "TestRun", domain: str): | ||
| server = tr.AddVerifierServerProcess( | ||
| f"server{TestRedirectToSameOriginOnCache.server_counter}.{domain}", | ||
| TestRedirectToSameOriginOnCache.replay_filepath_one, | ||
| other_args="--format \"{url}\"") | ||
| TestRedirectToSameOriginOnCache.server_counter += 1 | ||
|
|
||
| return server | ||
|
|
||
| @staticmethod | ||
| def configure_dns(tr: "TestRun", server_one: "Process", dns_port: int): | ||
| dns = tr.MakeDNServer("dns", port=dns_port, default="127.0.0.1") | ||
| return dns | ||
|
|
||
| def _configure_traffic_server(self, tr: "TestRun", server_one: "Process"): | ||
| """Configure Traffic Server. | ||
|
|
||
| :param tr: The TestRun object to associate the ts process with. | ||
| """ | ||
| ts = tr.MakeATSProcess( | ||
| f"ts-{TestRedirectToSameOriginOnCache.ts_counter}", select_ports=False, enable_tls=True, enable_cache=True) | ||
| TestRedirectToSameOriginOnCache.ts_counter += 1 | ||
|
|
||
| self._port_one = get_port(ts, "PortOne") | ||
| self._dns_port = get_port(ts, "DNSPort") | ||
| ts.Disk.records_config.update( | ||
| { | ||
| 'proxy.config.http.server_ports': f"{self._port_one}", | ||
| 'proxy.config.diags.debug.enabled': 1, | ||
| 'proxy.config.diags.debug.tags': "cache|dns|http|redirect|remap", | ||
| 'proxy.config.dns.nameservers': f"127.0.0.1:{self._dns_port}", | ||
| 'proxy.config.dns.resolv_conf': 'NULL', | ||
| 'proxy.config.http.redirect.actions': "self:follow", | ||
| 'proxy.config.http.number_of_redirections': 1, | ||
| }) | ||
|
|
||
| ts.Disk.remap_config.AddLine(f"map oof.com http://oof.backend.com:{server_one.Variables.http_port}") | ||
|
|
||
| self._ts = ts | ||
|
|
||
|
|
||
| # Tests start. | ||
|
|
||
|
|
||
| @TestRedirectToSameOriginOnCache.runner("Redirect to same origin with cache") | ||
| def test1(params: TestParams) -> None: | ||
| client = params["tr"].AddVerifierClientProcess( | ||
| f"client0", | ||
| TestRedirectToSameOriginOnCache.replay_filepath_one, | ||
| http_ports=[params["port_one"]], | ||
| other_args="--format \"{url}\" --keys \"/a/path/resource\"") | ||
|
|
||
| params["tr"].Processes.Default.ReturnCode = 0 | ||
| params["tr"].Processes.Default.Streams.stdout.Content += Testers.IncludesExpression("200 OK", "We should get the resource.") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.