<commit_before>require 'spec_helper'

describe 'ufw::allow', :type => :define do
  let(:title) { 'foo' }
  context 'basic operation' do
    it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.168.42.42-port-all').
      with_command("ufw allow  proto tcp from any to 192.168.42.42").
      with_unless("ufw status | grep -qE '^192.168.42.42/tcp +ALLOW +Anywhere( +.*)?$'")
    }
  end

  context 'specifying from address' do
    let(:params) { {:from => '192.0.2.42'} }
    it { should contain_exec('ufw-allow-IN-tcp-from-192.0.2.42-to-192.168.42.42-port-all').
      with_command("ufw allow  proto tcp from 192.0.2.42 to 192.168.42.42").
      with_unless("ufw status | grep -qE '^192.168.42.42/tcp +ALLOW +192.0.2.42/tcp( +.*)?$'")
    }
  end

  describe 'specifying to address' do
    context 'from ipaddress_eth0 fact' do
      let(:facts) { {:ipaddress_eth0 => '192.0.2.67'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.0.2.67-port-all').
        with_command("ufw allow  proto tcp from any to 192.0.2.67").
        with_unless("ufw status | grep -qE '^192.0.2.67/tcp +ALLOW +Anywhere( +.*)?$'")
      }
    end

    context 'from $ip parameter' do
      let(:params) { {:ip => '192.0.2.68'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.0.2.68-port-all').
        with_command("ufw allow  proto tcp from any to 192.0.2.68").
        with_unless("ufw status | grep -qE '^192.0.2.68/tcp +ALLOW +Anywhere( +.*)?$'")
      }
    end

    context 'from $ip parameter (ipv6)' do
      let(:params) { {:ip => 'fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-2a00:fdf8:f53e:61e4::18-port-all').
        with_command("ufw allow  proto tcp from any to fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b").
        with_unless("ufw status | grep -qE '^fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b/tcp +ALLOW +Anywhere \\(v6\\)( +.*)?$'")
      }
    end

    context 'when both $ip and ipaddress_eth0 are specified' do
      let(:facts) { {:ipaddress_eth0 => '192.0.2.67'} }
      let(:params) { {:ip => '192.0.2.68'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.0.2.68-port-all').
        with_command("ufw allow  proto tcp from any to 192.0.2.68").
        with_unless("ufw status | grep -qE '^192.0.2.68/tcp +ALLOW +Anywhere( +.*)?$'")
      }
    end

    context 'when from is a specific ip address' do
      let(:facts) { {:ipaddress_eth0 => '192.0.2.68'} }
      let(:params) { {:from => '192.0.2.69'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-192.0.2.69-to-192.0.2.68-port-all').
        with_command("ufw allow  proto tcp from 192.0.2.69 to 192.0.2.68").
        with_unless("ufw status | grep -qE '^192.0.2.68/tcp +ALLOW +192.0.2.69/tcp( +.*)?$'")
      }
    end
  end

  context 'specifying port' do
    let(:params) { {:port => '8080'} }
    it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.168.42.42-port-8080').
      with_command("ufw allow  proto tcp from any to 192.168.42.42 port 8080").
      with_unless("ufw status | grep -qE '^192.168.42.42 8080/tcp +ALLOW +Anywhere( +.*)?$'")
    }
  end

  context 'with ensure => absent' do
    let(:params) { {:ensure => 'absent'} }
    it { should contain_exec('ufw-delete-tcp-from-any-to-192.168.42.42-port-all').
      with_command("ufw delete allow  proto tcp from any to 192.168.42.42").
      with_onlyif("ufw status | grep -qE '^192.168.42.42/tcp +ALLOW +Anywhere$'")<commit_msg>spec add spect tests (failing)<commit_after>require 'spec_helper'

describe 'ufw::allow', :type => :define do
  let(:title) { 'foo' }
  context 'basic operation' do
    it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.168.42.42-port-all').
      with_command("ufw allow  proto tcp from any to 192.168.42.42").
      with_unless("ufw status | grep -qE '^192.168.42.42/tcp +ALLOW +Anywhere( +.*)?$'")
    }
  end

  context 'specifying from address' do
    let(:params) { {:from => '192.0.2.42'} }
    it { should contain_exec('ufw-allow-IN-tcp-from-192.0.2.42-to-192.168.42.42-port-all').
      with_command("ufw allow  proto tcp from 192.0.2.42 to 192.168.42.42").
      with_unless("ufw status | grep -qE '^192.168.42.42/tcp +ALLOW +192.0.2.42/tcp( +.*)?$'")
    }
  end

  describe 'specifying to address' do
    context 'from ipaddress_eth0 fact' do
      let(:facts) { {:ipaddress_eth0 => '192.0.2.67'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.0.2.67-port-all').
        with_command("ufw allow  proto tcp from any to 192.0.2.67").
        with_unless("ufw status | grep -qE '^192.0.2.67/tcp +ALLOW +Anywhere( +.*)?$'")
      }
    end

    context 'from $ip parameter' do
      let(:params) { {:ip => '192.0.2.68'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.0.2.68-port-all').
        with_command("ufw allow  proto tcp from any to 192.0.2.68").
        with_unless("ufw status | grep -qE '^192.0.2.68/tcp +ALLOW +Anywhere( +.*)?$'")
      }
    end

    context 'from $ip parameter (any protocol)' do
      let(:params) { {:ip => '192.0.2.68'} }
      it { should contain_exec('ufw-allow-IN-any-from-any-to-192.0.2.68-port-all').
                   with_command("ufw allow  proto any from any to 192.0.2.68").
                   with_unless("ufw status | grep -qE '^192.0.2.68 +ALLOW +Anywhere( +.*)?$'")
      }
    end

    context 'from $ip parameter (ipv6)' do
      let(:params) { {:ip => 'fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-2a00:fdf8:f53e:61e4::18-port-all').
        with_command("ufw allow  proto tcp from any to fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b").
        with_unless("ufw status | grep -qE '^2a00:fdf8:f53e:61e4::18/tcp +ALLOW +Anywhere \\(v6\\)( +.*)?$'")
      }
    end

    context 'from $ip parameter (ipv6, any protocol)' do
      let(:params) { {:ip => 'fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b'} }
      it { should contain_exec('ufw-allow-IN-any-from-any-to-2a00:fdf8:f53e:61e4::18-port-all').
                   with_command("ufw allow  proto any from any to fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b").
                   with_unless("ufw status | grep -qE '^fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b +ALLOW +Anywhere \\(v6\\)( +.*)?$'")
      }
    end

    context 'when both $ip and ipaddress_eth0 are specified' do
      let(:facts) { {:ipaddress_eth0 => '192.0.2.67'} }
      let(:params) { {:ip => '192.0.2.68'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.0.2.68-port-all').
        with_command("ufw allow  proto tcp from any to 192.0.2.68").
        with_unless("ufw status | grep -qE '^192.0.2.68/tcp +ALLOW +Anywhere( +.*)?$'")
      }
    end

    context 'when from is a specific ip address' do
      let(:facts) { {:ipaddress_eth0 => '192.0.2.68'} }
      let(:params) { {:from => '192.0.2.69'} }
      it { should contain_exec('ufw-allow-IN-tcp-from-192.0.2.69-to-192.0.2.68-port-all').
        with_command("ufw allow  proto tcp from 192.0.2.69 to 192.0.2.68").
        with_unless("ufw status | grep -qE '^192.0.2.68/tcp +ALLOW +192.0.2.69/tcp( +.*)?$'")
      }
    end
  end

  context 'specifying port' do
    let(:params) { {:port => '8080'} }
    it { should contain_exec('ufw-allow-IN-tcp-from-any-to-192.168.42.42-port-8080').
      with_command("ufw allow  proto tcp from any to 192.168.42.42 port 8080").
      with_unless("ufw status | grep -qE '^192.168.42.42 8080/tcp +ALLOW +Anywhere( +.*)?$'")
    }
  end

  context 'specifying port for any protocol' do
    let(:params) { {:port => '8080'} }
    it { should contain_exec('ufw-allow-IN-any-from-any-to-192.168.42.42-port-8080').
                 with_command("ufw allow  proto any from any to 192.168.42.42 port 8080").
                 with_unless("ufw status | grep -qE '^192.168.42.42 8080 +ALLOW +Anywhere( +.*)?$'")
    }
  end

  context 'with ensure => absent' do
    let(:params) { {:ensure => 'absent'} }
    it { should contain_exec('ufw-delete-tcp-from-any-to-192.168.42.42-port-all').
      with_command("ufw delete allow  proto tcp from any to 192.168.42.42").
      with_onlyif("ufw status | grep -qE '^192.168.42.42/tcp +ALLOW +Anywhere$'")
{'fraction_non_alphanumeric': 0.18894852403025128, 'fraction_numerical': 0.11075872163942425, 'mean_word_length': 2.68991899189919, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 81, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3071322', 'n_tokens_mistral': 3853, 'n_tokens_neox': 3306, 'n_words': 639}