|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'nftables::rules::out::choria' do |
| 6 | + on_supported_os.each do |os, os_facts| |
| 7 | + context "on #{os}" do |
| 8 | + let(:facts) { os_facts } |
| 9 | + let(:params) do |
| 10 | + { brokers: ['1.2.3.4'] } |
| 11 | + end |
| 12 | + |
| 13 | + context 'default options' do |
| 14 | + it { is_expected.to compile } |
| 15 | + it { is_expected.to contain_nftables__rule('default_out-choria-0').with_content('ip daddr 1.2.3.4 tcp dport 4222 accept') } |
| 16 | + it { is_expected.to contain_nftables__rule('default_out-choriawebsocket-0').with_content('ip daddr 1.2.3.4 tcp dport 4333 accept') } |
| 17 | + it { is_expected.to have_nftables__rule_resource_count(2) } |
| 18 | + end |
| 19 | + |
| 20 | + context 'with different port' do |
| 21 | + let(:params) do |
| 22 | + super().merge({ choria_port: 8141 }) |
| 23 | + end |
| 24 | + |
| 25 | + it { is_expected.to compile } |
| 26 | + it { is_expected.to contain_nftables__rule('default_out-choria-0').with_content('ip daddr 1.2.3.4 tcp dport 8141 accept') } |
| 27 | + it { is_expected.to contain_nftables__rule('default_out-choriawebsocket-0').with_content('ip daddr 1.2.3.4 tcp dport 4333 accept') } |
| 28 | + it { is_expected.to have_nftables__rule_resource_count(2) } |
| 29 | + end |
| 30 | + |
| 31 | + context 'with ipv6 address' do |
| 32 | + let(:params) do |
| 33 | + { brokers: ['fe80::1'] } |
| 34 | + end |
| 35 | + |
| 36 | + it { is_expected.to compile } |
| 37 | + it { is_expected.to contain_nftables__rule('default_out-choria-0').with_content('ip6 daddr fe80::1 tcp dport 4222 accept') } |
| 38 | + it { is_expected.to contain_nftables__rule('default_out-choriawebsocket-0').with_content('ip6 daddr fe80::1 tcp dport 4333 accept') } |
| 39 | + it { is_expected.to have_nftables__rule_resource_count(2) } |
| 40 | + end |
| 41 | + |
| 42 | + context 'with ipv6 & ipv4 address' do |
| 43 | + let(:params) do |
| 44 | + { brokers: ['fe80::1', '1.2.3.4'] } |
| 45 | + end |
| 46 | + |
| 47 | + it { is_expected.to compile } |
| 48 | + it { is_expected.to contain_nftables__rule('default_out-choria-0').with_content('ip6 daddr fe80::1 tcp dport 4222 accept') } |
| 49 | + it { is_expected.to contain_nftables__rule('default_out-choria-1').with_content('ip daddr 1.2.3.4 tcp dport 4222 accept') } |
| 50 | + it { is_expected.to contain_nftables__rule('default_out-choriawebsocket-0').with_content('ip6 daddr fe80::1 tcp dport 4333 accept') } |
| 51 | + it { is_expected.to contain_nftables__rule('default_out-choriawebsocket-1').with_content('ip daddr 1.2.3.4 tcp dport 4333 accept') } |
| 52 | + it { is_expected.to have_nftables__rule_resource_count(4) } |
| 53 | + end |
| 54 | + |
| 55 | + context 'with ipv6 & ipv4 address & without websockets' do |
| 56 | + let(:params) do |
| 57 | + { brokers: ['fe80::1', '1.2.3.4'], enable_websockets: false } |
| 58 | + end |
| 59 | + |
| 60 | + it { is_expected.to compile } |
| 61 | + it { is_expected.to contain_nftables__rule('default_out-choria-0').with_content('ip6 daddr fe80::1 tcp dport 4222 accept') } |
| 62 | + it { is_expected.to contain_nftables__rule('default_out-choria-1').with_content('ip daddr 1.2.3.4 tcp dport 4222 accept') } |
| 63 | + it { is_expected.to have_nftables__rule_resource_count(2) } |
| 64 | + end |
| 65 | + |
| 66 | + context 'without IPs' do |
| 67 | + let :params do |
| 68 | + {} |
| 69 | + end |
| 70 | + |
| 71 | + it { is_expected.to compile } |
| 72 | + it { is_expected.to contain_nftables__rule('default_out-choria-0').with_content('tcp dport 4222 accept') } |
| 73 | + it { is_expected.not_to contain_nftables__rule('default_out-choriawebsocket-0').with_content('tcp dport 4333 accept') } |
| 74 | + it { is_expected.to have_nftables__rule_resource_count(2) } |
| 75 | + end |
| 76 | + |
| 77 | + context 'without IPs & websockets' do |
| 78 | + let :params do |
| 79 | + { enable_websockets: false } |
| 80 | + end |
| 81 | + |
| 82 | + it { is_expected.to compile } |
| 83 | + it { is_expected.to contain_nftables__rule('default_out-choria-0').with_content('tcp dport 4222 accept') } |
| 84 | + it { is_expected.to have_nftables__rule_resource_count(1) } |
| 85 | + end |
| 86 | + end |
| 87 | + end |
| 88 | +end |
0 commit comments