Sha256: 3dce0cad1cb2f24b5ea0143e9762bed21188c979b1d687b49045ae642d5df869

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

require "openssl"

require File.expand_path("../../../base", __FILE__)

require "vagrant/util/keypair"

describe Vagrant::Util::Keypair do
  describe ".create" do
    it "generates a usable keypair with no password" do
      # I don't know how to validate the final return value yet...
      pubkey, privkey, _ = described_class.create

      pubkey  = OpenSSL::PKey::RSA.new(pubkey)
      privkey = OpenSSL::PKey::RSA.new(privkey)

      encrypted = pubkey.public_encrypt("foo")
      decrypted = privkey.private_decrypt(encrypted)

      expect(decrypted).to eq("foo")
    end

    it "generates a keypair that requires a password" do
      pubkey, privkey, _ = described_class.create("password")

      pubkey  = OpenSSL::PKey::RSA.new(pubkey)
      privkey = OpenSSL::PKey::RSA.new(privkey, "password")

      encrypted = pubkey.public_encrypt("foo")
      decrypted = privkey.private_decrypt(encrypted)

      expect(decrypted).to eq("foo")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-cloudstack-1.2.0 vendor/bundle/bundler/gems/vagrant-c84e05fd063f/test/unit/vagrant/util/keypair_test.rb