Sha256: 3b299c157488c9b02d409dcc31574cf4c8823d215843676f59e1a46f28b1b878

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

#
# Author:: Mukta Aphale <mukta.aphale@clogeny.com>
# Copyright:: Copyright (c) 2014-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'spec_helper'
require 'chef/knife/windows_cert_install'

describe Chef::Knife::WindowsCertInstall do
  context "on Windows" do
    before do
      allow(Chef::Platform).to receive(:windows?).and_return(true)
      @certinstall = Chef::Knife::WindowsCertInstall.new
    end

    it "installs certificate" do
      @certinstall.name_args = ["test-path"]
      @certinstall.config[:cert_passphrase] = "your-secret!"
      allow(Chef::Platform).to receive(:windows?).and_return(true)
      expect(@certinstall).to receive(:`).with("powershell.exe -Command \" 'your-secret!' | certutil -importPFX 'test-path' AT_KEYEXCHANGE\"")
      expect(@certinstall.ui).to receive(:info).with("Certificate added to Certificate Store")
      expect(@certinstall.ui).to receive(:info).with("Adding certificate to the Windows Certificate Store...")
      @certinstall.run
    end
  end

  context "not on Windows" do
    before do
      allow(Chef::Platform).to receive(:windows?).and_return(false)
      @listener = Chef::Knife::WindowsListenerCreate.new
    end

    it "exits with an error" do
      expect(@listener.ui).to receive(:error)
      expect { @listener.run }.to raise_error(SystemExit)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
knife-windows-1.7.0 spec/unit/knife/windows_cert_install_spec.rb
knife-windows-1.6.0 spec/unit/knife/windows_cert_install_spec.rb