Skip to content

Commit 0c00193

Browse files
authored
Fix multiple option instances and blocks (#645)
Fixes #643 and #644
1 parent 49bfd45 commit 0c00193

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This file is used to list changes made in each version of the nginx cookbook.
44

55
## Unreleased
66

7+
- Correct trailing semicolon for blocks - [#643](https://github.com/sous-chefs/nginx/issues/643)
8+
- Support multiple options - [#644](https://github.com/sous-chefs/nginx/issues/644)
9+
710
## 12.2.13 - *2025-01-07*
811

912
- Convert all test files to proper InSpec format with controls and metadata

templates/default/site-template.erb

+7-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ server {
5757
location <%= location %> {
5858
<% unless nil_or_empty?(options) -%>
5959
<% options.each do |option, value| -%>
60-
<%= option %><% unless nil_or_empty?(value) -%> <%= value %><% end -%>;
60+
<% if nil_or_empty?(value) -%>
61+
<%= option %>;
62+
<% else -%>
63+
<% Array(value).each do |val| -%>
64+
<%= option %> <%= val %><% unless String(val).end_with?('}') -%>;<% end -%>
65+
<% end -%>
66+
<% end -%>
6167
<% end -%>
6268
<% end -%>
6369
}

test/cookbooks/test/recipes/test_site.rb

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
'/' => {
2727
'root' => '/var/www/nginx-default',
2828
'index' => 'index.html index.htm',
29+
'proxy_set_header' => [
30+
'Connection ""',
31+
'X-My-Real-IP $remote_addr',
32+
'X-My-Real-Port $remote_port',
33+
'X-My-Server-Port $server_port',
34+
],
35+
'limit_except' => 'GET POST { deny all; }',
2936
},
3037
},
3138
}

test/integration/default/controls/config_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
it { should exist }
8888
it { should be_file }
8989
its('mode') { should cmp '0644' }
90+
its('content') { should include 'proxy_set_header X-My-Real-IP $remote_addr;' }
91+
its('content') { should include 'proxy_set_header X-My-Real-Port $remote_port;' }
92+
its('content') { should include 'limit_except GET POST { deny all; }' }
9093
end
9194

9295
describe file('/etc/nginx/conf.http.d/test_site_disabled.conf.disabled') do

0 commit comments

Comments
 (0)