goss-org / goss

Quick and Easy server testing/validation
https://goss.rocks
Apache License 2.0
5.57k stars 472 forks source link

file: contains does not match on multiline regex #235

Closed FlxPeters closed 4 years ago

FlxPeters commented 7 years ago

Hi,

i have an issue with the file contains check. I want to check if a HAProxy frontend is available. The config files contains the following lines:

# /etc/haproxy/haproxy.cfg
frontend haproxy_frontend_redirect
    bind *:80
    redirect scheme https if !{ ssl_fc }

My goss.yaml contains ist the following check:

file:
  /etc/haproxy/haproxy.cfg:
    exists: true
    owner: root
    group: root
    filetype: file
    contains:
    - "/frontend haproxy_frontend_redirect\\n\\s*bind\\s*\\*:80/"

goss validate gives me the return, that my regex does not match the content of the file.

Failures/Skipped:

File: /etc/haproxy/haproxy.cfg: contains: patterns not found: [/frontend haproxy_frontend_redirect\n\s*bind\s*\*:80/]

The regex is valid. You can find an example here: https://regex101.com/r/Gp2Ray/1

Is it a bug or how is a multiline regex possible? As you can see, it is important, that this rows are directly connmected without any other text betweeen.

aelsabbahy commented 7 years ago

Currently goss doesn't support multiline regex, it scans a file one-line at a time so it doesn't have to load whole files into memory.

If this is an important feature for you, we can mark this as an "enhancement" and work through the details.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

aelsabbahy commented 4 years ago

For what it's worth, this will be part of goss v0.4.0:

cat /tmp/haproxy.cfg 
frontend haproxy_frontend_redirect
    bind *:80
    redirect scheme https if !{ ssl_fc }
file:
  /tmp/haproxy.cfg:
    exists: true
    contains:
      match-regexp: 'frontend haproxy_frontend_redirect\n\s*bind\s*\*:80'
$ goss v --format documentation
File: /tmp/haproxy.cfg: exists: matches expectation: true
File: /tmp/haproxy.cfg: contains: matches expectation: {"match-regexp":"frontend haproxy_frontend_redirect\\n\\s*bind\\s*\\*:80"}

Total Duration: 0.000s
Count: 2, Failed: 0, Skipped: 0