-
Notifications
You must be signed in to change notification settings - Fork 682
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
Adds support for iis_app InSpec testing #1905
Conversation
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.
@EasyAsABC123 well done! I'm so green when it comes to Windows knowledge, so it brings me great joy to see PRs like this come in.
I have two things I'd love to see changed before we move forward on this. Otherwise, it's a very clean implementation and I can't wait to get it into InSpec.
lib/resources/iis_app.rb
Outdated
end | ||
|
||
def has_protocol?(protocol) | ||
(iis_app[:protocols].include? protocol) |
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.
This syntax is a bit strange. Can we change this to:
iis_app[:protocols].include?(protocol)
lib/resources/iis_app.rb
Outdated
|
||
def iis_app | ||
return @cache unless @cache.nil? | ||
@cache = @app_provider.iis_app(@path, @site_name) unless @app_provider.nil? |
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.
We usually introduce a new "provider" class like this whenever we have a situation where we may need to interact differently with a target depending on the OS type/version, etc. In this case, since this will only be supported on windows, we can probably get rid of AppProvider
and move the contents of AppProvider#iis_app
into this iis_app
method. That will eliminate an unnecessary layer of abstraction.
da9d24e
to
d0c68ec
Compare
@adamleff let me know if this is what you meant |
@EasyAsABC123 yes, exactly! Now you're failing tests unfortunately. It looks like indentation got messed up which has led to you missing an Ping me once you've got that fixed up and I'll give it another review. |
d0c68ec
to
632f2fc
Compare
@adamleff good catch, totally didn't notice. It is now fixed |
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.
@EasyAsABC123 well done! Thanks for your contribution!
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.
Great job @EasyAsABC123 I left some comments about minor improvements. Once they are addressed, LGTM
lib/resources/iis_app.rb
Outdated
"iis_app '#{@site_name}#{@path}'" | ||
end | ||
|
||
def iis_app |
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.
This should be a private function
lib/resources/iis_app.rb
Outdated
# frozen_string_literal: true | ||
# check for web applications in IIS | ||
# Usage: | ||
# describe iis_app('/myapp', 'Website') do |
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.
I think we do not need the usage comments here, since it is part of the inline examples
@@ -16,7 +16,7 @@ | |||
include_recipe('os_prepare::service') | |||
include_recipe('os_prepare::package') | |||
include_recipe('os_prepare::registry_key') | |||
include_recipe('os_prepare::iis_site') | |||
include_recipe('os_prepare::iis') |
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.
This is a good move. We should add this resource to our integration tests then too
632f2fc
to
934c61b
Compare
@chris-rock Thanks, good recommendations. Added them, although i implemented New-WebApplication as a powershell script for testing purposes. |
lib/resources/iis_app.rb
Outdated
|
||
def iis_app | ||
return @cache unless @cache.nil? | ||
command = "Import-Module WebAdministration; Get-WebApplication -Name '#{@path}' -Site '#{@site_name}' | Select-Object * | ConvertTo-Json" |
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.
Missed that before: What are the preconditions for the Powershell module? Can we expect this is deployed on IIS servers?
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.
None that i'm aware of this is just a built in module for 2012r2 as far as i know, i am avoid xWebAdministration for this reason.
For Windows 7 to 10 you will need to install the feature IIS Management Scripts and tools under Internet Information Services >> Web Management Tools
So it should be done simply from the IIS install.
Wow, that was quick :-) |
Signed-off-by: Justin Schuhmann <[email protected]>
934c61b
to
906251f
Compare
yeah, can't sleep...always a bummer tomorrow is going to be a coffee fueled haze |
|
||
def iis_app | ||
return @cache unless @cache.nil? | ||
command = "Import-Module WebAdministration; Get-WebApplication -Name '#{@path}' -Site '#{@site_name}' | Select-Object * | ConvertTo-Json" |
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.
One last question: What is the requirement for the WebAdministration module. Will it be on all IIS servers by default or do users need to install it?
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.
@chris-rock
None that i'm aware of this is just a built in module for 2012r2 as far as i know, i am avoid xWebAdministration for this reason.
For Windows 7 to 10 you will need to install the feature IIS Management Scripts and tools under Internet Information Services >> Web Management Tools
So it should be done simply from the IIS install.
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.
Perfect, thank you.
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.
@chris-rock never an issue, i'll take these recommendations to the other inspec resources i've written in the iis-cookbook
.
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.
Do you want to bring more of those resources into core inspec?
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.
@chris-rock of course! i'll be bringing them over one at a time to keep the reviews small.
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.
Very cool. Thank you for doing that!
Signed-off-by: Justin Schuhmann [email protected]