Inspec is an IT Security and Compliance-as-code framework for validating compliance.

What and Why Inspec?

Features of Inspec

Develop Custom Resources/Library for Inspec

Let’s go through sample resource which basically tests whether the given string is palindrome or not.

class PalindromeResource < Inspec.resource(1)
  name 'palin_drome'
  desc 'This resource checks whether the attribute is palindrome or not'
  example '
    describe palin_drome() do
      it { should be_palindrome }
      its(size) { should > 5 }
    end
  '
  def initialize(attribute)
    @params = {}
    @attribute = attribute
    @params['size'] = attribute.length
  end

  def palindrome?
    @attribute == @attribute.reverse
  end

  def method_missing(name)
    return @params[name.to_s]
  end

Example Control file for our Custom resource

# encoding: utf-8
# copyright: 2018, Anshul Patel

# you add controls here
control 'Palindrome-1.0' do
  impact 1.0
  title 'Palindrome Resource'
  desc 'Palindrome Resource'
  describe palin_drome("saras")  do
    it { should be_palindrome }
    its('size') {should > 3 }
  end
end

Example GitHub Repository : https://github.com/anshulpatel25/palindrome-inspec

References