ftw icon indicating copy to clipboard operation
ftw copied to clipboard

py.test syntax error

Open spencescu opened this issue 5 years ago • 6 comments

I am getting the errors below when trying to execute py.test. Also, are you guys not supplying a test file for the OWASP ruleset? Are we expected to write our own? Thanks in advance!

$ py.test test/test_default.py --ruledir test/yaml usage: py.test [options] [file_or_dir] [file_or_dir] [...] py.test: error: unrecognized arguments: --ruledir test/yaml inifile: None rootdir: /Users/sherman/Fastly/ftw

spencescu avatar Mar 07 '19 20:03 spencescu

There is quick start documentation here:

https://github.com/fastly/ftw/blob/master/docs/basic_usage.md

If you want to run a test corpus specifically for the OWASP CRS, they can be found here:

https://github.com/SpiderLabs/owasp-modsecurity-crs/tree/update-contributing-v3.2/util/regression-tests

The CRS tests assume that you have the Modsecurity log, so you will need to adjust the configuration (settings.ini) to match your environment. More documentation can be found in the README.md for the repository path linked above.

Hope this helps. Thanks!

csjperon avatar Mar 08 '19 21:03 csjperon

One last question: I don't want to test a local WAF - can I use this framework for it by just pointing to an IP address?

Thank you!

On Fri, Mar 8, 2019 at 11:02 PM Christian S.J. Peron < [email protected]> wrote:

There is quick start documentation here:

https://github.com/fastly/ftw/blob/master/docs/basic_usage.md

If you want to run a test corpus specifically for the the OWASP CRS, they can be found here:

https://github.com/SpiderLabs/owasp-modsecurity-crs/tree/update-contributing-v3.2/util/regression-tests

The CRS tests assume that you have the Modsecurity log, so you will need to adjust the configuration (settings.ini) to match your environment. More documentation can be found in the README.md for the repository path linked above.

Hope this helps. Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fastly/ftw/issues/104#issuecomment-471075271, or mute the thread https://github.com/notifications/unsubscribe-auth/AKDFsoD5Rrnoyycmyp5wP1MxIpCwW5gHks5vUs_zgaJpZM4bkCKb .

spencescu avatar Mar 10 '19 07:03 spencescu

You can override the target using the --destaddr option on the command line. In some cases (like when going through a CDN) you will need to specify or override the Host: header too. If you use the docker image both options are supported:

See: https://github.com/fastly/ftw/blob/master/docs/Docker.md

However, otherwise you would need to add some code to whatever test harness you are using as done here:

https://github.com/fastly/ftw/blob/master/tools/build_journal.py#L36

(or change the actual testing corpus to reflect what you want to accomplish with respect to targets and Host: headers)

csjayp avatar Mar 11 '19 13:03 csjayp

Having the same issue. Followed the readme and the installation via virtualenv and still getting a syntax error.

P4l1ndr0m avatar Mar 16 '20 02:03 P4l1ndr0m

Edit: This appears to be a version issue with py.test. I pulled the fork(?) in the CRS-Support repo (https://github.com/CRS-support/ftw) and after following the install directions there (which include virtualenv) also followed the update from this comment to get it working: https://github.com/CRS-support/ftw/issues/38#issuecomment-572984419

-- was --

Same issue here as well. Tried install and readme instructions from above link. Running on AWS Linux.

Here's a quick dump of my environment:

[ec2-user@ip-172-31-64-72 ~]$ cat test_rules.py
#!/usr/bin/python
#
from ftw import ruleset, testrunner, http, errors
import pytest

def test_default(ruleset, test, destaddr):
    '''
        Default test with no log [logger] obj.
    '''
    runner = testrunner.TestRunner()
    try:
        last_ua = http.HttpUA()
        for stage in test.stages:
            if destaddr is not None:
                stage.input.dest_addr = destaddr
            if stage.input.save_cookie:
                runner.run_stage(stage, http_ua=last_ua)
            else:
                runner.run_stage(stage, logger_obj=None, http_ua=None)
    except errors.TestError as e:
        e.args[1]['meta'] = ruleset.meta
        pytest.fail('Failure! Message -> {0}, Context -> {1}'.format(e.args[0],e.args[1]))

[ec2-user@ip-172-31-64-72 ~]$ cat rules.yml
---
  meta:
    author: "Zack"
    enabled: true
    name: "rules.yaml"
    description: "Description"
  tests:
    -
      test_title: 1234
      stages:
        -
          stage:
            input:
              method: "GET"
              port: 80
              headers:
                  User-Agent: "Foo"
                  Host: "localhost"
              protocol: "http"
              uri: "/"
            output:
              status: 200

[ec2-user@ip-172-31-64-72 ~]$ which py.test
/usr/local/bin/py.test

[ec2-user@ip-172-31-64-72 ~]$ py.test test_rules.py --rules=rules.yml
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --rules=rules.yml
  inifile: None
  rootdir: /home/ec2-user

[ec2-user@ip-172-31-64-72 ~]$ py.test test_rules.py --rules rules.yml
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --rules rules.yml
  inifile: None
  rootdir: /home/ec2-user

[ec2-user@ip-172-31-64-72 ~]$ py.test test_rules.py --ruledir .
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --ruledir .
  inifile: None
  rootdir: /home/ec2-user

[ec2-user@ip-172-31-64-72 ~]$ py.test test_rules.py --ruledir=.
usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --ruledir=.
  inifile: None
  rootdir: /home/ec2-user

[ec2-user@ip-172-31-64-72 ~]$ ls -l
total 16
drwxrwxr-x 10 ec2-user ec2-user 4096 Jun 15 13:50 ftw
-rw-rw-r--  1 ec2-user ec2-user  456 Jun 15 13:58 rules.yml
-rw-rw-r--  1 ec2-user ec2-user  742 Jun 15 13:56 test_rules.py
drwxrwxr-x  7 ec2-user ec2-user 4096 Jun 15 13:34 waf_testbed

bobrich avatar Jun 15 '20 14:06 bobrich

try: python setup.py install

dermarr avatar Jan 18 '21 08:01 dermarr