<commit_before>require 'spec_helper_acceptance'

describe 'stns::client class' do
  let(:manifest) do
    <<-EOS
      package { 'openssh-server':
        ensure => installed,
      }

      $ssh_service = $facts['osfamily'] ? {
        'RedHat' => 'sshd',
        'Debian' => 'ssh',
      }

      service { $ssh_service:
        ensure => running,
      }

      class { '::stns::client':
        api_end_point      => 'http://stns.example.jp:1104',
        auth_token         => '<PASSWORD>',
        user               => 'sample',
        password           => '<PASSWORD>',
        wrapper_path       => '/usr/local/bin/stns-query-wrapper',
        chain_ssh_wrapper  => '/usr/libexec/openssh/ssh-ldap-wrapper',
        ssl_verify         => true,
        request_timeout    => 3,
        request_retry      => 1,
        http_proxy         => 'http://proxy.example.com:1104',
        uid_shift          => 0,
        gid_shift          => 0,
        libnss_stns_ensure => latest,
        handle_nsswitch    => true,
        handle_sshd_config => true,
      }
    EOS
  end

  it 'works without errors' do
    result = apply_manifest(manifest, catch_failures: true)
    expect(result.exit_code).to eq 2
  end

  it 'runs a second time without changes' do
    result = apply_manifest(manifest)
    expect(result.exit_code).to eq 0
  end

  describe package('libnss-stns-v2') do
    it { is_expected.to be_installed }
  end

  describe file('/etc/stns/client/stns.conf') do
    its(:content) { is_expected.to match %r{^api_endpoint = "http://stns.example.jp:1104"$} }
    its(:content) { is_expected.to match %r{^auth_token = "<PASSWORD>"$} }
    its(:content) { is_expected.to match %r{^user = "sample"$} }
    its(:content) { is_expected.to match %r{^password = "<PASSWORD>"$} }
    its(:content) { is_expected.to match %r{^chain_ssh_wrapper = "/usr/libexec/openssh/ssh-ldap-wrapper"$} }
    its(:content) { is_expected.to match %r{^query_wrapper = "/usr/local/bin/stns-query-wrapper"$} }
    its(:content) { is_expected.to match %r{^ssl_verify = true$} }
    its(:content) { is_expected.to match %r{^http_proxy = "http://proxy.example.com:1104"$} }
    its(:content) { is_expected.to match %r{^uid_shift = 0$} }
    its(:content) { is_expected.to match %r{^gid_shift = 0$} }
    its(:content) { is_expected.to match %r{^request_timeout = 3$} }
    its(:content) { is_expected.to match %r{^request_retry = 1$} }
  end

  describe file('/etc/nsswitch.conf') do<commit_msg>Fix password spec<commit_after>require 'spec_helper_acceptance'

describe 'stns::client class' do
  let(:manifest) do
    <<-EOS
      package { 'openssh-server':
        ensure => installed,
      }

      $ssh_service = $facts['osfamily'] ? {
        'RedHat' => 'sshd',
        'Debian' => 'ssh',
      }

      service { $ssh_service:
        ensure => running,
      }

      class { '::stns::client':
        api_end_point      => 'http://stns.example.jp:1104',
        auth_token         => '<PASSWORD>',
        user               => 'sample',
        password           => '<PASSWORD>',
        wrapper_path       => '/usr/local/bin/stns-query-wrapper',
        chain_ssh_wrapper  => '/usr/libexec/openssh/ssh-ldap-wrapper',
        ssl_verify         => true,
        request_timeout    => 3,
        request_retry      => 1,
        http_proxy         => 'http://proxy.example.com:1104',
        uid_shift          => 0,
        gid_shift          => 0,
        libnss_stns_ensure => latest,
        handle_nsswitch    => true,
        handle_sshd_config => true,
      }
    EOS
  end

  it 'works without errors' do
    result = apply_manifest(manifest, catch_failures: true)
    expect(result.exit_code).to eq 2
  end

  it 'runs a second time without changes' do
    result = apply_manifest(manifest)
    expect(result.exit_code).to eq 0
  end

  describe package('libnss-stns-v2') do
    it { is_expected.to be_installed }
  end

  describe file('/etc/stns/client/stns.conf') do
    its(:content) { is_expected.to match %r{^api_endpoint = "http://stns.example.jp:1104"$} }
    its(:content) { is_expected.to match %r{^auth_token = "<PASSWORD>"$} }
    its(:content) { is_expected.to match %r{^user = "sample"$} }
    its(:content) { is_expected.to match %r{^password = "<PASSWORD>"$} }
    its(:content) { is_expected.to match %r{^chain_ssh_wrapper = "/usr/libexec/openssh/ssh-ldap-wrapper"$} }
    its(:content) { is_expected.to match %r{^query_wrapper = "/usr/local/bin/stns-query-wrapper"$} }
    its(:content) { is_expected.to match %r{^ssl_verify = true$} }
    its(:content) { is_expected.to match %r{^http_proxy = "http://proxy.example.com:1104"$} }
    its(:content) { is_expected.to match %r{^uid_shift = 0$} }
    its(:content) { is_expected.to match %r{^gid_shift = 0$} }
    its(:content) { is_expected.to match %r{^request_timeout = 3$} }
    its(:content) { is_expected.to match %r{^request_retry = 1$} }
  end

  describe file('/etc/nsswitch.conf') do
{'fraction_non_alphanumeric': 0.15403225806451612, 'fraction_numerical': 0.010887096774193548, 'mean_word_length': 2.5819494584837543, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1185259', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1668, 'n_words': 317}