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

fix rewrite rules being ignored #2330

Merged
merged 7 commits into from
Feb 10, 2023
Merged

fix rewrite rules being ignored #2330

merged 7 commits into from
Feb 10, 2023

Conversation

trefzer
Copy link
Contributor

@trefzer trefzer commented Oct 12, 2022

In 7b22dae the default value for $rewrites was changed from undef to [] in manifests/vhost.pp. This results in templates_vhost/_rewrite.erb always evaluating to false (boolean check on an empty array variable is still true) unless $rewrites is explicitly set to undef. This results in the content of $rewrite_rule being ignored.

closes: #2318

@trefzer trefzer requested a review from a team as a code owner October 12, 2022 07:44
@CLAassistant
Copy link

CLAassistant commented Oct 12, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

This looks correct to me, but it'd be great if we have a test case to prevent future regressions.

@trefzer
Copy link
Contributor Author

trefzer commented Oct 30, 2022

@ekohl
I agree, but since the logic is in a template we would need to check the final content in the file which I have no idea how to do with spec test. (anyone who nows please let me know !)

@ekohl
Copy link
Collaborator

ekohl commented Nov 4, 2022

I would probably take this example:

context 'empty rewrites_with_rewrite_inherit' do
let(:params) do
super().merge(
'rewrite_inherit' => true,
'rewrites' => [],
)
end
it {
is_expected.to contain_concat__fragment('rspec.example.com-rewrite').with(
content: %r{^\s+RewriteOptions Inherit$},
)
}
end

Then copy it and pass some parameters that triggers the behavior you want to test.

Note you can also test the whole file:

it {
  is_expected.to contain_concat__fragment('rspec.example.com-rewrite').with_content <<~CONTENT
    Here you can write the full content
    And use multiple lines
  CONTENT
}

@@ -741,7 +741,10 @@
it { is_expected.to contain_concat__fragment('rspec.example.com-redirect') }
it {
is_expected.to contain_concat__fragment('rspec.example.com-rewrite').with(
content: %r{^\s+RewriteEngine On$},
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't test this way (as the action indicates), but you can chain it: .with(content: ...).with(content: ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@david22swan
Copy link
Member

@trefzer Hey sorry to bother you, just checking in on when you'll have time to finish with the sped test?

In 7b22dae the default value for $rewrites was changed
from undef to [] in manifests/vhost.pp. This results
in templates_vhost/_rewrite.erb always evaluating to
false (boolean check on an empty array variable is
still true) unless $rewrites is explicitly set to undef.
This results in the content of $rewrite_rule being ignored.

closes: #2318
Copy link
Collaborator

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

These changes should make the test suite work.

Comment on lines 745 to 740
.with_content(%r{^\s+RewriteOptions Inherit$}),
.with_content(%r{^\s+RewriteBase /}),
.with_content(%r{^\s+RewriteRule ^index\.html$ welcome.html$}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.with_content(%r{^\s+RewriteOptions Inherit$}),
.with_content(%r{^\s+RewriteBase /}),
.with_content(%r{^\s+RewriteRule ^index\.html$ welcome.html$}),
.with_content(%r{^\s+RewriteOptions Inherit$})
.with_content(%r{^\s+RewriteBase /})
.with_content(%r{^\s+RewriteRule ^index\.html$ welcome.html$})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ups :) missed them.

@@ -1,4 +1,4 @@
<%- if @rewrites -%>
<%- if @rewrite_inherit or not @rewrites.empty? -%>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%- if @rewrite_inherit or not @rewrites.empty? -%>
<%- if @rewrite_inherit or !@rewrites.empty? -%>

.with_content(%r{^\s+RewriteEngine On$})
.with_content(%r{^\s+RewriteOptions Inherit$})
.with_content(%r{^\s+RewriteBase /})
.with_content(%r{^\s+RewriteRule ^index\.html$ welcome.html$})
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should make it valid Ruby

Suggested change
)

Copy link
Member

@david22swan david22swan left a comment

Choose a reason for hiding this comment

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

LGTM

@ekohl Just checking you're good with the changes you requested?

If so will merge in and release

Copy link
Collaborator

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Yes, I'm good. All my comments were there to make the test suite pass (we'll ignore mend for now) so 👍 to merging this.

Thanks @trefzer for your efforts! And it was great to collaborate on a PR in person again. That was a long time ago for me

@david22swan david22swan merged commit ab0d406 into puppetlabs:main Feb 10, 2023
@david22swan
Copy link
Member

Good good good

Should be released by end of day

@trefzer trefzer deleted the fix_rewrite branch April 6, 2024 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@param rewrite_rule ignored in apache::vhost due to changed default value of @param rewrite
5 participants