Skip to content

Conversation

@ekohl
Copy link
Member

@ekohl ekohl commented Jan 16, 2024

This was raised in the chat and it took a while to understand what the reporter was trying to say. Adding an acceptance test was the clearest way to see what was going on. This should add 3 keys, but in practice it isn't idempotent because it rewrites each entry. It appears the part after @ is discarded and no comment is written.

@yakatz
Copy link
Member

yakatz commented Jan 16, 2024

If I understand this correctly where name, I would suggest an additional test - there should also be a test for including the name parameter. Right now this code changes any existing line, not the correct type line.

    it_behaves_like 'an idempotent resource with names' do
      let(:manifest) do
        <<~PUPPET
          sshkey { 'gitlab.com@ecdsa-sha2-nistp256':
            ensure => present,
            name   => 'gitlab.com',
            type   => 'ecdsa-sha2-nistp256',
            key    => 'AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=',
          }
          sshkey { 'gitlab.com@ssh-rsa':
            ensure => present,
            name   => 'gitlab.com',
            type   => 'ssh-rsa',
            key    => 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgMtXL583qmBpzeQ+jqCMRgBqB98u3z++J1sKlXHWfM9dyhSevkMwSbhoR8XIq/U0tCNyokEi/ueaBMCvbcTHhO7FcwzY92WK4Yt0aGROY5qX2UKSeOvuP4D6TPqKF1onrSzH9bx9XUf2lEdWT/ia1NEKjunUqu1xOB/StKDHMoX4/OKyIzuS0q/T1zOATthvasJFoPrAjkohTyaDUz2LN5JoH839hViyEG82yB+MjcFV5MU3N1l1QL3cVUCh93xSaua1N85qivl+siMkPGbO5xR/En4iEY6K2XPASUEMaieWVNTRCtJ4S8H+9',
          }
          sshkey { 'gitlab.com@ssh-ed25519':
            ensure => present,
            name   => 'gitlab.com',
            type   => 'ssh-ed25519',
            key    => 'AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf',
          }
        PUPPET
      end

      it 'has created the SSH keys' do
        expected = [
          'gitlab.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=',
          'gitlab.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgMtXL583qmBpzeQ+jqCMRgBqB98u3z++J1sKlXHWfM9dyhSevkMwSbhoR8XIq/U0tCNyokEi/ueaBMCvbcTHhO7FcwzY92WK4Yt0aGROY5qX2UKSeOvuP4D6TPqKF1onrSzH9bx9XUf2lEdWT/ia1NEKjunUqu1xOB/StKDHMoX4/OKyIzuS0q/T1zOATthvasJFoPrAjkohTyaDUz2LN5JoH839hViyEG82yB+MjcFV5MU3N1l1QL3cVUCh93xSaua1N85qivl+siMkPGbO5xR/En4iEY6K2XPASUEMaieWVNTRCtJ4S8H+9',
          'gitlab.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf',
        ]
        expect(file('/etc/ssh/ssh_known_hosts')).to be_file.and(contain(expected))
      end
    end

@yakatz
Copy link
Member

yakatz commented Jan 16, 2024

Does this fix #75?

@ekohl
Copy link
Member Author

ekohl commented Jan 16, 2024

I don't think it does just yet. It does add an acceptance test, but not one that verifies the correct provider is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants