PageRenderTime 62ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/defines/resource_vhost_spec.rb

https://github.com/xaque208/puppet-nginx
Ruby | 821 lines | 771 code | 50 blank | 0 comment | 8 complexity | 4020442f5b628c44770ffc794b4c55eb MD5 | raw file
Possible License(s): Apache-2.0
  1. require 'spec_helper'
  2. describe 'nginx::resource::vhost' do
  3. let :title do
  4. 'www.rspec.example.com'
  5. end
  6. let :default_params do
  7. {
  8. :www_root => '/',
  9. :ipv6_enable => true,
  10. }
  11. end
  12. let :facts do
  13. {
  14. :osfamily => 'Debian',
  15. :operatingsystem => 'debian',
  16. :ipaddress6 => '::',
  17. }
  18. end
  19. let :pre_condition do
  20. [
  21. 'include ::nginx::params',
  22. 'include ::nginx::config',
  23. ]
  24. end
  25. describe 'os-independent items' do
  26. describe 'basic assumptions' do
  27. let :params do default_params end
  28. it { should contain_class("nginx::params") }
  29. it { should contain_class("nginx::config") }
  30. it { should contain_concat("/etc/nginx/sites-available/#{title}.conf").with({
  31. 'owner' => 'root',
  32. 'group' => 'root',
  33. 'mode' => '0644',
  34. })}
  35. it { should contain_concat__fragment("#{title}-header").with_content(%r{access_log[ ]+/var/log/nginx/www\.rspec\.example\.com\.access\.log}) }
  36. it { should contain_concat__fragment("#{title}-header").with_content(%r{error_log[ ]+/var/log/nginx/www\.rspec\.example\.com\.error\.log}) }
  37. it { should contain_concat__fragment("#{title}-footer") }
  38. it { should contain_nginx__resource__location("#{title}-default") }
  39. it { should_not contain_file("/etc/nginx/fastcgi_params") }
  40. it { should contain_file("#{title}.conf symlink").with({
  41. 'ensure' => 'link',
  42. 'path' => "/etc/nginx/sites-enabled/#{title}.conf",
  43. 'target' => "/etc/nginx/sites-available/#{title}.conf"
  44. })}
  45. end
  46. describe "vhost_header template content" do
  47. [
  48. {
  49. :title => 'should not contain www to non-www rewrite',
  50. :attr => 'rewrite_www_to_non_www',
  51. :value => false,
  52. :notmatch => %r|
  53. ^
  54. \s+listen\s+\*:443\s+ssl;\n
  55. \s+server_name\s+www\.rspec\.example\.com;\n
  56. \s+return\s+301\s+https://rspec\.example\.com\$uri;
  57. |x,
  58. },
  59. {
  60. :title => 'should contain www to non-www rewrite',
  61. :attr => 'rewrite_www_to_non_www',
  62. :value => true,
  63. :match => [
  64. ' listen *:80;',
  65. ' server_name www.rspec.example.com;',
  66. ' return 301 http://rspec.example.com$uri;',
  67. ],
  68. },
  69. {
  70. :title => 'should set the IPv4 listen IP',
  71. :attr => 'listen_ip',
  72. :value => '127.0.0.1',
  73. :match => ' listen 127.0.0.1:80;',
  74. },
  75. {
  76. :title => 'should set the IPv4 listen port',
  77. :attr => 'listen_port',
  78. :value => 45,
  79. :match => ' listen *:45;',
  80. },
  81. {
  82. :title => 'should set the IPv4 listen options',
  83. :attr => 'listen_options',
  84. :value => 'spdy default',
  85. :match => ' listen *:80 spdy default;',
  86. },
  87. {
  88. :title => 'should enable IPv6',
  89. :attr => 'ipv6_enable',
  90. :value => true,
  91. :match => ' listen [::]:80 default ipv6only=on;',
  92. },
  93. {
  94. :title => 'should not enable IPv6',
  95. :attr => 'ipv6_enable',
  96. :value => false,
  97. :notmatch => / listen \[::\]:80 default ipv6only=on;/,
  98. },
  99. {
  100. :title => 'should set the IPv6 listen IP',
  101. :attr => 'ipv6_listen_ip',
  102. :value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  103. :match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80 default ipv6only=on;',
  104. },
  105. {
  106. :title => 'should set the IPv6 listen port',
  107. :attr => 'ipv6_listen_port',
  108. :value => 45,
  109. :match => ' listen [::]:45 default ipv6only=on;',
  110. },
  111. {
  112. :title => 'should set the IPv6 listen options',
  113. :attr => 'ipv6_listen_options',
  114. :value => 'spdy',
  115. :match => ' listen [::]:80 spdy;',
  116. },
  117. {
  118. :title => 'should set servername(s)',
  119. :attr => 'server_name',
  120. :value => ['www.foo.com','foo.com'],
  121. :match => ' server_name www.foo.com foo.com;',
  122. },
  123. {
  124. :title => 'should rewrite www servername to non-www',
  125. :attr => 'rewrite_www_to_non_www',
  126. :value => true,
  127. :match => ' server_name rspec.example.com;',
  128. },
  129. {
  130. :title => 'should not rewrite www servername to non-www',
  131. :attr => 'rewrite_www_to_non_www',
  132. :value => false,
  133. :match => ' server_name www.rspec.example.com;',
  134. },
  135. {
  136. :title => 'should set auth_basic',
  137. :attr => 'auth_basic',
  138. :value => 'value',
  139. :match => ' auth_basic "value";',
  140. },
  141. {
  142. :title => 'should set auth_basic_user_file',
  143. :attr => 'auth_basic_user_file',
  144. :value => 'value',
  145. :match => ' auth_basic_user_file value;',
  146. },
  147. {
  148. :title => 'should set the client_body_timeout',
  149. :attr => 'client_body_timeout',
  150. :value => 'value',
  151. :match => /^[ ]+client_body_timeout\s+value;/
  152. },
  153. {
  154. :title => 'should set the client_header_timeout',
  155. :attr => 'client_header_timeout',
  156. :value => 'value',
  157. :match => /^[ ]+client_header_timeout\s+value;/
  158. },
  159. {
  160. :title => 'should set the gzip_types',
  161. :attr => 'gzip_types',
  162. :value => 'value',
  163. :match => /^[ ]+gzip_types\s+value;/
  164. },
  165. {
  166. :title => 'should contain raw_prepend directives',
  167. :attr => 'raw_prepend',
  168. :value => [
  169. 'if (a) {',
  170. ' b;',
  171. '}'
  172. ],
  173. :match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
  174. },
  175. {
  176. :title => 'should contain ordered prepended directives',
  177. :attr => 'vhost_cfg_prepend',
  178. :value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
  179. :match => [
  180. ' allow test value 3;',
  181. ' test1 test value 1a;',
  182. ' test1 test value 1b;',
  183. ' test2 test value 2;',
  184. ],
  185. },
  186. {
  187. :title => 'should set root',
  188. :attr => 'use_default_location',
  189. :value => false,
  190. :match => ' root /;',
  191. },
  192. {
  193. :title => 'should not set root',
  194. :attr => 'use_default_location',
  195. :value => true,
  196. :notmatch => / root \/;/,
  197. },
  198. {
  199. :title => 'should set proxy_set_header',
  200. :attr => 'proxy_set_header',
  201. :value => ['header1','header2'],
  202. :match => [
  203. ' proxy_set_header header1;',
  204. ' proxy_set_header header2;',
  205. ],
  206. },
  207. {
  208. :title => 'should rewrite to HTTPS',
  209. :attr => 'rewrite_to_https',
  210. :value => true,
  211. :match => [
  212. ' if ($ssl_protocol = "") {',
  213. ' return 301 https://$host$request_uri;',
  214. ],
  215. },
  216. {
  217. :title => 'should not rewrite to HTTPS',
  218. :attr => 'rewrite_to_https',
  219. :value => false,
  220. :notmatch => [
  221. /if \(\$ssl_protocol = ""\) \{/,
  222. / return 301 https:\/\/\$host\$request_uri;/,
  223. ],
  224. },
  225. {
  226. :title => 'should set access_log',
  227. :attr => 'access_log',
  228. :value => '/path/to/access.log',
  229. :match => ' access_log /path/to/access.log;',
  230. },
  231. {
  232. :title => 'should set error_log',
  233. :attr => 'error_log',
  234. :value => '/path/to/error.log',
  235. :match => ' error_log /path/to/error.log;',
  236. },
  237. ].each do |param|
  238. context "when #{param[:attr]} is #{param[:value]}" do
  239. let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
  240. it { should contain_concat__fragment("#{title}-header") }
  241. it param[:title] do
  242. matches = Array(param[:match])
  243. if matches.all? { |m| m.is_a? Regexp }
  244. matches.each { |item| should contain_concat__fragment("#{title}-header").with_content(item) }
  245. else
  246. lines = subject.resource('concat::fragment', "#{title}-header").send(:parameters)[:content].split("\n")
  247. (lines & Array(param[:match])).should == Array(param[:match])
  248. end
  249. Array(param[:notmatch]).each do |item|
  250. should contain_concat__fragment("#{title}-header").without_content(item)
  251. end
  252. end
  253. end
  254. end
  255. end
  256. describe "vhost_footer template content" do
  257. [
  258. {
  259. :title => 'should not contain www to non-www rewrite',
  260. :attr => 'rewrite_www_to_non_www',
  261. :value => false,
  262. :notmatch => %r|
  263. ^
  264. \s+listen\s+\*:443\s+ssl;\n
  265. \s+server_name\s+www\.rspec\.example\.com;\n
  266. \s+return\s+301\s+https://rspec\.example\.com\$uri;
  267. |x,
  268. },
  269. {
  270. :title => 'should contain include directives',
  271. :attr => 'include_files',
  272. :value => [ '/file1', '/file2' ],
  273. :match => [
  274. %r'^[ ]+include\s+/file1;',
  275. %r'^[ ]+include\s+/file2;',
  276. ],
  277. },
  278. {
  279. :title => 'should contain ordered appended directives',
  280. :attr => 'vhost_cfg_append',
  281. :value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
  282. :match => [
  283. ' allow test value 3;',
  284. ' test1 test value 1;',
  285. ' test2 test value 2a;',
  286. ' test2 test value 2b;',
  287. ],
  288. },
  289. {
  290. :title => 'should contain raw_append directives',
  291. :attr => 'raw_append',
  292. :value => [
  293. 'if (a) {',
  294. ' b;',
  295. '}'
  296. ],
  297. :match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
  298. },
  299. ].each do |param|
  300. context "when #{param[:attr]} is #{param[:value]}" do
  301. let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
  302. it { should contain_concat__fragment("#{title}-footer") }
  303. it param[:title] do
  304. matches = Array(param[:match])
  305. if matches.all? { |m| m.is_a? Regexp }
  306. matches.each { |item| should contain_concat__fragment("#{title}-footer").with_content(item) }
  307. else
  308. lines = subject.resource('concat::fragment', "#{title}-footer").send(:parameters)[:content].split("\n")
  309. (lines & Array(param[:match])).should == Array(param[:match])
  310. end
  311. Array(param[:notmatch]).each do |item|
  312. should contain_concat__fragment("#{title}-footer").without_content(item)
  313. end
  314. end
  315. end
  316. end
  317. end
  318. describe "vhost_ssl_header template content" do
  319. [
  320. {
  321. :title => 'should not contain www to non-www rewrite',
  322. :attr => 'rewrite_www_to_non_www',
  323. :value => false,
  324. :notmatch => %r|
  325. ^
  326. \s+listen\s+\*:443\s+ssl;\n
  327. \s+server_name\s+www\.rspec\.example\.com;\n
  328. \s+return\s+301\s+https://rspec\.example\.com\$uri;
  329. |x,
  330. },
  331. {
  332. :title => 'should contain www to non-www rewrite',
  333. :attr => 'rewrite_www_to_non_www',
  334. :value => true,
  335. :match => [
  336. ' listen *:443 ssl;',
  337. ' server_name www.rspec.example.com;',
  338. ' return 301 https://rspec.example.com$uri;',
  339. ],
  340. },
  341. {
  342. :title => 'should set the IPv4 listen IP',
  343. :attr => 'listen_ip',
  344. :value => '127.0.0.1',
  345. :match => ' listen 127.0.0.1:443 ssl;',
  346. },
  347. {
  348. :title => 'should set the IPv4 SSL listen port',
  349. :attr => 'ssl_port',
  350. :value => 45,
  351. :match => ' listen *:45 ssl;',
  352. },
  353. {
  354. :title => 'should set SPDY',
  355. :attr => 'spdy',
  356. :value => 'on',
  357. :match => ' listen *:443 ssl spdy;',
  358. },
  359. {
  360. :title => 'should not set SPDY',
  361. :attr => 'spdy',
  362. :value => 'off',
  363. :match => ' listen *:443 ssl;',
  364. },
  365. {
  366. :title => 'should set the IPv4 listen options',
  367. :attr => 'listen_options',
  368. :value => 'default',
  369. :match => ' listen *:443 ssl default;',
  370. },
  371. {
  372. :title => 'should enable IPv6',
  373. :attr => 'ipv6_enable',
  374. :value => true,
  375. :match => ' listen [::]:443 ssl default ipv6only=on;',
  376. },
  377. {
  378. :title => 'should disable IPv6',
  379. :attr => 'ipv6_enable',
  380. :value => false,
  381. :notmatch => / listen \[::\]:443 ssl default ipv6only=on;/,
  382. },
  383. {
  384. :title => 'should set the IPv6 listen IP',
  385. :attr => 'ipv6_listen_ip',
  386. :value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  387. :match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443 ssl default ipv6only=on;',
  388. },
  389. {
  390. :title => 'should set the IPv6 listen port',
  391. :attr => 'ssl_port',
  392. :value => 45,
  393. :match => ' listen [::]:45 ssl default ipv6only=on;',
  394. },
  395. {
  396. :title => 'should set the IPv6 listen options',
  397. :attr => 'ipv6_listen_options',
  398. :value => 'spdy default',
  399. :match => ' listen [::]:443 ssl spdy default;',
  400. },
  401. {
  402. :title => 'should set servername(s)',
  403. :attr => 'server_name',
  404. :value => ['www.foo.com','foo.com'],
  405. :match => ' server_name www.foo.com foo.com;',
  406. },
  407. {
  408. :title => 'should rewrite www servername to non-www',
  409. :attr => 'rewrite_www_to_non_www',
  410. :value => true,
  411. :match => ' server_name rspec.example.com;',
  412. },
  413. {
  414. :title => 'should not rewrite www servername to non-www',
  415. :attr => 'rewrite_www_to_non_www',
  416. :value => false,
  417. :match => ' server_name www.rspec.example.com;',
  418. },
  419. {
  420. :title => 'should set the SSL cache',
  421. :attr => 'ssl_cache',
  422. :value => 'shared:SSL:1m',
  423. :match => ' ssl_session_cache shared:SSL:1m;',
  424. },
  425. {
  426. :title => 'should set the SSL protocols',
  427. :attr => 'ssl_protocols',
  428. :value => 'SSLv3',
  429. :match => ' ssl_protocols SSLv3;',
  430. },
  431. {
  432. :title => 'should set the SSL ciphers',
  433. :attr => 'ssl_ciphers',
  434. :value => 'HIGH',
  435. :match => ' ssl_ciphers HIGH;',
  436. },
  437. {
  438. :title => 'should set auth_basic',
  439. :attr => 'auth_basic',
  440. :value => 'value',
  441. :match => ' auth_basic "value";',
  442. },
  443. {
  444. :title => 'should set auth_basic_user_file',
  445. :attr => 'auth_basic_user_file',
  446. :value => 'value',
  447. :match => ' auth_basic_user_file "value";',
  448. },
  449. {
  450. :title => 'should set the client_body_timeout',
  451. :attr => 'client_body_timeout',
  452. :value => 'value',
  453. :match => /^[ ]+client_body_timeout\s+value;/
  454. },
  455. {
  456. :title => 'should set the client_header_timeout',
  457. :attr => 'client_header_timeout',
  458. :value => 'value',
  459. :match => /^[ ]+client_header_timeout\s+value;/
  460. },
  461. {
  462. :title => 'should set the gzip_types',
  463. :attr => 'gzip_types',
  464. :value => 'value',
  465. :match => /^[ ]+gzip_types\s+value;/
  466. },
  467. {
  468. :title => 'should set access_log',
  469. :attr => 'access_log',
  470. :value => '/path/to/access.log',
  471. :match => ' access_log /path/to/access.log;',
  472. },
  473. {
  474. :title => 'should set error_log',
  475. :attr => 'error_log',
  476. :value => '/path/to/error.log',
  477. :match => ' error_log /path/to/error.log;',
  478. },
  479. {
  480. :title => 'should contain raw_prepend directives',
  481. :attr => 'raw_prepend',
  482. :value => [
  483. 'if (a) {',
  484. ' b;',
  485. '}'
  486. ],
  487. :match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
  488. },
  489. {
  490. :title => 'should contain ordered prepend directives',
  491. :attr => 'vhost_cfg_prepend',
  492. :value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
  493. :match => [
  494. ' allow test value 3;',
  495. ' test1 test value 1;',
  496. ' test2 test value 2a;',
  497. ' test2 test value 2b;',
  498. ]
  499. },
  500. {
  501. :title => 'should contain ordered ssl prepend directives',
  502. :attr => 'vhost_cfg_ssl_prepend',
  503. :value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
  504. :match => [
  505. ' allow test value 3;',
  506. ' test1 test value 1;',
  507. ' test2 test value 2a;',
  508. ' test2 test value 2b;',
  509. ]
  510. },
  511. {
  512. :title => 'should set root',
  513. :attr => 'use_default_location',
  514. :value => false,
  515. :match => ' root /;',
  516. },
  517. {
  518. :title => 'should not set root',
  519. :attr => 'use_default_location',
  520. :value => true,
  521. :notmatch => / root \/;/,
  522. },
  523. ].each do |param|
  524. context "when #{param[:attr]} is #{param[:value]}" do
  525. let :params do default_params.merge({
  526. param[:attr].to_sym => param[:value],
  527. :ssl => true,
  528. :ssl_key => 'dummy.key',
  529. :ssl_cert => 'dummy.crt',
  530. }) end
  531. it { should contain_concat__fragment("#{title}-ssl-header") }
  532. it param[:title] do
  533. matches = Array(param[:match])
  534. if matches.all? { |m| m.is_a? Regexp }
  535. matches.each { |item| should contain_concat__fragment("#{title}-ssl-header").with_content(item) }
  536. else
  537. lines = subject.resource('concat::fragment', "#{title}-ssl-header").send(:parameters)[:content].split("\n")
  538. (lines & Array(param[:match])).should == Array(param[:match])
  539. end
  540. Array(param[:notmatch]).each do |item|
  541. should contain_concat__fragment("#{title}-ssl-header").without_content(item)
  542. end
  543. end
  544. end
  545. end
  546. end
  547. describe "vhost_ssl_footer template content" do
  548. [
  549. {
  550. :title => 'should not contain www to non-www rewrite',
  551. :attr => 'rewrite_www_to_non_www',
  552. :value => false,
  553. :notmatch => %r|
  554. ^
  555. \s+listen\s+\*:443\s+ssl;\n
  556. \s+server_name\s+www\.rspec\.example\.com;\n
  557. \s+return\s+301\s+https://rspec\.example\.com\$uri;
  558. |x,
  559. },
  560. {
  561. :title => 'should contain include directives',
  562. :attr => 'include_files',
  563. :value => [ '/file1', '/file2' ],
  564. :match => [
  565. %r'^[ ]+include\s+/file1;',
  566. %r'^[ ]+include\s+/file2;',
  567. ],
  568. },
  569. {
  570. :title => 'should contain ordered appended directives',
  571. :attr => 'vhost_cfg_append',
  572. :value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
  573. :match => [
  574. ' allow test value 3;',
  575. ' test1 test value 1;',
  576. ' test2 test value 2;',
  577. ]
  578. },
  579. {
  580. :title => 'should contain raw_append directives',
  581. :attr => 'raw_append',
  582. :value => [
  583. 'if (a) {',
  584. ' b;',
  585. '}'
  586. ],
  587. :match => /^\s+if \(a\) {\n\s++b;\n\s+\}/,
  588. },
  589. {
  590. :title => 'should contain ordered ssl appended directives',
  591. :attr => 'vhost_cfg_ssl_append',
  592. :value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
  593. :match => [
  594. ' allow test value 3;',
  595. ' test1 test value 1;',
  596. ' test2 test value 2a;',
  597. ' test2 test value 2b;',
  598. ]
  599. },
  600. ].each do |param|
  601. context "when #{param[:attr]} is #{param[:value]}" do
  602. let :params do default_params.merge({
  603. param[:attr].to_sym => param[:value],
  604. :ssl => true,
  605. :ssl_key => 'dummy.key',
  606. :ssl_cert => 'dummy.crt',
  607. }) end
  608. it { should contain_concat__fragment("#{title}-ssl-footer") }
  609. it param[:title] do
  610. matches = Array(param[:match])
  611. if matches.all? { |m| m.is_a? Regexp }
  612. matches.each { |item| should contain_concat__fragment("#{title}-ssl-footer").with_content(item) }
  613. else
  614. lines = subject.resource('concat::fragment', "#{title}-ssl-footer").send(:parameters)[:content].split("\n")
  615. (lines & Array(param[:match])).should == Array(param[:match])
  616. end
  617. Array(param[:notmatch]).each do |item|
  618. should contain_concat__fragment("#{title}-ssl-footer").without_content(item)
  619. end
  620. end
  621. end
  622. end
  623. end
  624. context 'attribute resources' do
  625. context "with SSL enabled, www rewrite to naked domain with multiple server_names" do
  626. let :title do 'foo.com' end
  627. let(:params) do
  628. {
  629. :ssl => true,
  630. :ssl_cert => 'cert',
  631. :ssl_key => 'key',
  632. :server_name => %w(www.foo.com bar.foo.com foo.com),
  633. :use_default_location => false,
  634. :rewrite_www_to_non_www => true,
  635. }
  636. end
  637. it "should set the server_name of the rewrite server stanza to the first server_name with 'www.' stripped" do
  638. should contain_concat__fragment("#{title}-ssl-header").with_content(/^[ ]+server_name\s+foo.com;/)
  639. end
  640. end
  641. context "with SSL disabled, www rewrite to naked domain with multiple server_names" do
  642. let :title do 'foo.com' end
  643. let(:params) do
  644. {
  645. :server_name => %w(www.foo.com bar.foo.com foo.com),
  646. :use_default_location => false,
  647. :rewrite_www_to_non_www => true,
  648. }
  649. end
  650. it "should set the server_name of the rewrite server stanza to the first server_name with 'www.' stripped" do
  651. should contain_concat__fragment("#{title}-header").with_content(/^[ ]+server_name\s+foo.com;/)
  652. end
  653. end
  654. context "SSL cert missing" do
  655. let(:params) {{ :ssl => true, :ssl_key => 'key' }}
  656. it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error) }
  657. end
  658. context "SSL key missing" do
  659. let(:params) {{ :ssl => true, :ssl_cert => 'cert' }}
  660. it { expect { should contain_class('nginx::resource::vhost') }.to raise_error(Puppet::Error) }
  661. end
  662. context 'when use_default_location => true' do
  663. let :params do default_params.merge({
  664. :use_default_location => true,
  665. }) end
  666. it { should contain_nginx__resource__location("#{title}-default") }
  667. end
  668. context 'when use_default_location => false' do
  669. let :params do default_params.merge({
  670. :use_default_location => false,
  671. }) end
  672. it { should_not contain_nginx__resource__location("#{title}-default") }
  673. end
  674. context 'when location_cfg_prepend => { key => value }' do
  675. let :params do default_params.merge({
  676. :location_cfg_prepend => { 'key' => 'value' },
  677. }) end
  678. it { should contain_nginx__resource__location("#{title}-default").with_location_cfg_prepend({ 'key' => 'value' }) }
  679. end
  680. context "when location_raw_prepend => [ 'foo;' ]" do
  681. let :params do default_params.merge({
  682. :location_raw_prepend => [ 'foo;' ],
  683. }) end
  684. it { should contain_nginx__resource__location("#{title}-default").with_raw_prepend([ 'foo;' ]) }
  685. end
  686. context "when location_raw_append => [ 'foo;' ]" do
  687. let :params do default_params.merge({
  688. :location_raw_append => [ 'foo;' ],
  689. }) end
  690. it { should contain_nginx__resource__location("#{title}-default").with_raw_append([ 'foo;' ]) }
  691. end
  692. context 'when location_cfg_append => { key => value }' do
  693. let :params do default_params.merge({
  694. :location_cfg_append => { 'key' => 'value' },
  695. }) end
  696. it { should contain_nginx__resource__location("#{title}-default").with_location_cfg_append({ 'key' => 'value' }) }
  697. end
  698. context 'when fastcgi => "localhost:9000"' do
  699. let :params do default_params.merge({
  700. :fastcgi => 'localhost:9000',
  701. }) end
  702. it { should contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
  703. end
  704. context 'when listen_port == ssl_port' do
  705. let :params do default_params.merge({
  706. :listen_port => 80,
  707. :ssl_port => 80,
  708. }) end
  709. it { should_not contain_concat__fragment("#{title}-header") }
  710. it { should_not contain_concat__fragment("#{title}-footer") }
  711. end
  712. context 'when listen_port != ssl_port' do
  713. let :params do default_params.merge({
  714. :listen_port => 80,
  715. :ssl_port => 443,
  716. }) end
  717. it { should contain_concat__fragment("#{title}-header") }
  718. it { should contain_concat__fragment("#{title}-footer") }
  719. end
  720. context 'when ensure => absent' do
  721. let :params do default_params.merge({
  722. :ensure => 'absent',
  723. :ssl => true,
  724. :ssl_key => 'dummy.key',
  725. :ssl_cert => 'dummy.cert',
  726. }) end
  727. it { should contain_nginx__resource__location("#{title}-default").with_ensure('absent') }
  728. it { should contain_file("#{title}.conf symlink").with_ensure('absent') }
  729. end
  730. context 'when ssl => true and ssl_port == listen_port' do
  731. let :params do default_params.merge({
  732. :ssl => true,
  733. :listen_port => 80,
  734. :ssl_port => 80,
  735. :ssl_key => 'dummy.key',
  736. :ssl_cert => 'dummy.cert',
  737. }) end
  738. it { should contain_nginx__resource__location("#{title}-default").with_ssl_only(true) }
  739. it { should contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log}) }
  740. it { should contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log[ ]+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) }
  741. it { should contain_concat__fragment("#{title}-ssl-footer") }
  742. it { should contain_file("/etc/nginx/#{title}.crt") }
  743. it { should contain_file("/etc/nginx/#{title}.key") }
  744. end
  745. context 'when passenger_cgi_param is set' do
  746. let :params do default_params.merge({
  747. :passenger_cgi_param => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' }
  748. }) end
  749. it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
  750. it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
  751. it { should contain_concat__fragment("#{title}-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
  752. end
  753. context 'when passenger_cgi_param is set and ssl => true' do
  754. let :params do default_params.merge({
  755. :passenger_cgi_param => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' },
  756. :ssl => true,
  757. :ssl_key => 'dummy.key',
  758. :ssl_cert => 'dummy.cert',
  759. }) end
  760. it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test1 test value 1;/ ) }
  761. it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test2 test value 2;/ ) }
  762. it { should contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
  763. end
  764. context 'when vhost name is sanitized' do
  765. let :title do 'www rspec-vhost com' end
  766. let :params do default_params end
  767. it { should contain_concat('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
  768. end
  769. end
  770. end
  771. end