<commit_before># frozen_string_literal: true

require 'spec_helper'
require 'helpers/fs'

require 'conjur/puppet_module/identity'

describe Conjur::PuppetModule::Identity do
  describe '.from_file' do
    it 'reads credentials from netrc' do
      Tempfile.open do |netrc|
        netrc.write <<~NETRC
          machine example.com
          login not-this-one
          password <PASSWORD>

          machine conjur.test
          login conjur-login
          password <PASSWORD>
        NETRC
        netrc.close

        expect(Conjur::PuppetModule::Identity.from_file(
          URI('https://conjur.test/authn/foo'), 'netrc_path' => netrc.path
        )).to eq %w(conjur-login secret)
      end
    end
  end
  include FsMock
end<commit_msg>Add unit test for #from_wincred<commit_after># frozen_string_literal: true

require 'spec_helper'
require 'helpers/fs'
require 'helpers/native_wincred'

require 'conjur/puppet_module/identity'

describe Conjur::PuppetModule::Identity do
  describe '.from_file' do
    it 'reads credentials from netrc' do
      Tempfile.open do |netrc|
        netrc.write <<~NETRC
          machine example.com
          login not-this-one
          password <PASSWORD>

          machine conjur.test
          login conjur-login
          password <PASSWORD>
        NETRC
        netrc.close

        expect(Conjur::PuppetModule::Identity.from_file(
            URI('https://conjur.test/authn/foo'), 'netrc_path' => netrc.path
        )).to eq %w(conjur-login secret)
      end
    end
  end

  describe '.from_wincred', wincred: :mock do
    before { Puppet.features.stub(:microsoft_windows?) { true } }

    let(:wincred_credentials) do
      {
          # password needs an encoding
          'conjur.test' => ["conjur-login", "secret".encode('utf-16le').force_encoding('binary')]
      }
    end

    it 'reads credentials from wincred' do
      expect(Conjur::PuppetModule::Identity.from_wincred(
          URI('https://conjur.test/authn/foo')
      )).to eq %w(conjur-login secret)
    end
  end

  include FsMock
end
{'fraction_non_alphanumeric': 0.10516066212268745, 'fraction_numerical': 0.0009737098344693282, 'mean_word_length': 2.543103448275862, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 3, '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': '5317722', 'n_tokens_mistral': 679, 'n_tokens_neox': 645, 'n_words': 145}