Skip to content
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

allows patch levels (ie 9.5.14) #26

Merged
merged 3 commits into from
Sep 13, 2018
Merged

allows patch levels (ie 9.5.14) #26

merged 3 commits into from
Sep 13, 2018

Conversation

ojongerius
Copy link
Contributor

@ojongerius ojongerius commented Sep 3, 2018

This broke after #25 went in

  ×  postgres-02: Use stable postgresql version (1 failed)
     ×  Command psql -V stdout should match /\b9\.[3-6]$|\b10\.5$/
     expected "psql (PostgreSQL) 9.5.14\n" to match /\b9\.[3-6]$|\b10\.5$/
     Diff:
     @@ -1,2 +1,2 @@
     -/\b9\.[3-6]$|\b10\.5$/
     +psql (PostgreSQL) 9.5.14

Using this PR:

  ✔  postgres-02: Use stable postgresql version
     ✔  Command psql -V stdout should match /(\b9\.[3-6]|\b10\.5)\.[0-9]+$/
     ✔  Command psql -V stdout should not match /RC/
     ✔  Command psql -V stdout should not match /DEVEL/
     ✔  Command psql -V stdout should not match /BETA/

See http://rubular.com/r/2aiU6kIEG6

@chris-rock
Copy link
Member

chris-rock commented Sep 4, 2018

@ojongerius Thank you for highlighting the issue and your first time contribution. 💯 You are right that we should support all patch versions.

I propose the following regex instead \b((9\.[3-6]|\b10\.5)(\.\d*)*)$. Yours only matched releases that had a patch version.

@ojongerius
Copy link
Contributor Author

Good catch! Should be addressed in 5947fa4. Let me know if you prefer me to rebase to one commit.

@pmav99
Copy link
Contributor

pmav99 commented Sep 4, 2018

Please check this too: inspec/inspec#3349

I believe that neither regex will match postgresql 10 output on ubuntu:

$ psql -V
psql (PostgreSQL) 10.5 (Ubuntu 10.5-1.pgdg16.04+1)

I think that using a look behind is necessary here. E.g.

(?<=\)\s)\b((9\.[3-6]|\b10\.5)(\.\d+)*)\b

http://rubular.com/r/yEW71p2lph

@chris-rock
Copy link
Member

Thank you for pointing this out @pmav99 I think it is right to fix the detection upstream in InSpec. Could we also use a simpler regex for the detection? ^psql\s\(PostgreSQL\)\s((9\.[3-6]|10\.5)(\.\d*)*) http://rubular.com/r/ErwU6FlP4J

@pmav99
Copy link
Contributor

pmav99 commented Sep 4, 2018

@chris-rock I think that the regex you propose is not correct because it does match the text too. I don't have much experience with ruby but according to this ruby regexes do not support non-capturing groups. This is why I proposed a look behind.

Although it seems that there is indeed a simpler solution:

"psql (PostgreSQL) 9.6.10".split[2]
"psql (PostgreSQL) 10.5 (Ubuntu 10.5-1.pgdg16.04+1)".split[2]

@ojongerius
Copy link
Contributor Author

I'm not too familiar with Inspec, what does the match matcher do exactly?

Does it test if something matched at all? ie are we trying to make something like 'psql (PostgreSQL) 10.5 (Ubuntu 10.5-1.pgdg16.04+1)' =~ /^psql\s\(PostgreSQL\)\s((9\.[3-6]|10\.5)(\.\d*)*)/ return anything other than nil or does Inspec compare the left side (stdout of a command in this case) of 'should match' with a particular match from the right side (the regexp).

Generally simpler is better, both easier to read and maintain, how about /^psql\s\(PostgreSQL\)\s(9\.[3-6]|10\.5).*/ ? Anyone packaging Postgres could add their own version strings, and we only care about the major and minor versions.

@chris-rock
Copy link
Member

The inspec matcher is just running the regular expression and checks if it matches. Maybe we should write a simple pg_version resource that parses the output and returns a version struct. This allows us to focus on version numbers only for the comparison. It also is easier to read and understand.

@ojongerius
Copy link
Contributor Author

@chris-rock ta. Would that resource do more than test if /^psql\s\(PostgreSQL\)\s(9\.[3-6]|10\.5).*/ matches?

If not, I'd say let's go with /^psql\s\(PostgreSQL\)\s(9\.[3-6]|10\.5).*/ and be done with it.

@ojongerius
Copy link
Contributor Author

@chris-rock ping!

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ojongerius for addressing that issue and for your contribution. This looks good to me. Lets see if we need to improve this further later.

@chris-rock chris-rock merged commit 1528d2c into dev-sec:master Sep 13, 2018
@ojongerius ojongerius deleted the support_patch_levels branch September 13, 2018 07:31
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants