mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
Merge pull request #5931 from inspec/ss/resource-ppa
CFINSPEC-82: Add ppa resource
This commit is contained in:
commit
4c351b00c8
4 changed files with 118 additions and 11 deletions
64
docs-chef-io/content/inspec/resources/ppa.md
Normal file
64
docs-chef-io/content/inspec/resources/ppa.md
Normal file
|
@ -0,0 +1,64 @@
|
|||
+++
|
||||
title = "ppa resource"
|
||||
draft = false
|
||||
gh_repo = "inspec"
|
||||
platform = "linux"
|
||||
|
||||
[menu]
|
||||
[menu.inspec]
|
||||
title = "ppa"
|
||||
identifier = "inspec/resources/os/ppa.md ppa resource"
|
||||
parent = "inspec/resources/os"
|
||||
+++
|
||||
|
||||
Use the `ppa` Chef InSpec audit resource to verify the PPA repositories on Debian-based Linux distributions. The Personal Package Archives (PPAs) are software repositories designed for Ubuntu users and are easier to install than other third-party repositories.
|
||||
|
||||
The following ppa formats are supported:
|
||||
|
||||
- `ubuntu-wine/ppa`
|
||||
- `ppa:ubuntu-wine/ppa`
|
||||
- `http://ppa.launchpad.net/juju/stable/ubuntu`
|
||||
|
||||
## Availability
|
||||
|
||||
### Installation
|
||||
|
||||
This resource is distributed with Chef InSpec.
|
||||
|
||||
## Syntax
|
||||
|
||||
describe ppa('PATH') do
|
||||
it { should exist }
|
||||
it { should be_enabled }
|
||||
end
|
||||
where
|
||||
|
||||
- `ppa('PATH')` represents PPA repository
|
||||
- `exist` and `be_enabled` are a valid matchers for this resource.
|
||||
|
||||
## Matchers
|
||||
|
||||
For a full list of available matchers, please visit our [matchers page](https://docs.chef.io/inspec/matchers/).
|
||||
|
||||
### exist
|
||||
|
||||
The `exist` matcher tests if a repository exists on the system:
|
||||
|
||||
it { should exist }
|
||||
|
||||
### be_enabled
|
||||
|
||||
The `be_enabled` matcher tests if a repository is enabled on the system:
|
||||
|
||||
it { should be_enabled }
|
||||
|
||||
## Example
|
||||
|
||||
The following example shows how to use this Chef InSpec audit resource.
|
||||
|
||||
### Verify that a PPA repository exists and is enabled
|
||||
|
||||
describe ppa('ppa:nginx/stable') do
|
||||
it { should exist }
|
||||
it { should be_enabled }
|
||||
end
|
|
@ -83,11 +83,6 @@
|
|||
"suffix": "This resource was removed in InSpec 4.0.",
|
||||
"comment": "Needed for ServerSpec compatibility"
|
||||
},
|
||||
"resource_ppa": {
|
||||
"action": "exit",
|
||||
"suffix": "This resource was removed in InSpec 4.0.",
|
||||
"comment": "Needed for ServerSpec compatibility"
|
||||
},
|
||||
"resource_script": {
|
||||
"action": "exit",
|
||||
"suffix": "This resource will be removed in InSpec 4.0"
|
||||
|
|
|
@ -135,19 +135,25 @@ module Inspec::Resources
|
|||
|
||||
class PpaRepository < AptRepository
|
||||
name "ppa"
|
||||
desc "Use the ppa InSpec audit resource to verify PPA repositories on the Debian-based linux platforms."
|
||||
example <<~EXAMPLE
|
||||
describe ppa('ubuntu-wine/ppa') do
|
||||
it { should exist }
|
||||
it { should be_enabled }
|
||||
end
|
||||
|
||||
describe ppa('ppa:ubuntu-wine/ppa') do
|
||||
it { should exist }
|
||||
it { should be_enabled }
|
||||
end
|
||||
EXAMPLE
|
||||
|
||||
def exists?
|
||||
deprecated
|
||||
super()
|
||||
end
|
||||
|
||||
def enabled?
|
||||
deprecated
|
||||
super()
|
||||
end
|
||||
|
||||
def deprecated
|
||||
Inspec.deprecate(:resource_ppa, "The `ppa` resource is deprecated. Please use `apt`")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
42
test/unit/resources/ppa_test.rb
Normal file
42
test/unit/resources/ppa_test.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require "inspec/globals"
|
||||
require "#{Inspec.src_root}/test/helper"
|
||||
require_relative "../../../lib/inspec/resources/ppa"
|
||||
|
||||
describe Inspec::Resources::PpaRepository do
|
||||
|
||||
it "checks on ubuntu as name/ppa" do
|
||||
resource = MockLoader.new(:ubuntu).load_resource("ppa", "ubuntu-wine/ppa")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.enabled?).must_equal true
|
||||
end
|
||||
|
||||
it "checks on ubuntu as ppa:name/ppa" do
|
||||
resource = MockLoader.new(:ubuntu).load_resource("ppa", "ppa:ubuntu-wine/ppa")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.enabled?).must_equal true
|
||||
end
|
||||
|
||||
it "checks on mint as name/ppa" do
|
||||
resource = MockLoader.new(:mint18).load_resource("ppa", "ubuntu-wine/ppa")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.enabled?).must_equal true
|
||||
end
|
||||
|
||||
it "checks on mint as ppa:name/ppa" do
|
||||
resource = MockLoader.new(:mint18).load_resource("ppa", "ppa:ubuntu-wine/ppa")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.enabled?).must_equal true
|
||||
end
|
||||
|
||||
it "checks on debian as http://name/" do
|
||||
resource = MockLoader.new(:debian8).load_resource("ppa", "http://archive.ubuntu.com/ubuntu/")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.enabled?).must_equal true
|
||||
end
|
||||
|
||||
it "checks on unknown os" do
|
||||
resource = MockLoader.new(:undefined).load_resource("ppa", "ubuntu-wine/ppa")
|
||||
_(resource.exists?).must_equal false
|
||||
_(resource.enabled?).must_equal false
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue