vulndbhq 0.0.1.beta → 0.1.0
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.
- data/.rspec +1 -0
- data/.travis.yml +4 -1
- data/Gemfile +2 -0
- data/README.md +36 -9
- data/lib/vulndbhq/base.rb +4 -0
- data/lib/vulndbhq/client.rb +45 -2
- data/lib/vulndbhq/configurable.rb +23 -6
- data/lib/vulndbhq/default.rb +1 -0
- data/lib/vulndbhq/error/base.rb +36 -0
- data/lib/vulndbhq/error/client_error.rb +26 -0
- data/lib/vulndbhq/error/failed_dependency.rb +8 -0
- data/lib/vulndbhq/error/not_found.rb +8 -0
- data/lib/vulndbhq/error/unauthorized.rb +8 -0
- data/lib/vulndbhq/error.rb +5 -0
- data/lib/vulndbhq/public_page.rb +5 -0
- data/lib/vulndbhq/response/raise_client_error.rb +13 -0
- data/lib/vulndbhq/version.rb +3 -3
- data/lib/vulndbhq.rb +9 -15
- data/spec/faraday_spec.rb +2 -5
- data/spec/vulndbhq/client_spec.rb +8 -1
- data/spec/vulndbhq/error/client_error_spec.rb +22 -0
- data/spec/vulndbhq/private_page_spec.rb +14 -2
- data/spec/vulndbhq/public_page_spec.rb +32 -0
- data/spec/vulndbhq_spec.rb +19 -1
- data/vulndbhq.gemspec +2 -0
- metadata +21 -6
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -2,6 +2,9 @@ language: ruby
|
|
2
2
|
matrix:
|
3
3
|
allow_failures:
|
4
4
|
- rvm: ruby-head
|
5
|
+
# There is a problem in fraday 0.8 with jruby + ssl
|
6
|
+
- rvm: jruby-18mode
|
7
|
+
- rvm: jruby-19mode
|
5
8
|
rvm:
|
6
9
|
- jruby-18mode
|
7
10
|
- jruby-19mode
|
@@ -13,4 +16,4 @@ rvm:
|
|
13
16
|
- ruby-head
|
14
17
|
notifications:
|
15
18
|
email:
|
16
|
-
- daniel@securityroots.com
|
19
|
+
- daniel@securityroots.com
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,13 +7,6 @@ This gem provides a Ruby wrapper to the VulnDB HQ API (http://vulndbhq.com).
|
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
DANGER, WILL ROBINSON!
|
11
|
-
DANGER, WILL ROBINSON!
|
12
|
-
DANGER, WILL ROBINSON!
|
13
|
-
THIS GEM IS IN EARLY BETA STAGE. EVERYTHING CAN CHANGE AT ANY POINT!!
|
14
|
-
|
15
|
-
THIS GEM USES API v2 WHICH WILL BE AVAILABLE SOON
|
16
|
-
|
17
10
|
Add this line to your application's Gemfile:
|
18
11
|
|
19
12
|
gem 'vulndbhq'
|
@@ -40,11 +33,21 @@ client.user = 'your@email.com'
|
|
40
33
|
client.password = 'password'
|
41
34
|
```
|
42
35
|
|
36
|
+
Or provide configuration in line:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
client = VulnDBHQ::Client.new(host: 'https://your.vulndbhq.com', user: 'your@email.com', password: 'password')
|
40
|
+
```
|
41
|
+
|
43
42
|
## Usage examples
|
44
43
|
|
45
|
-
Return the
|
44
|
+
Return the all PrivatePage:
|
45
|
+
|
46
|
+
client.private_pages
|
47
|
+
|
48
|
+
Return private pages containing `XSS`
|
46
49
|
|
47
|
-
|
50
|
+
client.private_pages(q: 'XSS')
|
48
51
|
|
49
52
|
Get a PrivatePage by id:
|
50
53
|
|
@@ -55,6 +58,15 @@ puts private_page.name
|
|
55
58
|
puts private_page.content
|
56
59
|
```
|
57
60
|
|
61
|
+
Return all the PublicPages:
|
62
|
+
|
63
|
+
client.public_pages
|
64
|
+
|
65
|
+
|
66
|
+
See the [VulnDB HQ API docs][api] for the full list of available methods.
|
67
|
+
|
68
|
+
[api]: http://support.securityroots.com/vulndbhq_api_v2.html
|
69
|
+
|
58
70
|
## Contributing
|
59
71
|
|
60
72
|
1. Fork it
|
@@ -62,3 +74,18 @@ puts private_page.content
|
|
62
74
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
63
75
|
4. Push to the branch (`git push origin my-new-feature`)
|
64
76
|
5. Create new Pull Request
|
77
|
+
|
78
|
+
|
79
|
+
## Copyright
|
80
|
+
|
81
|
+
Copyright (c) 2012 Daniel Martin, Security Roots Ltd.
|
82
|
+
See [LICENSE][license] for details.
|
83
|
+
|
84
|
+
[license]: https://github.com/securityroots/vulndbhq/blob/master/LICENSE
|
85
|
+
|
86
|
+
## Acknowledgements
|
87
|
+
|
88
|
+
This gem uses the [Faraday][faraday] gem for the HTTP layer and is inspired by the [Twitter][twitter] gem architecture.
|
89
|
+
|
90
|
+
[faraday]: http://rubygems.org/gems/faraday
|
91
|
+
[twitter]: http://rubygems.org/gems/twitter
|
data/lib/vulndbhq/base.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'vulndbhq/identity_map'
|
2
2
|
|
3
3
|
module VulnDBHQ
|
4
|
+
|
5
|
+
# Provides some common facilities for all VulnDBHQ objects including the
|
6
|
+
# ability to store attributes and to use an identity map to prevent
|
7
|
+
# re-loading the same object multiple times.
|
4
8
|
class Base
|
5
9
|
attr_reader :attrs
|
6
10
|
alias to_hash attrs
|
data/lib/vulndbhq/client.rb
CHANGED
@@ -4,8 +4,11 @@ require 'multi_json'
|
|
4
4
|
require 'vulndbhq/base'
|
5
5
|
require 'vulndbhq/configurable'
|
6
6
|
require 'vulndbhq/default'
|
7
|
+
require 'vulndbhq/error'
|
7
8
|
require 'vulndbhq/private_page'
|
9
|
+
require 'vulndbhq/public_page'
|
8
10
|
require 'vulndbhq/response/parse_json'
|
11
|
+
require 'vulndbhq/response/raise_client_error'
|
9
12
|
require 'vulndbhq/version'
|
10
13
|
|
11
14
|
module VulnDBHQ
|
@@ -22,10 +25,13 @@ module VulnDBHQ
|
|
22
25
|
# @return [VulnDBHQ::Client]
|
23
26
|
def initialize(options={})
|
24
27
|
VulnDBHQ::Configurable.keys.each do |key|
|
25
|
-
instance_variable_set("@#{key}", options[key] || VulnDBHQ.
|
28
|
+
instance_variable_set(:"@#{key}", options[key] || VulnDBHQ.instance_variable_get(:"@#{key}"))
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
32
|
+
|
33
|
+
# ************************************************************* PrivatePage
|
34
|
+
|
29
35
|
# Returns a private page
|
30
36
|
#
|
31
37
|
# @see http://support.securityroots.com/vulndbhq_api_v2.html#model-private-page
|
@@ -54,9 +60,46 @@ module VulnDBHQ
|
|
54
60
|
# VulnDBHQ.private_pages
|
55
61
|
def private_pages(options={})
|
56
62
|
response = get("/api/private_pages", options)
|
57
|
-
|
63
|
+
collection_from_array(response[:body], VulnDBHQ::PrivatePage)
|
58
64
|
end
|
59
65
|
|
66
|
+
|
67
|
+
# ************************************************************** PublicPage
|
68
|
+
|
69
|
+
# Returns a public page
|
70
|
+
#
|
71
|
+
# @see http://support.securityroots.com/vulndbhq_api_v2.html#model-public-page
|
72
|
+
|
73
|
+
# @authentication_required Yes
|
74
|
+
# @raise [VulnDBHQ::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
75
|
+
# @return [VulnDBHQ::PublicPage] The requested messages.
|
76
|
+
# @param id [Integer] A VulnDB HQ private page ID.
|
77
|
+
# @param options [Hash] A customizable set of options.
|
78
|
+
# @example Return the public page with the id 87
|
79
|
+
# VulnDBHQ.public_page(87)
|
80
|
+
def public_page(id, options={})
|
81
|
+
response = get("/api/public_pages/#{id}", options)
|
82
|
+
VulnDBHQ::PublicPage.from_response(response)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the collection of VulnDBHQ::PublicPage available at the moment
|
86
|
+
#
|
87
|
+
# @see http://support.securityroots.com/vulndbhq_api_v2.html#model-public-page
|
88
|
+
# @authentication_required Yes
|
89
|
+
# @raise [VulnDBHQ::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
90
|
+
# @return [Array<VulnDBHQ::PublicPage>] PrivatePages in the account associated with this user.
|
91
|
+
# @param options [Hash] A customizable set of options.
|
92
|
+
# @option options [nil] no options are supported yet.
|
93
|
+
# @example Return the public pages available in the system
|
94
|
+
# VulnDBHQ.public_pages
|
95
|
+
def public_pages(options={})
|
96
|
+
response = get("/api/public_pages", options)
|
97
|
+
collection_from_array(response[:body], VulnDBHQ::PublicPage)
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
# ********************************************************* Support methods
|
102
|
+
|
60
103
|
# Perform an HTTP GET request
|
61
104
|
def get(path, params={}, options={})
|
62
105
|
request(:get, path, params, options)
|
@@ -2,12 +2,6 @@ module VulnDBHQ
|
|
2
2
|
# Defines constants and methods related to configuration
|
3
3
|
module Configurable
|
4
4
|
|
5
|
-
# Convenience method to allow configuration options to be set in a block
|
6
|
-
def configure
|
7
|
-
yield self
|
8
|
-
self
|
9
|
-
end
|
10
|
-
|
11
5
|
# An array of valid keys in the options hash when configuring a {VulnDBHQ::Client}
|
12
6
|
CONFIG_KEYS = [
|
13
7
|
:connection_options,
|
@@ -25,5 +19,28 @@ module VulnDBHQ
|
|
25
19
|
def self.keys
|
26
20
|
@keys ||= CONFIG_KEYS + AUTH_KEYS
|
27
21
|
end
|
22
|
+
|
23
|
+
# Convenience method to allow configuration options to be set in a block
|
24
|
+
def configure
|
25
|
+
yield self
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def cache_key
|
30
|
+
options.hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def reset!
|
34
|
+
VulnDBHQ::Configurable.keys.each do |key|
|
35
|
+
instance_variable_set(:"@#{key}", VulnDBHQ::Default.options[key])
|
36
|
+
end
|
37
|
+
self
|
38
|
+
end
|
39
|
+
alias setup reset!
|
40
|
+
|
41
|
+
private
|
42
|
+
def options
|
43
|
+
Hash[VulnDBHQ::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
|
44
|
+
end
|
28
45
|
end
|
29
46
|
end
|
data/lib/vulndbhq/default.rb
CHANGED
@@ -26,6 +26,7 @@ module VulnDBHQ
|
|
26
26
|
@middleware ||= Faraday::Builder.new(
|
27
27
|
&Proc.new do |builder|
|
28
28
|
builder.use Faraday::Request::UrlEncoded # Convert request params as "www-form-urlencoded"
|
29
|
+
builder.use VulnDBHQ::Response::RaiseClientError # Handle 4xx server responses
|
29
30
|
builder.use VulnDBHQ::Response::ParseJson # Parse JSON response bodies using MultiJson
|
30
31
|
builder.adapter Faraday.default_adapter # Set Faraday's HTTP adapter
|
31
32
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module VulnDBHQ
|
2
|
+
module Error
|
3
|
+
|
4
|
+
# Custom error class for rescuing from all VulnDBHQ errors
|
5
|
+
class Base < StandardError
|
6
|
+
|
7
|
+
attr_reader :wrapped_exception
|
8
|
+
|
9
|
+
def self.errors
|
10
|
+
@errors ||= Hash[descendants.map{|klass| [klass.const_get(:HTTP_STATUS_CODE), klass]}]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.descendants
|
14
|
+
ObjectSpace.each_object(::Class).select{|klass| klass < self}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Initializes a new Error object
|
18
|
+
#
|
19
|
+
# @param exception [Exception, String]
|
20
|
+
# @return [VulnDBHQ::Error]
|
21
|
+
def initialize(exception=$!)
|
22
|
+
if exception.respond_to?(:backtrace)
|
23
|
+
super(exception.message)
|
24
|
+
@wrapped_exception = exception
|
25
|
+
else
|
26
|
+
super(exception.to_s)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def backtrace
|
31
|
+
@wrapped_exception ? @wrapped_exception.backtrace : super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module VulnDBHQ
|
2
|
+
module Error
|
3
|
+
# Raised when VulnDBHQ returns a 4xx HTTP status code or there's an error in Faraday
|
4
|
+
class ClientError < Base
|
5
|
+
|
6
|
+
# Create a new error from an HTTP environment
|
7
|
+
#
|
8
|
+
# @param body [Hash]
|
9
|
+
# @return [VulnDBHQ::Error]
|
10
|
+
def self.from_response_body(body)
|
11
|
+
new(parse_error(body))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.parse_error(body)
|
17
|
+
if body.nil?
|
18
|
+
''
|
19
|
+
elsif body[:message]
|
20
|
+
body[:message]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module VulnDBHQ
|
2
|
+
module Response
|
3
|
+
class RaiseClientError < Faraday::Response::Middleware
|
4
|
+
|
5
|
+
def on_complete(env)
|
6
|
+
status_code = env[:status].to_i
|
7
|
+
error_class = VulnDBHQ::Error::ClientError.errors[status_code]
|
8
|
+
raise error_class.from_response_body(env[:body]) if error_class
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/vulndbhq/version.rb
CHANGED
data/lib/vulndbhq.rb
CHANGED
@@ -6,7 +6,11 @@ module VulnDBHQ
|
|
6
6
|
include VulnDBHQ::Configurable
|
7
7
|
|
8
8
|
def client
|
9
|
-
|
9
|
+
if @client && @client.cache_key == options.hash
|
10
|
+
@client
|
11
|
+
else
|
12
|
+
@client = VulnDBHQ::Client.new(options)
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
# Delegate to a VulnDBHQ::Client
|
@@ -14,21 +18,11 @@ module VulnDBHQ
|
|
14
18
|
self.client.respond_to?(method, include_private) || super
|
15
19
|
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
@options
|
23
|
-
end
|
24
|
-
|
25
|
-
def reset!
|
26
|
-
VulnDBHQ::Configurable.keys.each do |key|
|
27
|
-
instance_variable_set("@#{key}", VulnDBHQ::Default.options[key])
|
28
|
-
end
|
29
|
-
self
|
21
|
+
private
|
22
|
+
def method_missing(method, *args, &block)
|
23
|
+
return super unless self.client.respond_to?(method)
|
24
|
+
self.client.send(method, *args, &block)
|
30
25
|
end
|
31
|
-
alias setup reset!
|
32
26
|
|
33
27
|
end
|
34
28
|
end
|
data/spec/faraday_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
describe 'Faraday response' do
|
2
4
|
|
3
5
|
context "for valid object" do
|
@@ -17,9 +19,4 @@ describe 'Faraday response' do
|
|
17
19
|
response.body[:b].should eq('dos')
|
18
20
|
end
|
19
21
|
end
|
20
|
-
|
21
|
-
context "for invalid object" do
|
22
|
-
let(:client) { VulnDBHQ::Client.new }
|
23
|
-
pending "handles 404 responses"
|
24
|
-
end
|
25
22
|
end
|
@@ -9,5 +9,12 @@ describe VulnDBHQ::Client do
|
|
9
9
|
# subject.request(:get, "/path", {}, {})
|
10
10
|
# end.should raise_error(VulnDBHQ::Error::ClientError, "Oups")
|
11
11
|
# end
|
12
|
-
|
12
|
+
pending "catches MultiJson::DecodeError errrors"
|
13
|
+
# it "catches MultiJson::DecodeError errors" do
|
14
|
+
# subject.stub!(:connection).and_raise(MultiJson::DecodeError.new("unexpected token", [], "<!DOCTYPE html>"))
|
15
|
+
# lambda do
|
16
|
+
# subject.request(:get, "/path")
|
17
|
+
# end.should raise_error(Twitter::Error::DecodeError, "unexpected token")
|
18
|
+
# end
|
19
|
+
pending "raises an exception if no host endpoint has been provided"
|
13
20
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VulnDBHQ::Error::ClientError do
|
4
|
+
before do
|
5
|
+
@client = VulnDBHQ::Client.new(:host => TEST_ENDPOINT)
|
6
|
+
end
|
7
|
+
|
8
|
+
VulnDBHQ::Error::ClientError.errors.each do |status, exception|
|
9
|
+
context "when HTTP status is #{status}" do
|
10
|
+
before do
|
11
|
+
body_message = '{"message":"Client Error"}'
|
12
|
+
stub_get("/api/private_pages/1").
|
13
|
+
to_return(:status => status, :body => body_message)
|
14
|
+
end
|
15
|
+
it "raises #{exception.name}" do
|
16
|
+
lambda do
|
17
|
+
@client.private_page(1)
|
18
|
+
end.should raise_error(exception)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -7,8 +7,7 @@ describe VulnDBHQ::PrivatePage do
|
|
7
7
|
to_return(:status => 200,
|
8
8
|
:body => "{\"content\":\"#[Title]#\\r\\nThis is my Private Page\\r\\n\\r\\n\",\"id\":1,\"name\":\"MyPrivatePage\"}",
|
9
9
|
:headers => {'Content-Type' => 'application/json; charset=utf-8'})
|
10
|
-
client = VulnDBHQ::
|
11
|
-
client.host = TEST_ENDPOINT
|
10
|
+
client = VulnDBHQ::Client.new(:host => TEST_ENDPOINT)
|
12
11
|
|
13
12
|
private_page = client.private_page(1)
|
14
13
|
private_page.should be
|
@@ -17,4 +16,17 @@ describe VulnDBHQ::PrivatePage do
|
|
17
16
|
private_page.content.should eq("#[Title]#\r\nThis is my Private Page\r\n\r\n")
|
18
17
|
end
|
19
18
|
|
19
|
+
it "loads a collection of PrivatePages" do
|
20
|
+
stub_get('/api/private_pages').
|
21
|
+
to_return(:status => 200,
|
22
|
+
:body => "[{\"content\":\"#[Title]#\\r\\nThis is my Private Page\\r\\n\\r\\n\",\"id\":1,\"name\":\"MyPrivatePage1\"}," +
|
23
|
+
"{\"content\":\"#[Title]#\\r\\nThis is another Private Page\\r\\n\\r\\n\",\"id\":2,\"name\":\"MyPrivatePage2\"}]",
|
24
|
+
:headers => {'Content-Type' => 'application/json; charset=utf-8'})
|
25
|
+
client = VulnDBHQ::Client.new(:host => TEST_ENDPOINT)
|
26
|
+
|
27
|
+
collection = client.private_pages
|
28
|
+
collection.should be
|
29
|
+
collection.length.should eq(2)
|
30
|
+
collection.last.name.should eq('MyPrivatePage2')
|
31
|
+
end
|
20
32
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VulnDBHQ::PublicPage do
|
4
|
+
|
5
|
+
it "loads :name and :content from the server's JSON body" do
|
6
|
+
stub_get('/api/public_pages/1').
|
7
|
+
to_return(:status => 200,
|
8
|
+
:body => "{\"content\":\"#[Title]#\\r\\nThis is my Public Page\\r\\n\\r\\n\",\"id\":1,\"name\":\"MyPublicPage\"}",
|
9
|
+
:headers => {'Content-Type' => 'application/json; charset=utf-8'})
|
10
|
+
client = VulnDBHQ::Client.new(:host => TEST_ENDPOINT)
|
11
|
+
|
12
|
+
public_page = client.public_page(1)
|
13
|
+
public_page.should be
|
14
|
+
public_page.should be_a(VulnDBHQ::PublicPage)
|
15
|
+
public_page.name.should eq('MyPublicPage')
|
16
|
+
public_page.content.should eq("#[Title]#\r\nThis is my Public Page\r\n\r\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "loads a collection of PublicPages" do
|
20
|
+
stub_get('/api/public_pages').
|
21
|
+
to_return(:status => 200,
|
22
|
+
:body => "[{\"content\":\"#[Title]#\\r\\nThis is my Public Page\\r\\n\\r\\n\",\"id\":1,\"name\":\"MyPublicPage1\"}," +
|
23
|
+
"{\"content\":\"#[Title]#\\r\\nThis is another Public Page\\r\\n\\r\\n\",\"id\":2,\"name\":\"MyPublicPage2\"}]",
|
24
|
+
:headers => {'Content-Type' => 'application/json; charset=utf-8'})
|
25
|
+
client = VulnDBHQ::Client.new(:host => TEST_ENDPOINT)
|
26
|
+
|
27
|
+
collection = client.public_pages
|
28
|
+
collection.should be
|
29
|
+
collection.length.should eq(2)
|
30
|
+
collection.last.name.should eq('MyPublicPage2')
|
31
|
+
end
|
32
|
+
end
|
data/spec/vulndbhq_spec.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe VulnDBHQ do
|
4
|
+
after do
|
5
|
+
VulnDBHQ.reset!
|
6
|
+
end
|
4
7
|
|
5
8
|
describe '.respond_to?' do
|
6
9
|
it "delegates to VulnDBHQ::Client" do
|
@@ -15,6 +18,21 @@ describe VulnDBHQ do
|
|
15
18
|
it "returns a VulnDBHQ::Client" do
|
16
19
|
VulnDBHQ.client.should be_a VulnDBHQ::Client
|
17
20
|
end
|
21
|
+
context "when the options don't change" do
|
22
|
+
it "caches the client" do
|
23
|
+
VulnDBHQ.client.should eq VulnDBHQ.client
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context "when the options change" do
|
27
|
+
it "busts the cache" do
|
28
|
+
client1 = VulnDBHQ.client
|
29
|
+
VulnDBHQ.configure do |config|
|
30
|
+
config.host = TEST_ENDPOINT
|
31
|
+
end
|
32
|
+
client2 = VulnDBHQ.client
|
33
|
+
client1.should_not eq client2
|
34
|
+
end
|
35
|
+
end
|
18
36
|
end
|
19
37
|
|
20
38
|
describe ".configure" do
|
@@ -23,7 +41,7 @@ describe VulnDBHQ do
|
|
23
41
|
VulnDBHQ.configure do |config|
|
24
42
|
config.send("#{key}=", key)
|
25
43
|
end
|
26
|
-
VulnDBHQ.instance_variable_get("@#{key}").should eq key
|
44
|
+
VulnDBHQ.instance_variable_get(:"@#{key}").should eq key
|
27
45
|
end
|
28
46
|
end
|
29
47
|
end
|
data/vulndbhq.gemspec
CHANGED
@@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ['lib']
|
16
16
|
gem.version = VulnDBHQ::Version
|
17
17
|
|
18
|
+
# gem.add_runtime_dependency 'faraday', '~> 0.8'
|
19
|
+
# see https://github.com/technoweenie/faraday/commit/b0d9a144596e96861a18d68f2418b7d74e7b791d
|
18
20
|
gem.add_runtime_dependency 'faraday', '~> 0.8'
|
19
21
|
gem.add_runtime_dependency 'multi_json', '~> 1.3'
|
20
22
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vulndbhq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel Martin
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -110,16 +110,26 @@ files:
|
|
110
110
|
- lib/vulndbhq/client.rb
|
111
111
|
- lib/vulndbhq/configurable.rb
|
112
112
|
- lib/vulndbhq/default.rb
|
113
|
+
- lib/vulndbhq/error.rb
|
114
|
+
- lib/vulndbhq/error/base.rb
|
115
|
+
- lib/vulndbhq/error/client_error.rb
|
116
|
+
- lib/vulndbhq/error/failed_dependency.rb
|
117
|
+
- lib/vulndbhq/error/not_found.rb
|
118
|
+
- lib/vulndbhq/error/unauthorized.rb
|
113
119
|
- lib/vulndbhq/identity_map.rb
|
114
120
|
- lib/vulndbhq/private_page.rb
|
121
|
+
- lib/vulndbhq/public_page.rb
|
115
122
|
- lib/vulndbhq/response/parse_json.rb
|
123
|
+
- lib/vulndbhq/response/raise_client_error.rb
|
116
124
|
- lib/vulndbhq/version.rb
|
117
125
|
- spec/faraday_spec.rb
|
118
126
|
- spec/spec_helper.rb
|
119
127
|
- spec/support/webmock.rb
|
120
128
|
- spec/vulndbhq/base_spec.rb
|
121
129
|
- spec/vulndbhq/client_spec.rb
|
130
|
+
- spec/vulndbhq/error/client_error_spec.rb
|
122
131
|
- spec/vulndbhq/private_page_spec.rb
|
132
|
+
- spec/vulndbhq/public_page_spec.rb
|
123
133
|
- spec/vulndbhq_spec.rb
|
124
134
|
- vulndbhq.gemspec
|
125
135
|
homepage: http://vulndbhq.com
|
@@ -136,13 +146,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
146
|
version: '0'
|
137
147
|
segments:
|
138
148
|
- 0
|
139
|
-
hash: -
|
149
|
+
hash: -1225293818451848289
|
140
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
151
|
none: false
|
142
152
|
requirements:
|
143
|
-
- - ! '
|
153
|
+
- - ! '>='
|
144
154
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
155
|
+
version: '0'
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
hash: -1225293818451848289
|
146
159
|
requirements: []
|
147
160
|
rubyforge_project:
|
148
161
|
rubygems_version: 1.8.24
|
@@ -155,5 +168,7 @@ test_files:
|
|
155
168
|
- spec/support/webmock.rb
|
156
169
|
- spec/vulndbhq/base_spec.rb
|
157
170
|
- spec/vulndbhq/client_spec.rb
|
171
|
+
- spec/vulndbhq/error/client_error_spec.rb
|
158
172
|
- spec/vulndbhq/private_page_spec.rb
|
173
|
+
- spec/vulndbhq/public_page_spec.rb
|
159
174
|
- spec/vulndbhq_spec.rb
|