ruby-paloalto-client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +152 -0
  9. data/Rakefile +2 -0
  10. data/lib/palo-alto/client/version.rb +5 -0
  11. data/lib/palo-alto/client.rb +50 -0
  12. data/lib/palo-alto/common/base-api.rb +84 -0
  13. data/lib/palo-alto/helpers/rest.rb +46 -0
  14. data/lib/palo-alto/models/address-group.rb +27 -0
  15. data/lib/palo-alto/models/address.rb +25 -0
  16. data/lib/palo-alto/models/device.rb +27 -0
  17. data/lib/palo-alto/models/rulebase.rb +24 -0
  18. data/lib/palo-alto/models/virtual-system.rb +28 -0
  19. data/lib/palo-alto/v6/address-api.rb +46 -0
  20. data/lib/palo-alto/v6/address-group-api.rb +57 -0
  21. data/lib/palo-alto/v6/api.rb +16 -0
  22. data/lib/palo-alto/v6/device-api.rb +55 -0
  23. data/lib/palo-alto/v6/virtual-system-api.rb +76 -0
  24. data/ruby-paloalto-client.gemspec +29 -0
  25. data/spec/fixtures/address_groups.xml +14 -0
  26. data/spec/fixtures/addresses.xml +14 -0
  27. data/spec/fixtures/blank_address_groups.xml +6 -0
  28. data/spec/fixtures/blank_addresses.xml +5 -0
  29. data/spec/fixtures/blank_devices.xml +4 -0
  30. data/spec/fixtures/blank_virtual_systems.xml +4 -0
  31. data/spec/fixtures/devices.xml +17 -0
  32. data/spec/fixtures/failure.xml +2 -0
  33. data/spec/fixtures/no_address_group_virtual_systems.xml +24 -0
  34. data/spec/fixtures/no_address_virtual_systems.xml +24 -0
  35. data/spec/fixtures/no_members_address_groups.xml +11 -0
  36. data/spec/fixtures/no_rulebase_virtual_systems.xml +24 -0
  37. data/spec/fixtures/no_vsys_devices.xml +13 -0
  38. data/spec/fixtures/virtual_systems.xml +32 -0
  39. data/spec/lib/palo-alto/client_spec.rb +36 -0
  40. data/spec/lib/palo-alto/common/base_api_spec.rb +121 -0
  41. data/spec/lib/palo-alto/helpers/rest_spec.rb +32 -0
  42. data/spec/lib/palo-alto/models/address_group_spec.rb +43 -0
  43. data/spec/lib/palo-alto/models/address_spec.rb +32 -0
  44. data/spec/lib/palo-alto/models/device_spec.rb +43 -0
  45. data/spec/lib/palo-alto/models/rulebase_spec.rb +23 -0
  46. data/spec/lib/palo-alto/models/virtual_system_spec.rb +53 -0
  47. data/spec/lib/palo-alto/v6/address_api_spec.rb +54 -0
  48. data/spec/lib/palo-alto/v6/address_group_api_spec.rb +79 -0
  49. data/spec/lib/palo-alto/v6/api_spec.rb +4 -0
  50. data/spec/lib/palo-alto/v6/device_api_spec.rb +78 -0
  51. data/spec/lib/palo-alto/v6/virtual_system_api_spec.rb +93 -0
  52. data/spec/spec_helper.rb +26 -0
  53. metadata +221 -0
@@ -0,0 +1,55 @@
1
+ require "palo-alto/models/device"
2
+ require "palo-alto/models/virtual-system"
3
+
4
+ module PaloAlto
5
+ module V6
6
+ module DeviceApi
7
+ # Parse out the devices from a response to query for devices
8
+ #
9
+ # == Returns
10
+ #
11
+ # * +Array+ - Array of Models::Device instances
12
+ #
13
+ # == Raises
14
+ #
15
+ # * +Exception+ - Raises an exception if the request is unsuccessful
16
+ def devices
17
+ devices_list = []
18
+
19
+ # configure options for the request
20
+ options = {}
21
+ options[:url] = self.endpoint
22
+ options[:method] = :post
23
+ options[:payload] = { type: "config",
24
+ action: "show",
25
+ key: self.auth_key,
26
+ xpath: "/config/devices" }
27
+
28
+ html_result = Helpers::Rest.make_request(options)
29
+
30
+ raise "Error obtaining device XML" if html_result.nil?
31
+
32
+ # parse the XML data
33
+ data = Nokogiri::XML(html_result)
34
+
35
+ if data.xpath('//response/@status').to_s == "success"
36
+ data.xpath('//response/result/devices/entry').each do |device_entry|
37
+ device = PaloAlto::Models::Device.new(name: device_entry.xpath('@name').to_s,
38
+ ip: device_entry.xpath('deviceconfig/system/ip-address').first.content)
39
+
40
+ # get all virtual_system members for the device
41
+ device_entry.xpath('vsys/entry').each do |vsys_entry|
42
+ device.virtual_systems << PaloAlto::Models::VirtualSystem.new(name: vsys_entry.xpath('@name').to_s)
43
+ end
44
+
45
+ devices_list << device
46
+ end
47
+ else
48
+ raise "Error in response XML: #{data.inspect}"
49
+ end
50
+
51
+ devices_list
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,76 @@
1
+ require "palo-alto/models/virtual-system"
2
+ require "palo-alto/models/address"
3
+ require "palo-alto/models/address-group"
4
+ require "palo-alto/models/rulebase"
5
+
6
+ module PaloAlto
7
+ module V6
8
+ module VirtualSystemApi
9
+ # Parse out the virtual systems from a response to query for virtual systems
10
+ #
11
+ # == Returns
12
+ #
13
+ # * +Array+ - Array of Models::VirtualSystem instances
14
+ #
15
+ # == Raises
16
+ #
17
+ # * +Exception+ - Raises an exception if the request is unsuccessful
18
+ def virtual_systems
19
+ virtual_systems_list = []
20
+
21
+ # configure options for the request
22
+ options = {}
23
+ options[:url] = self.endpoint
24
+ options[:method] = :post
25
+ options[:payload] = { type: "config",
26
+ action: "show",
27
+ key: self.auth_key,
28
+ xpath: "/config/devices/entry/vsys" }
29
+
30
+ html_result = Helpers::Rest.make_request(options)
31
+
32
+ raise "Error obtaining virtual system XML" if html_result.nil?
33
+
34
+ # parse the XML data
35
+ data = Nokogiri::XML(html_result)
36
+
37
+ if data.xpath('//response/@status').to_s == "success"
38
+ data.xpath('//response/result/vsys/entry').each do |vsys_entry|
39
+ vsys = PaloAlto::Models::VirtualSystem.new(name: vsys_entry.xpath('@name').to_s)
40
+
41
+ # get all address members for the virtual system
42
+ vsys_entry.xpath('address/entry').each do |address_entry|
43
+ vsys.addresses << PaloAlto::Models::Address.new(name: address_entry.xpath('@name').to_s,
44
+ ip: address_entry.xpath('ip-netmask').first.content)
45
+ end
46
+
47
+ # get all address group members for the virtual system
48
+ vsys_entry.xpath('address-group/entry').each do |address_group_entry|
49
+ address_group = PaloAlto::Models::AddressGroup.new(name: address_group_entry.xpath('@name').to_s,
50
+ description: address_group_entry.xpath('description').first.content)
51
+
52
+ # associate addresses with the address group
53
+ address_group_entry.xpath('*/member').each do |address_entry|
54
+ address_group.addresses << PaloAlto::Models::Address.new(name: address_entry.content, ip: "")
55
+ end
56
+
57
+ vsys.address_groups << address_group
58
+ end
59
+
60
+ # get all rulebase members for the virtual system
61
+ # TODO: Expand beyond just the security rulebase
62
+ vsys_entry.xpath('rulebase/security/rules/entry').each do |rulebase_entry|
63
+ vsys.rulebases << PaloAlto::Models::Rulebase.new(name: rulebase_entry.xpath('@name').to_s)
64
+ end
65
+
66
+ virtual_systems_list << vsys
67
+ end
68
+ else
69
+ raise "Error in response XML: #{data.inspect}"
70
+ end
71
+
72
+ virtual_systems_list
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'palo-alto/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-paloalto-client"
8
+ spec.version = PaloAlto::Client::VERSION
9
+ spec.authors = ["Justin Karimi"]
10
+ spec.email = ["jekhokie@gmail.com"]
11
+ spec.summary = %q{Ruby PaloAlto Client (API V6.X)}
12
+ spec.description = %q{A Ruby-based client library to interact with the PaloAlto APIs.}
13
+ spec.homepage = ""
14
+ spec.license = "Apache 2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "nokogiri"
22
+ spec.add_runtime_dependency "rest-client"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "fakeweb"
29
+ end
@@ -0,0 +1,14 @@
1
+ <response status="success" code="19">
2
+ <result total-count="1" count="1">
3
+ <entry name="test" src="tpl" admin="admin" time="2015/02/02 13:45:00">
4
+ <address-group admin="someone" time="2015/03/04 13:45:08">
5
+ <entry name="test" admin="someone" time="2015/03/04 13:45:08">
6
+ <static admin="someone" time="2015/03/04 13:45:08">
7
+ <member admin="someone" time="2015/03/04 13:45:08">10.10.111.225-1</member>
8
+ </static>
9
+ <description>Testing using API</description>
10
+ </entry>
11
+ </address-group>
12
+ </entry>
13
+ </result>
14
+ </response>
@@ -0,0 +1,14 @@
1
+ <response status="success">
2
+ <result>
3
+ <entry name="test" src="tpl" admin="admin" time="2015/02/02 13:45:00">
4
+ <address>
5
+ <entry name="test-1">
6
+ <ip-netmask>192.168.80.0/24</ip-netmask>
7
+ </entry>
8
+ <entry name="test-2">
9
+ <ip-netmask>10.10.111.225</ip-netmask>
10
+ </entry>
11
+ </address>
12
+ </entry>
13
+ </result>
14
+ </response>
@@ -0,0 +1,6 @@
1
+ <response status="success" code="19">
2
+ <result total-count="1" count="1">
3
+ <entry name="test" src="tpl" admin="admin" time="2015/02/02 13:45:00">
4
+ </entry>
5
+ </result>
6
+ </response>
@@ -0,0 +1,5 @@
1
+ <response status="success">
2
+ <result>
3
+ <entry name="test" src="tpl" admin="admin" time="2015/02/02 13:45:00">
4
+ </result>
5
+ </response>
@@ -0,0 +1,4 @@
1
+ <response status="success">
2
+ <result total-count="0" count="0">
3
+ </result>
4
+ </response>
@@ -0,0 +1,4 @@
1
+ <response status="success" code="19">
2
+ <result total-count="0" count="0">
3
+ </result>
4
+ </response>
@@ -0,0 +1,17 @@
1
+ <response status="success">
2
+ <result total-count="1" count="1">
3
+ <devices src="tpl" admin="admin" time="2015/03/05 10:22:56">
4
+ <entry name="localhost.localdomain" src="tpl" admin="admin" time="2015/03/05 10:22:56">
5
+ <vsys src="tpl" admin="jkarimi" time="2015/03/05 10:22:56">
6
+ <entry name="vsys1" src="tpl" admin="jkarimi" time="2015/03/05 10:22:56">
7
+ </entry>
8
+ </vsys>
9
+ <deviceconfig>
10
+ <system>
11
+ <ip-address>2.2.2.2</ip-address>
12
+ </system>
13
+ </deviceconfig>
14
+ </entry>
15
+ </devices>
16
+ </result>
17
+ </response>
@@ -0,0 +1,2 @@
1
+ <response status="fail">
2
+ </response>
@@ -0,0 +1,24 @@
1
+ <response status="success" code="19">
2
+ <result total-count="1" count="1">
3
+ <vsys src="tpl" admin="admin" time="2015/03/05 10:22:56">
4
+ <entry name="vsys1" src="tpl" admin="admin" time="2015/03/05 10:22:56">
5
+ <rulebase admin="admin" time="2015/03/04 13:46:08">
6
+ <security admin="admin" time="2015/03/04 13:46:08">
7
+ <rules admin="admin" time="2015/03/04 13:46:08">
8
+ <entry name="DNS" admin="admin" time="2015/03/04 13:46:07">
9
+ </entry>
10
+ </rules>
11
+ </security>
12
+ </rulebase>
13
+ <address admin="admin" time="2015/03/05 10:22:56">
14
+ <entry name="address-1" admin="admin" time="2015/03/04 13:39:03">
15
+ <ip-netmask admin="admin" time="2015/03/04 13:39:02">1.1.1.1</ip-netmask>
16
+ </entry>
17
+ <entry name="address-2" admin="admin" time="2015/03/05 10:22:56">
18
+ <ip-netmask admin="admin" time="2015/03/05 10:22:56">2.2.2.2</ip-netmask>
19
+ </entry>
20
+ </address>
21
+ </entry>
22
+ </vsys>
23
+ </result>
24
+ </response>
@@ -0,0 +1,24 @@
1
+ <response status="success" code="19">
2
+ <result total-count="1" count="1">
3
+ <vsys src="tpl" admin="admin" time="2015/03/05 10:22:56">
4
+ <entry name="vsys1" src="tpl" admin="admin" time="2015/03/05 10:22:56">
5
+ <rulebase admin="admin" time="2015/03/04 13:46:08">
6
+ <security admin="admin" time="2015/03/04 13:46:08">
7
+ <rules admin="admin" time="2015/03/04 13:46:08">
8
+ <entry name="DNS" admin="admin" time="2015/03/04 13:46:07">
9
+ </entry>
10
+ </rules>
11
+ </security>
12
+ </rulebase>
13
+ <address-group admin="admin" time="2015/03/04 13:45:08">
14
+ <entry name="test" admin="admin" time="2015/03/04 13:45:08">
15
+ <static admin="admin" time="2015/03/04 13:45:08">
16
+ <member admin="admin" time="2015/03/04 13:45:08">address-group-1</member>
17
+ </static>
18
+ <description>Testing using API</description>
19
+ </entry>
20
+ </address-group>
21
+ </entry>
22
+ </vsys>
23
+ </result>
24
+ </response>
@@ -0,0 +1,11 @@
1
+ <response status="success" code="19">
2
+ <result total-count="1" count="1">
3
+ <entry name="test" src="tpl" admin="admin" time="2015/02/02 13:45:00">
4
+ <address-group admin="someone" time="2015/03/04 13:45:08">
5
+ <entry name="test" admin="someone" time="2015/03/04 13:45:08">
6
+ <description>Testing using API</description>
7
+ </entry>
8
+ </address-group>
9
+ </entry>
10
+ </result>
11
+ </response>
@@ -0,0 +1,24 @@
1
+ <response status="success" code="19">
2
+ <result total-count="1" count="1">
3
+ <vsys src="tpl" admin="admin" time="2015/03/05 10:22:56">
4
+ <entry name="vsys1" src="tpl" admin="admin" time="2015/03/05 10:22:56">
5
+ <address admin="admin" time="2015/03/05 10:22:56">
6
+ <entry name="address-1" admin="admin" time="2015/03/04 13:39:03">
7
+ <ip-netmask admin="admin" time="2015/03/04 13:39:02">1.1.1.1</ip-netmask>
8
+ </entry>
9
+ <entry name="address-2" admin="admin" time="2015/03/05 10:22:56">
10
+ <ip-netmask admin="admin" time="2015/03/05 10:22:56">2.2.2.2</ip-netmask>
11
+ </entry>
12
+ </address>
13
+ <address-group admin="admin" time="2015/03/04 13:45:08">
14
+ <entry name="test" admin="admin" time="2015/03/04 13:45:08">
15
+ <static admin="admin" time="2015/03/04 13:45:08">
16
+ <member admin="admin" time="2015/03/04 13:45:08">address-group-1</member>
17
+ </static>
18
+ <description>Testing using API</description>
19
+ </entry>
20
+ </address-group>
21
+ </entry>
22
+ </vsys>
23
+ </result>
24
+ </response>
@@ -0,0 +1,13 @@
1
+ <response status="success">
2
+ <result total-count="1" count="1">
3
+ <devices src="tpl" admin="admin" time="2015/03/05 10:22:56">
4
+ <entry name="localhost.localdomain" src="tpl" admin="admin" time="2015/03/05 10:22:56">
5
+ <deviceconfig>
6
+ <system>
7
+ <ip-address>2.2.2.2</ip-address>
8
+ </system>
9
+ </deviceconfig>
10
+ </entry>
11
+ </devices>
12
+ </result>
13
+ </response>
@@ -0,0 +1,32 @@
1
+ <response status="success" code="19">
2
+ <result total-count="1" count="1">
3
+ <vsys src="tpl" admin="admin" time="2015/03/05 10:22:56">
4
+ <entry name="vsys1" src="tpl" admin="admin" time="2015/03/05 10:22:56">
5
+ <rulebase admin="admin" time="2015/03/04 13:46:08">
6
+ <security admin="admin" time="2015/03/04 13:46:08">
7
+ <rules admin="admin" time="2015/03/04 13:46:08">
8
+ <entry name="DNS" admin="admin" time="2015/03/04 13:46:07">
9
+ </entry>
10
+ </rules>
11
+ </security>
12
+ </rulebase>
13
+ <address admin="admin" time="2015/03/05 10:22:56">
14
+ <entry name="address-1" admin="admin" time="2015/03/04 13:39:03">
15
+ <ip-netmask admin="admin" time="2015/03/04 13:39:02">1.1.1.1</ip-netmask>
16
+ </entry>
17
+ <entry name="address-2" admin="admin" time="2015/03/05 10:22:56">
18
+ <ip-netmask admin="admin" time="2015/03/05 10:22:56">2.2.2.2</ip-netmask>
19
+ </entry>
20
+ </address>
21
+ <address-group admin="admin" time="2015/03/04 13:45:08">
22
+ <entry name="test" admin="admin" time="2015/03/04 13:45:08">
23
+ <static admin="admin" time="2015/03/04 13:45:08">
24
+ <member admin="admin" time="2015/03/04 13:45:08">address-group-1</member>
25
+ </static>
26
+ <description>Testing using API</description>
27
+ </entry>
28
+ </address-group>
29
+ </entry>
30
+ </vsys>
31
+ </result>
32
+ </response>
@@ -0,0 +1,36 @@
1
+ require "palo-alto/client"
2
+
3
+ describe "PaloAlto::Client" do
4
+ let(:host) { "some.host" }
5
+ let(:port) { "443" }
6
+ let(:ssl) { true }
7
+ let(:username) { "admin" }
8
+ let(:password) { "admin" }
9
+ let(:api_version) { "6" }
10
+
11
+ describe ".new" do
12
+ let(:fake_api) { Class.new }
13
+
14
+ it "attempts to create a new Api instance" do
15
+ expect(Object).to receive(:const_get).and_return(fake_api)
16
+ expect(fake_api).to receive(:new)
17
+
18
+ PaloAlto::Client.new(host: host,
19
+ port: port,
20
+ ssl: ssl,
21
+ username: username,
22
+ password: password,
23
+ api_version: api_version)
24
+ end
25
+
26
+ it "raises an exception for an un-implemented API version" do
27
+ expect(File).to receive("exist?").and_return(false)
28
+ expect{ PaloAlto::Client.new(host: host,
29
+ port: port,
30
+ ssl: ssl,
31
+ username: username,
32
+ password: password,
33
+ api_version: "BOGUS") }.to raise_exception
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,121 @@
1
+ require "palo-alto/common/base-api"
2
+ require "palo-alto/helpers/rest"
3
+
4
+ describe "PaloAlto::Common::BaseApi" do
5
+ let(:host) { "some.host" }
6
+ let(:port) { "443" }
7
+ let(:ssl) { false }
8
+ let(:username) { "admin" }
9
+ let(:password) { "admin" }
10
+ let(:api_version) { "6" }
11
+ let(:url) { "http://#{host}:#{port}/api/" }
12
+ let(:auth_key) { "039th90hg092h" }
13
+ let(:auth_response) { "<response status=\"success\">
14
+ <result>
15
+ <key>#{auth_key}</key>
16
+ </result>
17
+ </response>" }
18
+
19
+ before do
20
+ FakeWeb.clean_registry
21
+ FakeWeb.register_uri(:post, url, :status => [ 200 ], :body => auth_response)
22
+
23
+ @api = PaloAlto::Common::BaseApi.new(host: host,
24
+ port: port,
25
+ ssl: ssl,
26
+ username: username,
27
+ password: password)
28
+ end
29
+
30
+ it "has a host attribute" do
31
+ expect(@api).to respond_to(:host)
32
+ end
33
+
34
+ it "has a port attribute" do
35
+ expect(@api).to respond_to(:port)
36
+ end
37
+
38
+ it "has a ssl attribute" do
39
+ expect(@api).to respond_to(:ssl)
40
+ end
41
+
42
+ it "has a username attribute" do
43
+ expect(@api).to respond_to(:username)
44
+ end
45
+
46
+ it "has a password attribute" do
47
+ expect(@api).to respond_to(:password)
48
+ end
49
+
50
+ it "has an auth_key attribute" do
51
+ expect(@api).to respond_to(:auth_key)
52
+ end
53
+
54
+ describe ".initialize" do
55
+ it "returns a PaloAlto::V6::Api instance" do
56
+ expect(@api).to be_instance_of(PaloAlto::Common::BaseApi)
57
+ end
58
+
59
+ it "assigns host" do
60
+ expect(@api.host).to eq(host)
61
+ end
62
+
63
+ it "assigns port" do
64
+ expect(@api.port).to eq(port)
65
+ end
66
+
67
+ it "assigns ssl" do
68
+ expect(@api.ssl).to eq(ssl)
69
+ end
70
+
71
+ it "assigns username" do
72
+ expect(@api.username).to eq(username)
73
+ end
74
+
75
+ it "assigns password" do
76
+ expect(@api.password).to eq(password)
77
+ end
78
+
79
+ it "obtains and assigns the auth_key" do
80
+ expect(@api.auth_key).to eq(auth_key)
81
+ end
82
+
83
+ describe "when an auth_key cannot be obtained" do
84
+ before do
85
+ FakeWeb.clean_registry
86
+ FakeWeb.register_uri(:post, url, :status => [ 401 ], :body => File.open(fixture_file("failure.xml")).read)
87
+ end
88
+
89
+ it "throws and exception" do
90
+ expect{ PaloAlto::Common::BaseApi.new(host: host,
91
+ port: port,
92
+ ssl: ssl,
93
+ username: username,
94
+ password: password) }.to raise_exception
95
+ end
96
+ end
97
+ end
98
+
99
+ describe ".endpoint" do
100
+ it "returns the endpoint with secure protocol" do
101
+ url = "http://#{host}:#{port}/api/"
102
+ expect(@api.endpoint).to eq(url)
103
+ end
104
+ end
105
+
106
+ describe "private method" do
107
+ describe ".get_auth_key" do
108
+ it "returns the resulting auth_key from a request" do
109
+ expect(PaloAlto::Helpers::Rest).to receive(:make_request).and_return(auth_response)
110
+
111
+ expect(@api.send(:get_auth_key)).to eq(auth_key)
112
+ end
113
+
114
+ it "returns nil when a HTTP request attempt is unsuccessful" do
115
+ expect(PaloAlto::Helpers::Rest).to receive(:make_request).and_return(File.open(fixture_file("failure.xml")).read)
116
+
117
+ expect(@api.send(:get_auth_key)).to be_nil
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,32 @@
1
+ require "palo-alto/helpers/rest"
2
+ require "rest-client"
3
+
4
+ describe "PaloAlto::Helpers::Rest" do
5
+ let(:url) { "http://localhost.localdomain:443/api/" }
6
+ let(:specified_opts) { { url: url,
7
+ method: :post,
8
+ payload: {
9
+ type: "config",
10
+ action: "set"
11
+ }
12
+ }
13
+ }
14
+ let(:final_opts) { { verify_ssl: OpenSSL::SSL::VERIFY_NONE,
15
+ headers: {
16
+ "User-Agent" => "ruby-keystone-client",
17
+ "Accept" => "application/xml",
18
+ "Content-Type" => "application/xml"
19
+ }
20
+ }.merge(specified_opts)
21
+ }
22
+
23
+ describe "#make_request" do
24
+ before do
25
+ expect(RestClient::Request).to receive(:execute).with(final_opts).and_return(true)
26
+ end
27
+
28
+ it "makes the specified request" do
29
+ expect(PaloAlto::Helpers::Rest.make_request(specified_opts)).to be_truthy
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require "palo-alto/models/address-group"
2
+
3
+ describe "PaloAlto::Models::AddressGroup" do
4
+ let(:name) { "test-address-group" }
5
+ let(:description) { "test-address-group-description" }
6
+ let(:addresses) { [ "a", "b" ] }
7
+
8
+ before do
9
+ @address_group = PaloAlto::Models::AddressGroup.new(name: name,
10
+ description: description,
11
+ addresses: addresses)
12
+ end
13
+
14
+ it "has a name attribute" do
15
+ expect(@address_group).to respond_to(:name)
16
+ end
17
+
18
+ it "has a description attribute" do
19
+ expect(@address_group).to respond_to(:description)
20
+ end
21
+
22
+ it "has an addresses attribute" do
23
+ expect(@address_group).to respond_to(:addresses)
24
+ end
25
+
26
+ describe ".initialize" do
27
+ it "returns a PaloAlto::Models::AddressGroup instance" do
28
+ expect(@address_group).to be_instance_of(PaloAlto::Models::AddressGroup)
29
+ end
30
+
31
+ it "assigns name" do
32
+ expect(@address_group.name).to eq(name)
33
+ end
34
+
35
+ it "assigns description" do
36
+ expect(@address_group.description).to eq(description)
37
+ end
38
+
39
+ it "assigns addresses" do
40
+ expect(@address_group.addresses).to eq(addresses)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ require "palo-alto/models/address"
2
+
3
+ describe "PaloAlto::Models::Address" do
4
+ let(:name) { "test-address" }
5
+ let(:ip) { "2.2.2.2" }
6
+
7
+ before do
8
+ @address = PaloAlto::Models::Address.new(name: name, ip: ip)
9
+ end
10
+
11
+ it "has a name attribute" do
12
+ expect(@address).to respond_to(:name)
13
+ end
14
+
15
+ it "has an ip attribute" do
16
+ expect(@address).to respond_to(:ip)
17
+ end
18
+
19
+ describe ".initialize" do
20
+ it "returns a PaloAlto::Models::Address instance" do
21
+ expect(@address).to be_instance_of(PaloAlto::Models::Address)
22
+ end
23
+
24
+ it "assigns name" do
25
+ expect(@address.name).to eq(name)
26
+ end
27
+
28
+ it "assigns ip" do
29
+ expect(@address.ip).to eq(ip)
30
+ end
31
+ end
32
+ end