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

file content doesn't work properly #244

Open
maratsal opened this issue Oct 27, 2019 · 5 comments
Open

file content doesn't work properly #244

maratsal opened this issue Oct 27, 2019 · 5 comments
Labels
Aspect: UX How users feel interacting with the project, focusing on function, ease-of-use and accessibility. Triage: Needs Verify

Comments

@maratsal
Copy link

Describe the problem

When run kitchen verify it reports that content of the file is not matching. However when I check file content manually - the content is right. Seems when kitchen verify is fetching content of the file it appends ssh last login information to the content of the file:
The check:

  describe file('/etc/security/limits.d/95-hardening.conf') do
    it { should be_file }
    its('content') { should match "# FILE MANAGED BY CHEF, DO NOT EDIT\n* hard core 0" }
    its('mode') { should cmp '0644' }
  end

Failure:

  ×  hardening-base: Hardening Checks (1 failed)
     ✔  File /etc/security/limits.d/95-hardening.conf should be file
     ×  File /etc/security/limits.d/95-hardening.conf content should match "# FILE MANAGED BY CHEF, DO NOT EDIT\n* hard core 0"
     expected "# FILE MANAGED BY CHEF, DO NOT EDIT\n* hard core 0Last login: Sat Oct 26 21:09:58 EDT 2019\n" to match "# FILE MANAGED BY CHEF, DO NOT EDIT\n* hard core 0"
     Diff:
     @@ -1,3 +1,3 @@
      # FILE MANAGED BY CHEF, DO NOT EDIT
     -* hard core 0
     +* hard core 0Last login: Sat Oct 26 21:09:58 EDT 2019

chef dk version I use:

$ chef --version
ChefDK version: 4.5.1
Chef Infra Client version: 15.4.45
Chef InSpec version: 4.18.0
Test Kitchen version: 2.3.3
Foodcritic version: 16.1.1
Cookstyle version: 5.9.3

And here is my OS:

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15
BuildVersion:	19A602
@maratsal
Copy link
Author

please let me know if any other information is needed.

@miah
Copy link
Contributor

miah commented Oct 28, 2019

In your example, you use match which expects a regular expression, but you supplied a string.

You may want to try:

its('content') { should cmp "# FILE MANAGED BY CHEF, DO NOT EDIT\n* hard core 0" }

Or use a regexp

its('content') { should match /hard.core.[0]/ }

You can find all the docs on our matchers here:
https://www.inspec.io/docs/reference/matchers/

Please let us know if you're still having issues with the file resource.

@maratsal
Copy link
Author

for sure will give a try. however I think it is more some additional text added to the string from ssh session Last login: Sat Oct 26 21:09:58 EDT 2019 is causing this mismatch.

@miah miah transferred this issue from inspec/inspec Oct 31, 2019
@miah
Copy link
Contributor

miah commented Oct 31, 2019

Ok. I think this issue is something in kitchen-inspec rather than inspec.

@kekaichinose kekaichinose added Triage: Needs Verify Aspect: UX How users feel interacting with the project, focusing on function, ease-of-use and accessibility. labels Oct 31, 2019
@maratsal
Copy link
Author

Ok. I think this issue is something in kitchen-inspec rather than inspec.

Is there a way to get more verbose output from kitchen runs to get more details from the verification stage?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Aspect: UX How users feel interacting with the project, focusing on function, ease-of-use and accessibility. Triage: Needs Verify
Projects
None yet
Development

No branches or pull requests

3 participants