Sha256: 86ca787f492c429105e966989d75b7a3847dfa307c87f8a94819160fff0139f6

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

require 'certmeister/policy/ip'

describe Certmeister::Policy::IP do

  subject { Certmeister::Policy::IP.new(['127.0.0.0/8', '192.168.0.0/23']) }

  it "demands a request" do
    expect { subject.authenticate }.to raise_error(ArgumentError)
  end

  it "refuses to authenticate a request with a missing ip" do
    response = subject.authenticate(cn: 'localhost')
    expect(response).to_not be_authenticated
    expect(response.error).to eql "missing ip"
  end

  it "refuses to authenticate a request with a malformed ip" do
    response = subject.authenticate(cn: 'localhost', ip: '127.1')
    expect(response).to_not be_authenticated
    expect(response.error).to eql "invalid ip"
  end

  it "refuses to authenticate an IP outside the configured list of networks" do
    response = subject.authenticate(cn: 'localhost', ip: '172.16.0.1')
    expect(response).to_not be_authenticated
    expect(response.error).to eql "unauthorized ip"
  end

  it "allows an IP inside a configured network" do
    response = subject.authenticate(cn: 'localhost', ip: '192.168.0.1')
    expect(response).to be_authenticated
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
certmeister-0.2.0 spec/certmeister/policy/ip_spec.rb