-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat: use test host name for marker if localhost alias #370
Conversation
What's the use case? |
Ok, I understand the use case. |
Thanks for the feedback! |
eb5fd5a
to
5c2a285
Compare
I just tested this PR against CRS and it causes tests to fail. For example, for one test the host header is set to @airween How were you expecting to handle those kinds of tests with your setup? |
Excellent! This is what I exactly needed! Now I can configure different virtual hosts with separated log files, and I'm able to use Thanks guys! |
runner/run.go
Outdated
if host == "" { | ||
host = "localhost" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theseion Maybe we can add an url parse here, if we prefix the host with http://
. E.g.
u, err := url.Parse("http://localhost%00")
if err != nil {
log.Fatal(err)
}
For the test that fails:
2009/11/10 23:00:00 parse "http://localhost%00": invalid URL escape "%00"
And if err != nil
we resort to just localhost
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me have a chat with @airween. Let's see what he really needs.
Let me explain how do (or would) I use this. I've created a new feature for mod_security and want to test that. I've created a special rule set for that, so I don't use CRS. Therefore I created an own test set against that rule set. I've created the tests based on ftw-tests-schema because I wanted to use ftw. But I definitely didn't want to create a new test environment, so I've created a new virtual host in my Apache config, something like this:
Usually I used to configure vhosts that it uses separated logs:
and here is how I configured ---
logfile: '/var/log/apache2/xml.mytest.site-error.log'
logmarkerheadername: 'X-XML-Test'
logtype:
name: 'apache' (and I put a special rule into my rule set:
) When I test that patch during the developing phase I use
After I finished the development I've created tests. A test file looks like this: ---
meta:
author: "airween"
rule_id: 20100
tests:
- test_id: 1
stages:
- description: "New feature test"
input:
dest_addr: "127.0.0.1"
port: 80
method: "POST"
headers:
User-Agent: "OWASP CRS test agent"
Host: "xml.mytest.site"
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Content-Type: "application/xml" So I thought ftw uses both I didn't think that ftw wants to resolve the address. If this is a question to be decided, I would suggest that if both values ( |
That is correct. Note that with your current setup you cannot write tests for I propose that we amend the schema and add a |
Perhaps it's not important to me but I don't see the reason why. I thought each test has a marker and a flusher request, so when ftw reads the test, it builds the marker request too (not before) and uses the
Yes, that was the issue explained in #361.
Yes, I know, but it wasn't problem for me (in this case).
What would be the difference between tests:
- test_id: 1
stages:
- description: "New feature test"
input:
dest_addr: "127.0.0.1"
port: 80
method: "POST"
virtual_host: "xml.mytest.site"
headers:
User-Agent: "OWASP CRS test agent"
Host: "xml.mytest.site" (indeed the In this case, what value would be used for the request Or do you mean |
The internal request (mark / flush) uses
In this case we want to test that a rule that verifies the
Yes.
Actually, maybe we don't need a field |
Ah, now I see the point - thanks. Then I think the most clear solution would be an optional key (eg. What do you think? |
That was my initial idea with We can call the field something like |
Except if the test uses
Would it be a boolean type or a string? Now I think the string variable is the solution. |
I was thinking boolean. Not sure what you mean, what would the value of |
Consider the following test: tests:
- test_id: 1
stages:
- description: "New feature test"
use_host_for_marker_request: "xml.mytest.site"
input:
dest_addr: "127.0.0.1"
port: 80
method: "POST"
headers:
User-Agent: "OWASP CRS test agent"
Host: "xml.mytest.site%00"
output:
no_expect_ids: [123456] As you can see I put With this method, in special cases we can check the |
That's a good point. However, you could simply rewrite the test with I have no hard opinion on this but I would like to keep things as simple as possible and would prefer boolean over virtual host name. |
@fzipi do you want to pick this up again with the resolution we found? Or would you like me to continue? |
Pick it up, I can approve 😄 |
I've opened coreruleset/ftw-tests-schema#29 to amend the schema. |
By default, internal requests (i.e., requests for marking and flushing the web server log) use `localhost` for the `Host` header value. In scenarios, where tests are run against a virtual host this will cause the internal requests to be processed by the default virtual host while the test requests will be processed by the targeted virtual host. If the web server logs are segregated by virtual host, internal and test requests will end up in different log files and go-ftw will not be able to find the markers it is looking for. With `virtual_host_mode: true`, the value of the `Host` header from the test input will be used for internal requests, to ensure that internal requests will also be processed by the targeted virtual host. Fixes #361
5c2a285
to
73e0a29
Compare
@fzipi please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
what
why
caveats
Fixes #361