require 'spec_helper'

describe TrustCheck do

  it "defaults to all" do
    trust_check = TrustCheck.new

    trust_check.trusted?('127.0.0.1', 6767).should be_true
    trust_check.trusted?('127.0.0.1', 6768).should be_true
    trust_check.trusted?('192.0.0.1', 6768).should be_true
    trust_check.trusted?('10.0.0.1', 6768).should be_true
    trust_check.trusted?('11.0.0.1', 6768).should be_true
  end

  it "verifies port when specified" do
    trust_check = TrustCheck.new(6768)

    trust_check.trusted?('127.0.0.1', 6767).should be_false
    trust_check.trusted?('127.0.0.1', 6768).should be_true
    trust_check.trusted?('192.0.0.1', 6768).should be_true
    trust_check.trusted?('10.0.0.1', 6768).should be_true
    trust_check.trusted?('11.0.0.1', 6768).should be_true
  end

  it "verifies cidr when specified" do
    trust_check = TrustCheck.new(6768, '127.0.0.1/8')

    trust_check.trusted?('127.0.0.1', 6767).should be_false
    trust_check.trusted?('127.0.0.1', 6768).should be_true
    trust_check.trusted?('192.0.0.1', 6768).should be_false
    trust_check.trusted?('10.0.0.1', 6768).should be_false
    trust_check.trusted?('11.0.0.1', 6768).should be_false
  end

  it "verifies mutltiple cidrs" do
    trust_check = TrustCheck.new(6768, ['192.168.1.2', '192.168.1.3'])

    trust_check.trusted?('192.168.1.1', 6767).should be_false
    trust_check.trusted?('192.168.1.2', 6767).should be_false
    trust_check.trusted?('192.168.1.1', 6768).should be_false
    trust_check.trusted?('192.168.1.2', 6768).should be_true
    trust_check.trusted?('192.168.1.3', 6768).should be_true
    trust_check.trusted?('192.168.1.4', 6768).should be_false
  end
end