<commit_before>require 'spec_helper_acceptance'

describe 'iis_site', :suite_b do
  before(:all) do
    # Remove 'Default Web Site' to start from a clean slate
    remove_all_sites
  end

  context 'when configuring a website' do
    context 'with basic required parameters' do
      before (:all) do
        create_path('C:\inetpub\basic')
      end

      site_name = SecureRandom.hex(10).to_s
      manifest = <<-HERE
        iis_site { '#{site_name}':
          ensure          => 'started',
          physicalpath    => 'C:\\inetpub\\basic',
          applicationpool => 'DefaultAppPool',
        }
      HERE

      iis_idempotent_apply('create iis site', manifest)

      it 'has all properties correctly configured' do
        resource_data = resource('iis_site', site_name)
        [
          'ensure', 'started',
          'physicalpath', 'C:\inetpub\basic',
          'applicationpool', 'DefaultAppPool'
        ].each_slice(2) do |key, value|
          puppet_resource_should_show(key, value, resource_data)
        end
      end

      after(:all) do
        remove_all_sites
      end
    end

    context 'with all parameters specified' do
      context 'using W3C log format, logflags and logtruncatesize' do
        site_name = SecureRandom.hex(10).to_s
        before (:all) do
          create_path('C:\inetpub\new')
        end

        let(:certificate_hash) { create_selfsigned_cert('www.puppet.local').downcase }

        let(:manifest) do
          <<-HERE
            iis_site { '#{site_name}':
              ensure               => 'started',
              applicationpool      => 'DefaultAppPool',
              enabledprotocols     => 'https',
              bindings             => [
                {
                  'bindinginformation'   => '*:8080:',
                  'protocol'             => 'http',
                },
                {
                  'bindinginformation'   => '*:8084:domain.test',
                  'protocol'             => 'http',
                },
                {
                  'bindinginformation'   => '*:8088:www.puppet.local',
                  'protocol'             => 'http',
                },
                {
                  'bindinginformation'   => '*:443:www.puppet.local',
                  'certificatehash'      => '#{certificate_hash}',
                  'certificatestorename' => 'My',
                  'protocol'             => 'https',
                  'sslflags'             => 1,
                },
              ],
              limits               => {
                connectiontimeout => 120,
                maxbandwidth      => 4294967200,
                maxconnections    => 4294967200,
              },
              logflags             => ['ClientIP', 'Date', 'Time', 'UserName'],
              logformat            => 'W3C',
              loglocaltimerollover => false,
              logpath              => 'C:\\inetpub\\logs\\NewLogFiles',
              logtruncatesize      => 2000000,
              physicalpath         => 'C:\\inetpub\\new',
            }
          HERE
        end

        it 'creates a site with SSL bindings' do
          apply_manifest(manifest, catch_failures: true)
        end

        it ' runs the manifest a second time without changes' do
          # SSL Flags not existing on IIS7 causes an idempotency bug in the provider
          pending('ssl flags do not exist on IIS 7 - MODULES-9894') if target_host_facts['os']['release']['major'].match(/2008/)
          apply_manifest(manifest, catch_changes: true)
        end

        it 'has all properties correctly configured' do
          resource_data = resource('iis_site', site_name)
          expect(resource_data.stdout).to match(%r{'bindinginformation' => '\*:443:www.puppet.local'})
          [
            'ensure', 'started',
            'enabledprotocols', 'https',
            'applicationpool', 'DefaultAppPool',
            'logflags', ['ClientIP', 'Date', 'Time', 'UserName'],
            'logformat', 'W3C',
            'loglocaltimerollover', 'false',
            'logpath', 'C:\\inetpub\\logs\\NewLogFiles',
            'logtruncatesize', '2000000',
            'physicalpath', 'C:\\inetpub\\new'
          ].each_slice(2) do |key, value|
            puppet_resource_should_show(key, value, resource_data)
          end
        end

        it 'when capitalization is changed in path parameters' do
          manifest = <<-HERE
            iis_site { '#{site_name}':
              ensure               => 'started',
              # Change capitalization to see if it break idempotency
              logpath              => 'C:\\ineTpub\\logs\\NewLogFiles',
              physicalpath         => 'C:\\ineTpub\\new'
            }
          HERE
          apply_manifest(manifest, catch_changes: true)<commit_msg>Comment out iis_site_spec check for 2008 Windows version<commit_after>require 'spec_helper_acceptance'

describe 'iis_site', :suite_b do
  before(:all) do
    # Remove 'Default Web Site' to start from a clean slate
    remove_all_sites
  end

  context 'when configuring a website' do
    context 'with basic required parameters' do
      before (:all) do
        create_path('C:\inetpub\basic')
      end

      site_name = SecureRandom.hex(10).to_s
      manifest = <<-HERE
        iis_site { '#{site_name}':
          ensure          => 'started',
          physicalpath    => 'C:\\inetpub\\basic',
          applicationpool => 'DefaultAppPool',
        }
      HERE

      iis_idempotent_apply('create iis site', manifest)

      it 'has all properties correctly configured' do
        resource_data = resource('iis_site', site_name)
        [
          'ensure', 'started',
          'physicalpath', 'C:\inetpub\basic',
          'applicationpool', 'DefaultAppPool'
        ].each_slice(2) do |key, value|
          puppet_resource_should_show(key, value, resource_data)
        end
      end

      after(:all) do
        remove_all_sites
      end
    end

    context 'with all parameters specified' do
      context 'using W3C log format, logflags and logtruncatesize' do
        site_name = SecureRandom.hex(10).to_s
        before (:all) do
          create_path('C:\inetpub\new')
        end

        let(:certificate_hash) { create_selfsigned_cert('www.puppet.local').downcase }

        let(:manifest) do
          <<-HERE
            iis_site { '#{site_name}':
              ensure               => 'started',
              applicationpool      => 'DefaultAppPool',
              enabledprotocols     => 'https',
              bindings             => [
                {
                  'bindinginformation'   => '*:8080:',
                  'protocol'             => 'http',
                },
                {
                  'bindinginformation'   => '*:8084:domain.test',
                  'protocol'             => 'http',
                },
                {
                  'bindinginformation'   => '*:8088:www.puppet.local',
                  'protocol'             => 'http',
                },
                {
                  'bindinginformation'   => '*:443:www.puppet.local',
                  'certificatehash'      => '#{certificate_hash}',
                  'certificatestorename' => 'My',
                  'protocol'             => 'https',
                  'sslflags'             => 1,
                },
              ],
              limits               => {
                connectiontimeout => 120,
                maxbandwidth      => 4294967200,
                maxconnections    => 4294967200,
              },
              logflags             => ['ClientIP', 'Date', 'Time', 'UserName'],
              logformat            => 'W3C',
              loglocaltimerollover => false,
              logpath              => 'C:\\inetpub\\logs\\NewLogFiles',
              logtruncatesize      => 2000000,
              physicalpath         => 'C:\\inetpub\\new',
            }
          HERE
        end

        it 'creates a site with SSL bindings' do
          apply_manifest(manifest, catch_failures: true)
        end

        it ' runs the manifest a second time without changes' do
          # SSL Flags not existing on IIS7 causes an idempotency bug in the provider
          # Remove comment if running acceptance tests on 2008 versions
          # pending('ssl flags do not exist on IIS 7 - MODULES-9894') if target_host_facts['os']['release']['major'].match(/2008/)
          apply_manifest(manifest, catch_changes: true)
        end

        it 'has all properties correctly configured' do
          resource_data = resource('iis_site', site_name)
          expect(resource_data.stdout).to match(%r{'bindinginformation' => '\*:443:www.puppet.local'})
          [
            'ensure', 'started',
            'enabledprotocols', 'https',
            'applicationpool', 'DefaultAppPool',
            'logflags', ['ClientIP', 'Date', 'Time', 'UserName'],
            'logformat', 'W3C',
            'loglocaltimerollover', 'false',
            'logpath', 'C:\\inetpub\\logs\\NewLogFiles',
            'logtruncatesize', '2000000',
            'physicalpath', 'C:\\inetpub\\new'
          ].each_slice(2) do |key, value|
            puppet_resource_should_show(key, value, resource_data)
          end
        end

        it 'when capitalization is changed in path parameters' do
          manifest = <<-HERE
            iis_site { '#{site_name}':
              ensure               => 'started',
              # Change capitalization to see if it break idempotency
              logpath              => 'C:\\ineTpub\\logs\\NewLogFiles',
              physicalpath         => 'C:\\ineTpub\\new'
            }
          HERE
          apply_manifest(manifest, catch_changes: true)
{'fraction_non_alphanumeric': 0.1125345905503741, 'fraction_numerical': 0.016193502101055652, 'mean_word_length': 1.5220987335228742, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, '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': '1861329', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2548, 'n_words': 595}