Sha256: d8cfe03ae3b52141930747ac675e35b814cccfd627935c1b22d87e9174b9ccf5

Contents?: true

Size: 849 Bytes

Versions: 14

Compression:

Stored size: 849 Bytes

Contents

# frozen_string_literal: true

require "test_helper"

class RsaTest < Minitest::Test
  let(:model) do
    Class.new do
      def self.name
        "User"
      end

      include ActiveModel::Model
      validates_ssh_private_key :key, type: "rsa"
      attr_accessor :key
    end
  end

  test "accepts rsa key" do
    record = model.new(key: SSHKey.generate(type: "rsa").private_key)
    record.valid?

    assert record.errors[:key].empty?
  end

  test "rejects dsa key" do
    record = model.new(key: SSHKey.generate(type: "dsa").private_key)
    record.valid?

    refute record.errors[:key].empty?
  end

  test "sets translated error message" do
    I18n.locale = "pt-BR"

    record = model.new(key: SSHKey.generate(type: "dsa").private_key)
    record.valid?

    assert_includes record.errors[:key], "precisa ser uma chave RSA"
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
validators-3.4.2 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.4.1 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.4.0 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.3.0 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.2.1 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.2.0 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.1.1 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.1.0 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.0.5 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.0.4 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.0.3 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.0.2 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.0.1 test/validators/validates_ssh_private_key/rsa_test.rb
validators-3.0.0 test/validators/validates_ssh_private_key/rsa_test.rb