digicert 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/Gemfile +1 -1
  4. data/README.md +31 -0
  5. data/bin/rspec +3 -2
  6. data/lib/digicert.rb +3 -0
  7. data/lib/digicert/actions/all.rb +7 -3
  8. data/lib/digicert/actions/create.rb +1 -1
  9. data/lib/digicert/actions/fetch.rb +1 -1
  10. data/lib/digicert/actions/update.rb +1 -1
  11. data/lib/digicert/certificate.rb +1 -1
  12. data/lib/digicert/client_certificate/premium.rb +1 -1
  13. data/lib/digicert/csr_generator.rb +1 -1
  14. data/lib/digicert/domain.rb +3 -3
  15. data/lib/digicert/email_validation.rb +1 -1
  16. data/lib/digicert/errors.rb +1 -1
  17. data/lib/digicert/errors/request_error.rb +3 -2
  18. data/lib/digicert/order_cancellation.rb +1 -1
  19. data/lib/digicert/order_manager.rb +1 -1
  20. data/lib/digicert/organization.rb +1 -1
  21. data/lib/digicert/request.rb +5 -3
  22. data/lib/digicert/response.rb +2 -2
  23. data/lib/digicert/rspec.rb +21 -0
  24. data/lib/digicert/ssl_certificate/base.rb +0 -1
  25. data/lib/digicert/util.rb +34 -0
  26. data/lib/digicert/version.rb +1 -1
  27. data/spec/acceptance/duplicating_certificate_spec.rb +1 -1
  28. data/spec/acceptance/reissuing_certificate_spec.rb +2 -2
  29. data/spec/digicert/actions/all_spec.rb +33 -5
  30. data/spec/digicert/actions/update_spec.rb +2 -2
  31. data/spec/digicert/certificate_downloader_spec.rb +4 -4
  32. data/spec/digicert/certificate_request_spec.rb +2 -2
  33. data/spec/digicert/certificate_spec.rb +1 -1
  34. data/spec/digicert/client_certificate/digital_signature_plus_spec.rb +1 -1
  35. data/spec/digicert/client_certificate/email_security_plus_spec.rb +1 -1
  36. data/spec/digicert/client_certificate/premium_spec.rb +1 -1
  37. data/spec/digicert/domain_spec.rb +2 -2
  38. data/spec/digicert/order_duplicator_spec.rb +1 -1
  39. data/spec/digicert/order_reissuer_spec.rb +1 -1
  40. data/spec/digicert/order_spec.rb +24 -10
  41. data/spec/digicert/request_spec.rb +1 -1
  42. data/spec/digicert/util_spec.rb +26 -0
  43. data/spec/requests/certificate_reissuing_spec.rb +0 -1
  44. data/spec/requests/domain_management_spec.rb +1 -1
  45. data/spec/requests/order_client_email_security_plus_spec.rb +1 -1
  46. data/spec/requests/order_client_premium_certificate_spec.rb +65 -0
  47. data/spec/requests/order_ssl_ev_plus_spec.rb +2 -2
  48. data/spec/requests/order_ssl_wildcard_spec.rb +1 -1
  49. data/spec/spec_helper.rb +2 -2
  50. data/spec/support/fake_digicert_api.rb +22 -16
  51. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55bfc7916ddf2ce78f11cbbe178e6b7e0417778d
4
- data.tar.gz: ae7b474592b1f669afe8df47cb58dd04ee61af8d
3
+ metadata.gz: fdf876cef7eea96750f7678894027221b448f2e6
4
+ data.tar.gz: fcb2979e844e56a22617647f85d50364d2038b0c
5
5
  SHA512:
6
- metadata.gz: 5adb81424d8b251143a7aef3711837044ae8aa51257fed7e16b4e4794676aa88ea1bd0a9cd598e80671883d057453da401519928b20744a5014371d2f71d7851
7
- data.tar.gz: 4c4d35432a65cd9e0fbc862a4dd3b9df6541927fa78b3f5cdf77593b776d887aabca4d2bf1ada3729dd2dabec7dfadb702dbecf281ea3c663e76c889f7aff6db
6
+ metadata.gz: dfc0e06614d1e50fe1379855abe21f099574c4af48878c9ea109f5a5ad4b61c4b72fe3f7897c30279683160afcacdb72c7cd6f7daf73d3d25ae86a027bfa7d0d
7
+ data.tar.gz: c97dc961f495a41aa270e02bcf4cedeedc7cc95071ec5e1a4d6a9230d099fe5fcad3572e8b043bc3f16fb931551df9118703509f01498cef676f2d139953095e
data/.rubocop.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.3
3
+
2
4
  Exclude:
3
5
  - db/schema.rb
4
6
 
@@ -351,6 +353,9 @@ Style/StringLiterals:
351
353
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals'
352
354
  EnforcedStyle: double_quotes
353
355
  Enabled: true
356
+ SupportedStyles:
357
+ - single_quotes
358
+ - double_quotes
354
359
 
355
360
  Style/FrozenStringLiteralComment:
356
361
  Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in digicert.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
  Status](https://travis-ci.org/riboseinc/digicert.svg?branch=master)](https://travis-ci.org/riboseinc/digicert)
5
5
  [![Code
6
6
  Climate](https://codeclimate.com/github/riboseinc/digicert/badges/gpa.svg)](https://codeclimate.com/github/riboseinc/digicert)
7
+ [![Gem
8
+ Version](https://badge.fury.io/rb/digicert.svg)](https://badge.fury.io/rb/digicert)
7
9
 
8
10
  The Ruby client for the official Digicert API.
9
11
 
@@ -515,6 +517,35 @@ Use this interface to retrieve a list of all certificate orders.
515
517
  Digicert::Order.all
516
518
  ```
517
519
 
520
+ This interface also supports query params like `limit`, `offset`, `sort` and
521
+ filters. We can use those to retrieve more precised orders.
522
+
523
+ ```ruby
524
+ Digicert::Order.all(
525
+ limit: 20,
526
+ offset: 0,
527
+ sort: 'date_created',
528
+
529
+ filters: {
530
+ status: "approved",
531
+ common_name: "ribosetest.com"
532
+ }
533
+ )
534
+ ```
535
+
536
+ There is also another interface `.filter`, which is basically an alias around
537
+ the `.all` interface but it passes each of the argument as a filters attributes
538
+
539
+ ```ruby
540
+ Digicert::Order.filter(status: "approved", common_name: "ribosetest.com")
541
+
542
+ # Similar functionality with all interface
543
+ #
544
+ Digicert::Order.all(
545
+ filters: { status: "approved", common_name: "ribosetest.com" }
546
+ )
547
+ ```
548
+
518
549
  #### List of Email Validations
519
550
 
520
551
  Use this interface to view the status of all emails that require validation on a
data/bin/rspec CHANGED
@@ -8,8 +8,9 @@
8
8
  #
9
9
 
10
10
  require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
12
+ "../../Gemfile", Pathname.new(__FILE__).realpath
13
+ )
13
14
 
14
15
  require "rubygems"
15
16
  require "bundler/setup"
data/lib/digicert.rb CHANGED
@@ -40,4 +40,7 @@ require "digicert/duplicate_certificate_finder"
40
40
  require "digicert/certificate"
41
41
 
42
42
  module Digicert
43
+ def self.root
44
+ File.dirname(__dir__)
45
+ end
43
46
  end
@@ -7,7 +7,7 @@ module Digicert
7
7
 
8
8
  def all
9
9
  response = Digicert::Request.new(
10
- :get, resource_path, params: query_params,
10
+ :get, resource_path, params: query_params
11
11
  ).parse
12
12
 
13
13
  response[resources_key]
@@ -18,8 +18,12 @@ module Digicert
18
18
  end
19
19
 
20
20
  module ClassMethods
21
- def all(filter_params = {})
22
- new(params: filter_params).all
21
+ def all(query_params = {})
22
+ new(params: query_params).all
23
+ end
24
+
25
+ def filter(filter_params = {})
26
+ new(params: { filters: filter_params }).all
23
27
  end
24
28
  end
25
29
  end
@@ -7,7 +7,7 @@ module Digicert
7
7
 
8
8
  def create
9
9
  Digicert::Request.new(
10
- :post, resource_creation_path, validate(attributes),
10
+ :post, resource_creation_path, validate(attributes)
11
11
  ).parse
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ module Digicert
7
7
 
8
8
  def fetch
9
9
  Digicert::Request.new(
10
- :get, [resource_path, resource_id].join("/"), params: query_params,
10
+ :get, [resource_path, resource_id].join("/"), params: query_params
11
11
  ).parse
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ module Digicert
7
7
 
8
8
  def update
9
9
  Digicert::Request.new(
10
- :put, resource_update_path, attributes,
10
+ :put, resource_update_path, attributes
11
11
  ).run
12
12
  end
13
13
 
@@ -22,7 +22,7 @@ module Digicert
22
22
 
23
23
  def download_to_path(path:, ext: "zip", **attributes)
24
24
  certificate_downloader.fetch_to_path(
25
- resource_id, attributes.merge(path: path, ext: ext),
25
+ resource_id, attributes.merge(path: path, ext: ext)
26
26
  )
27
27
  end
28
28
 
@@ -6,7 +6,7 @@ module Digicert
6
6
  private
7
7
 
8
8
  def certificate_type
9
- "client_premium_sha2"
9
+ "client_premium"
10
10
  end
11
11
 
12
12
  def validate_certificate(csr:, **attributes)
@@ -27,7 +27,7 @@ module Digicert
27
27
 
28
28
  def r509_attributes_hash
29
29
  { key: rsa_key, subject: subject_items, san_names: san_names }.
30
- reject { |key, value| value.nil? || value.empty? }
30
+ reject { |_key, value| value.nil? || value.empty? }
31
31
  end
32
32
 
33
33
  def subject_items
@@ -11,13 +11,13 @@ module Digicert
11
11
 
12
12
  def activate
13
13
  request_klass.new(
14
- :put, [resource_path, resource_id, "activate"].join("/"),
14
+ :put, [resource_path, resource_id, "activate"].join("/")
15
15
  ).parse
16
16
  end
17
17
 
18
18
  def deactivate
19
19
  request_klass.new(
20
- :put, [resource_path, resource_id, "deactivate"].join("/"),
20
+ :put, [resource_path, resource_id, "deactivate"].join("/")
21
21
  ).parse
22
22
  end
23
23
 
@@ -50,7 +50,7 @@ module Digicert
50
50
  required_attributes = {
51
51
  name: name,
52
52
  organization: organization,
53
- validations: validate_validations(validations)
53
+ validations: validate_validations(validations),
54
54
  }
55
55
 
56
56
  required_attributes.merge(attributes)
@@ -10,7 +10,7 @@ module Digicert
10
10
 
11
11
  def self.valid?(token:, email:)
12
12
  response = Digicert::Request.new(
13
- :put, ["email-validation", token].join("/"), params: {email: email }
13
+ :put, ["email-validation", token].join("/"), params: { email: email }
14
14
  ).run
15
15
 
16
16
  response.code.to_i == 204
@@ -14,7 +14,7 @@ module Digicert
14
14
  Errno::ECONNRESET,
15
15
  Net::OpenTimeout,
16
16
  SocketError,
17
- Net::HTTPServerError
17
+ Net::HTTPServerError,
18
18
  ]
19
19
  end
20
20
 
@@ -9,7 +9,7 @@ module Digicert
9
9
  end
10
10
 
11
11
  def message
12
- <<-MSG.gsub(/^ {8}/, '')
12
+ <<-MSG.gsub(/^ {8}/, "")
13
13
  #{explanation}:
14
14
  #{response_body}
15
15
  MSG
@@ -28,7 +28,8 @@ module Digicert
28
28
  attr_reader :msg
29
29
 
30
30
  def response_body
31
- JSON[msg] rescue {}
31
+ JSON[msg]
32
+ rescue {}
32
33
  end
33
34
  end
34
35
  end
@@ -4,7 +4,7 @@ module Digicert
4
4
  class OrderCancellation < Digicert::Base
5
5
  def create
6
6
  request_klass.new(
7
- :put, resource_path, default_attributes.merge(attributes),
7
+ :put, resource_path, default_attributes.merge(attributes)
8
8
  ).run
9
9
  end
10
10
 
@@ -22,7 +22,7 @@ module Digicert
22
22
  csr: order.certificate.csr,
23
23
  signature_hash: order.certificate.signature_hash,
24
24
  server_platform: { id: order.certificate.server_platform.id },
25
- }
25
+ },
26
26
  }
27
27
  end
28
28
 
@@ -34,7 +34,7 @@ module Digicert
34
34
  first_name: first_name,
35
35
  last_name: last_name,
36
36
  email: email,
37
- telephone: telephone
37
+ telephone: telephone,
38
38
  }
39
39
 
40
40
  required_attributes.merge(attrs)
@@ -1,6 +1,8 @@
1
1
  require "uri"
2
2
  require "json"
3
3
  require "net/http"
4
+
5
+ require "digicert/util"
4
6
  require "digicert/response"
5
7
  require "digicert/errors"
6
8
 
@@ -65,7 +67,7 @@ module Digicert
65
67
  URI::HTTPS.build(
66
68
  host: Digicert.configuration.api_host,
67
69
  path: digicert_api_path_with_base,
68
- query: build_query_params
70
+ query: build_query_params,
69
71
  )
70
72
  end
71
73
 
@@ -82,13 +84,13 @@ module Digicert
82
84
  def set_request_headers!(request)
83
85
  request.initialize_http_header(
84
86
  "Content-Type" => "application/json",
85
- "X-DC-DEVKEY" => Digicert.configuration.api_key
87
+ "X-DC-DEVKEY" => Digicert.configuration.api_key,
86
88
  )
87
89
  end
88
90
 
89
91
  def build_query_params
90
92
  if @query_params
91
- URI.encode_www_form(@query_params)
93
+ Digicert::Util.to_query(@query_params)
92
94
  end
93
95
  end
94
96
 
@@ -1,5 +1,5 @@
1
1
  require "json"
2
- require 'ostruct'
2
+ require "ostruct"
3
3
 
4
4
  module Digicert
5
5
  class Response
@@ -26,5 +26,5 @@ module Digicert
26
26
  end
27
27
  end
28
28
 
29
- class ResponseObject < OpenStruct;end
29
+ class ResponseObject < OpenStruct; end
30
30
  end
@@ -0,0 +1,21 @@
1
+ # Test Helpers for RSpec
2
+ #
3
+ # Actual API requests are slow and expensive and we try not to make actual
4
+ # API request when possible. For most of our tests we mock the API call which
5
+ # verifies the endpoint, http verb and headers and based on those it responses
6
+ # with an identical fixture file.
7
+ #
8
+ # The main purpose of this file is to allow you to use our test helpers by
9
+ # simplify adding this file to your application and then use the available
10
+ # helper method when necessary.
11
+ #
12
+ # Please check `spec/support` directory to see the available helper methods.
13
+ #
14
+ # We do not include this module with the gem by default, but you can do so
15
+ # by adding `require "digicert/rspec"` on top of your `spec_helpe` file.
16
+ #
17
+ require File.join(Digicert.root, "spec/support/fake_digicert_api.rb")
18
+
19
+ RSpec.configure do |config|
20
+ config.include Digicert::FakeDigicertApi
21
+ end
@@ -3,7 +3,6 @@ require "digicert/base_order"
3
3
  module Digicert
4
4
  module SSLCertificate
5
5
  class Base < Digicert::BaseOrder
6
-
7
6
  end
8
7
  end
9
8
  end
@@ -0,0 +1,34 @@
1
+ require "cgi"
2
+
3
+ module Digicert
4
+ class Util
5
+ def to_query(query)
6
+ build_query(query).flatten.join("&")
7
+ end
8
+
9
+ def self.to_query(query)
10
+ new.to_query(query)
11
+ end
12
+
13
+ private
14
+
15
+ def build_query(value, key = nil)
16
+ if value.is_a?(Hash)
17
+ build_recursive_query(value, key)
18
+ else
19
+ build_escaped_key_value_pair(key, value)
20
+ end
21
+ end
22
+
23
+ def build_recursive_query(query, namespace = nil)
24
+ query.map do |key, value|
25
+ query_key = namespace ? "#{namespace}[#{key}]" : key
26
+ build_query(value, query_key)
27
+ end
28
+ end
29
+
30
+ def build_escaped_key_value_pair(key, value)
31
+ [CGI.escape(key.to_s), CGI.escape(value.to_s)].join("=")
32
+ end
33
+ end
34
+ end
@@ -21,5 +21,5 @@
21
21
  # ++
22
22
 
23
23
  module Digicert
24
- VERSION = "0.1.1".freeze
24
+ VERSION = "0.1.2".freeze
25
25
  end
@@ -73,7 +73,7 @@ RSpec.describe "Certificate Order Duplication" do
73
73
  csr: order.certificate.csr,
74
74
  signature_hash: order.certificate.signature_hash,
75
75
  server_platform: { id: order.certificate.server_platform.id },
76
- }
76
+ },
77
77
  }
78
78
  end
79
79
 
@@ -32,7 +32,7 @@ RSpec.describe "Re-issuing a certificate" do
32
32
  #
33
33
  if request.status == "pending"
34
34
  stub_digicert_certificate_request_update_api(
35
- request_id, request_status_attributes,
35
+ request_id, request_status_attributes
36
36
  )
37
37
 
38
38
  Digicert::CertificateRequest.update(request_id, request_status_attributes)
@@ -84,7 +84,7 @@ RSpec.describe "Re-issuing a certificate" do
84
84
  csr: order.certificate.csr,
85
85
  signature_hash: order.certificate.signature_hash,
86
86
  server_platform: { id: order.certificate.server_platform.id },
87
- }
87
+ },
88
88
  }
89
89
  end
90
90
 
@@ -3,12 +3,40 @@ require "digicert/base"
3
3
 
4
4
  RSpec.describe "Digicert::Actions::ALL" do
5
5
  describe ".all" do
6
- it "retrieves the list of resources" do
7
- stub_digicert_organization_list_api
8
- organizations = Digicert::TestAllAction.all
6
+ context "with out query param" do
7
+ it "retrieves the list of resources" do
8
+ stub_digicert_organization_list_api
9
+ organizations = Digicert::TestAllAction.all
9
10
 
10
- expect(organizations.count).to eq(2)
11
- expect(organizations.first.name).not_to be_nil
11
+ expect(organizations.count).to eq(2)
12
+ expect(organizations.first.name).not_to be_nil
13
+ end
14
+ end
15
+
16
+ context "with specificed query params" do
17
+ it "pass the params and retrieve the list of resources" do
18
+ query_params = { limit: 2, offset: 0, sort: "date_created" }
19
+
20
+ stub_digicert_organization_list_api(query_params)
21
+ organizations = Digicert::TestAllAction.all(query_params)
22
+
23
+ expect(organizations.count).to eq(2)
24
+ expect(organizations.first.name).not_to be_nil
25
+ end
26
+ end
27
+ end
28
+
29
+ describe ".filter" do
30
+ context "with filters params" do
31
+ it "retrieves the filterered resources" do
32
+ filters = { status: "approved" }
33
+ stub_digicert_organization_list_api(filters: filters)
34
+
35
+ organizations = Digicert::TestAllAction.filter(filters)
36
+
37
+ expect(organizations.count).to eq(2)
38
+ expect(organizations.first.name).not_to be_nil
39
+ end
12
40
  end
13
41
  end
14
42
 
@@ -7,11 +7,11 @@ RSpec.describe "Digicert::Actions::Update" do
7
7
  it "updates the resource attributes" do
8
8
  resource_id = 123_456_789
9
9
  stub_digicert_certificate_request_update_api(
10
- resource_id, certificate_status_attributes,
10
+ resource_id, certificate_status_attributes
11
11
  )
12
12
 
13
13
  resource = Digicert::TestUpdateAction.update(
14
- resource_id, certificate_status_attributes,
14
+ resource_id, certificate_status_attributes
15
15
  )
16
16
 
17
17
  expect(resource.code.to_i).to eq(204)
@@ -8,7 +8,7 @@ RSpec.describe Digicert::CertificateDownloader do
8
8
  stub_digicert_certificate_download_by_platform(certificate_id, platform)
9
9
 
10
10
  certificate = Digicert::CertificateDownloader.fetch(
11
- certificate_id, platform: platform,
11
+ certificate_id, platform: platform
12
12
  )
13
13
 
14
14
  expect(certificate.code.to_i).to eq(200)
@@ -24,7 +24,7 @@ RSpec.describe Digicert::CertificateDownloader do
24
24
 
25
25
  stub_digicert_certificate_download_by_platform(certificate_id)
26
26
  Digicert::CertificateDownloader.fetch_to_path(
27
- certificate_id, path: download_path, ext: "zip",
27
+ certificate_id, path: download_path, ext: "zip"
28
28
  )
29
29
 
30
30
  download_url = [download_path, "certificate.zip"].join("/")
@@ -39,7 +39,7 @@ RSpec.describe Digicert::CertificateDownloader do
39
39
 
40
40
  stub_digicert_certificate_download_by_platform(certificate_id, platform)
41
41
  certificate = Digicert::CertificateDownloader.fetch_by_platform(
42
- certificate_id, platform: platform,
42
+ certificate_id, platform: platform
43
43
  )
44
44
 
45
45
  expect(certificate.code.to_i).to eq(200)
@@ -54,7 +54,7 @@ RSpec.describe Digicert::CertificateDownloader do
54
54
 
55
55
  stub_digicert_certificate_download_by_format(certificate_id, format)
56
56
  certificate = Digicert::CertificateDownloader.fetch_by_format(
57
- certificate_id, format: format,
57
+ certificate_id, format: format
58
58
  )
59
59
 
60
60
  expect(certificate.code.to_i).to eq(200)
@@ -29,11 +29,11 @@ RSpec.describe Digicert::CertificateRequest do
29
29
  it "updates the specified ceritfiicate request status" do
30
30
  request_id = 123_456_789
31
31
  stub_digicert_certificate_request_update_api(
32
- request_id, request_status_attributes,
32
+ request_id, request_status_attributes
33
33
  )
34
34
 
35
35
  status_update = Digicert::CertificateRequest.update(
36
- request_id, request_status_attributes,
36
+ request_id, request_status_attributes
37
37
  )
38
38
 
39
39
  expect(status_update.code).to eq("204")
@@ -82,7 +82,7 @@ RSpec.describe Digicert::Certificate do
82
82
  stub_digicert_certificate_revoke_api(certificate_id, comments: comments)
83
83
 
84
84
  revocation = Digicert::Certificate.revoke(
85
- certificate_id, comments: comments,
85
+ certificate_id, comments: comments
86
86
  )
87
87
 
88
88
  expect(revocation.id).not_to be_nil
@@ -4,7 +4,7 @@ RSpec.describe Digicert::ClientCertificate::DigitalSignaturePlus do
4
4
  describe ".create" do
5
5
  it "creates a new order for a digital signature plus certificate" do
6
6
  stub_digicert_order_create_api(
7
- "client_digital_signature_plus", order_attributes,
7
+ "client_digital_signature_plus", order_attributes
8
8
  )
9
9
 
10
10
  order = Digicert::ClientCertificate::DigitalSignaturePlus.create(
@@ -4,7 +4,7 @@ RSpec.describe Digicert::ClientCertificate::EmailSecurityPlus do
4
4
  describe ".create" do
5
5
  it "creates a new order for a email security plus certificate" do
6
6
  stub_digicert_order_create_api(
7
- "client_email_security_plus", order_attributes,
7
+ "client_email_security_plus", order_attributes
8
8
  )
9
9
 
10
10
  order = Digicert::ClientCertificate::EmailSecurityPlus.create(
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  RSpec.describe Digicert::ClientCertificate::Premium do
4
4
  describe ".create" do
5
5
  it "creates a new order for a client premium certificate" do
6
- stub_digicert_order_create_api("client_premium_sha2", order_attributes)
6
+ stub_digicert_order_create_api("client_premium", order_attributes)
7
7
  order = Digicert::ClientCertificate::Premium.create(order_attributes)
8
8
 
9
9
  expect(order.id).not_to be_nil
@@ -38,7 +38,7 @@ RSpec.describe Digicert::Domain do
38
38
  describe ".fetch" do
39
39
  it "retrieves the specific domain" do
40
40
  domain_id = 123_456_789
41
- filters = { include_dcv: true, include_validation: true}
41
+ filters = { include_dcv: true, include_validation: true }
42
42
 
43
43
  stub_digicert_domain_fetch_api(domain_id, filters)
44
44
  domain = Digicert::Domain.fetch(domain_id, filters)
@@ -80,7 +80,7 @@ RSpec.describe Digicert::Domain do
80
80
  validations: [
81
81
  {
82
82
  type: "ev",
83
- user: { id: 12 }
83
+ user: { id: 12 },
84
84
  },
85
85
  ],
86
86
  dcv: { method: "email" },
@@ -25,7 +25,7 @@ RSpec.describe Digicert::OrderDuplicator do
25
25
  csr: order.certificate.csr,
26
26
  signature_hash: order.certificate.signature_hash,
27
27
  server_platform: { id: order.certificate.server_platform.id },
28
- }
28
+ },
29
29
  }
30
30
  end
31
31
 
@@ -29,7 +29,7 @@ RSpec.describe Digicert::OrderReissuer do
29
29
  csr: order.certificate.csr,
30
30
  signature_hash: order.certificate.signature_hash,
31
31
  server_platform: { id: order.certificate.server_platform.id },
32
- }
32
+ },
33
33
  }
34
34
  end
35
35
  end
@@ -15,13 +15,27 @@ RSpec.describe Digicert::Order do
15
15
  end
16
16
 
17
17
  describe ".all" do
18
- it "retrieves the list of all certificate orders" do
19
- stub_digicert_order_list_api
20
- orders = Digicert::Order.all
18
+ context "without any query params" do
19
+ it "retrieves the list of all certificate orders" do
20
+ stub_digicert_order_list_api
21
+ orders = Digicert::Order.all
22
+
23
+ expect(orders.first.id).not_to be_nil
24
+ expect(orders.first.status).to eq("issued")
25
+ expect(orders.first.certificate.common_name).to eq("digicert.com")
26
+ end
27
+ end
28
+
29
+ context "with specified query params" do
30
+ it "retrieves the filtered list of certificate orders" do
31
+ query_params = { limit: 3, offset: 0, sort: "date_created" }
32
+ stub_digicert_order_list_api(query_params)
33
+
34
+ orders = Digicert::Order.all(query_params)
21
35
 
22
- expect(orders.first.id).not_to be_nil
23
- expect(orders.first.status).to eq("issued")
24
- expect(orders.first.certificate.common_name).to eq("digicert.com")
36
+ expect(orders.count).to eq(query_params[:limit])
37
+ expect(orders.first.certificate.common_name).to eq("digicert.com")
38
+ end
25
39
  end
26
40
  end
27
41
 
@@ -61,7 +75,7 @@ RSpec.describe Digicert::Order do
61
75
  order.reissue
62
76
 
63
77
  expect(
64
- Digicert::OrderReissuer
78
+ Digicert::OrderReissuer,
65
79
  ).to have_received(:create).with(order_id: order_id)
66
80
  end
67
81
  end
@@ -75,7 +89,7 @@ RSpec.describe Digicert::Order do
75
89
  order.duplicate
76
90
 
77
91
  expect(
78
- Digicert::OrderDuplicator
92
+ Digicert::OrderDuplicator,
79
93
  ).to have_received(:create).with(order_id: order_id)
80
94
  end
81
95
  end
@@ -89,7 +103,7 @@ RSpec.describe Digicert::Order do
89
103
  order.duplicate_certificates
90
104
 
91
105
  expect(
92
- Digicert::DuplicateCertificate
106
+ Digicert::DuplicateCertificate,
93
107
  ).to have_received(:all).with(order_id: order_id)
94
108
  end
95
109
  end
@@ -105,7 +119,7 @@ RSpec.describe Digicert::Order do
105
119
  order.cancel(note: note)
106
120
 
107
121
  expect(
108
- Digicert::OrderCancellation
122
+ Digicert::OrderCancellation,
109
123
  ).to have_received(:create).with(order_id: order_id, note: note)
110
124
  end
111
125
  end
@@ -18,7 +18,7 @@ RSpec.describe Digicert::Request do
18
18
  stub_invalid_ping_request_via_get
19
19
  request = Digicert::Request.new(:get, "ping")
20
20
 
21
- expect{ request.run }.to raise_error(/not_found\|route/)
21
+ expect { request.run }.to raise_error(/not_found\|route/)
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,26 @@
1
+ require "cgi"
2
+ require "spec_helper"
3
+
4
+ RSpec.describe Digicert::Util do
5
+ describe ".to_query" do
6
+ context "plain hash with key and value" do
7
+ it "builds and returns the queryable params" do
8
+ params = { limit: 10, sort: "date_created" }
9
+ query_params = Digicert::Util.to_query(params)
10
+
11
+ expect(query_params).to eq("limit=10&sort=date_created")
12
+ end
13
+ end
14
+
15
+ context "with nested hash as key" do
16
+ it "resolves it and returns the queryable params" do
17
+ params = { limit: 10, filters: { status: "issued", search: "ribose" } }
18
+ query_params = Digicert::Util.to_query(params)
19
+
20
+ expect(
21
+ CGI.unescape(query_params),
22
+ ).to eq("limit=10&filters[status]=issued&filters[search]=ribose")
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,7 +3,6 @@ require "spec_helper"
3
3
  RSpec.describe "Reissuing Certificate" do
4
4
  describe "reissue" do
5
5
  it "reissues an existing nonexpired certificate", api_call: true do
6
-
7
6
  # This tests will find the last created certificate order and
8
7
  # then will try to reissue that, but one important thing to note
9
8
  # that digicert only allows expects active certificate to reissue
@@ -42,7 +42,7 @@ RSpec.describe "Domain Management" do
42
42
  dcv: { method: "email" },
43
43
  name: ribose_test_domain,
44
44
  organization: { id: organization_id },
45
- validations: [{ type: "OV", user: { id: administrator_id }}],
45
+ validations: [{ type: "OV", user: { id: administrator_id } }],
46
46
  }
47
47
  end
48
48
 
@@ -9,7 +9,7 @@ RSpec.describe "Order client email security plus" do
9
9
  # interface with `product_name_id` and required attributes
10
10
  #
11
11
  order_request = Digicert::Order.create(
12
- product_name_id, order_attributes,
12
+ product_name_id, order_attributes
13
13
  )
14
14
 
15
15
  puts order_request
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Client Premium Certificate" do
4
+ describe "ordering a client premium certificate", api_call: true do
5
+ it "creates a new order or a client's premium certificate" do
6
+ product_name_id = "client_premium"
7
+
8
+ # Reqeust a new certificate using the order creation
9
+ # interface by providing t`name_id` and required attributes
10
+ #
11
+ order_request = Digicert::Order.create(
12
+ product_name_id, order_attributes
13
+ )
14
+
15
+ # Retrieve order details using the order_request id as
16
+ # it should contains the `certifcate`, so we then can
17
+ # download the generated certificate
18
+ #
19
+ order = Digicert::Order.fetch(order_request.id)
20
+
21
+ expect(order.product.name).to eq("Premium")
22
+ expect(order.certificate.common_name).to eq(common_name)
23
+ expect(order.organization.display_name).to eq(ribose_inc.display_name)
24
+ end
25
+ end
26
+
27
+ def common_name
28
+ "Awesome People"
29
+ end
30
+
31
+ def order_attributes
32
+ {
33
+ validity_years: 1,
34
+ certificate: certificate_attributes,
35
+ organization: { id: ribose_inc.id },
36
+ }
37
+ end
38
+
39
+ def ribose_inc
40
+ @ribose_inc ||= Digicert::Organization.all.first
41
+ end
42
+
43
+ def certificate_attributes
44
+ {
45
+ common_name: common_name,
46
+ signature_hash: "sha256",
47
+ emails: [awesomepeople_email],
48
+ csr: csr_content_for_ribosetest,
49
+ }
50
+ end
51
+
52
+ def domain
53
+ "ribosetest.com"
54
+ end
55
+
56
+ def awesomepeople_email
57
+ ["awesomepeople", domain].join("@")
58
+ end
59
+
60
+ def csr_content_for_ribosetest
61
+ @csr_content ||= Digicert::CSRGenerator.generate(
62
+ common_name: common_name, organization: ribose_inc,
63
+ )
64
+ end
65
+ end
@@ -9,7 +9,7 @@ RSpec.describe "Order SSl EV Plus" do
9
9
  # interface by providing t`name_id` and required attributes
10
10
  #
11
11
  order_request = Digicert::Order.create(
12
- product_name_id, order_attributes,
12
+ product_name_id, order_attributes
13
13
  )
14
14
 
15
15
  # Retrieve order details using the order_request id as
@@ -45,7 +45,7 @@ RSpec.describe "Order SSl EV Plus" do
45
45
  common_name: common_name,
46
46
  signature_hash: "sha256",
47
47
  csr: csr_content_for_ribosetest,
48
- server_platform: { id: 2 }
48
+ server_platform: { id: 2 },
49
49
  }
50
50
  end
51
51
 
@@ -9,7 +9,7 @@ RSpec.describe "Order SSLWildcard" do
9
9
  # interface by providing t`name_id` and required attributes
10
10
  #
11
11
  order_request = Digicert::Order.create(
12
- product_name_id, order_attributes,
12
+ product_name_id, order_attributes
13
13
  )
14
14
 
15
15
  # Retrieve order details using the order_request id as
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require "dotenv/load"
2
2
  require "webmock/rspec"
3
3
  require "bundler/setup"
4
+
4
5
  require "digicert"
6
+ require "digicert/rspec"
5
7
 
6
8
  Dir["./spec/support/**/*.rb"].sort.each { |file| require file }
7
9
 
@@ -30,6 +32,4 @@ RSpec.configure do |config|
30
32
  Digicert.configuration.debug_mode = true
31
33
  WebMock.allow_net_connect!
32
34
  end
33
-
34
- config.include Digicert::FakeDigicertApi
35
35
  end
@@ -2,19 +2,19 @@ module Digicert
2
2
  module FakeDigicertApi
3
3
  def stub_digicert_product_list_api
4
4
  stub_api_response(
5
- :get, "product", filename: "products", status: 200,
5
+ :get, "product", filename: "products", status: 200
6
6
  )
7
7
  end
8
8
 
9
9
  def stub_digicert_product_fetch_api(name_id)
10
10
  stub_api_response(
11
- :get, ["product", name_id].join("/"), filename: "product", status: 200,
11
+ :get, ["product", name_id].join("/"), filename: "product", status: 200
12
12
  )
13
13
  end
14
14
 
15
15
  def stub_digicert_certificate_request_list_api
16
16
  stub_api_response(
17
- :get, "request", filename: "certificate_requests", status: 200,
17
+ :get, "request", filename: "certificate_requests", status: 200
18
18
  )
19
19
  end
20
20
 
@@ -49,25 +49,31 @@ module Digicert
49
49
 
50
50
  def stub_digicert_order_fetch_api(order_id)
51
51
  stub_api_response(
52
- :get, ["order/certificate", order_id].join("/"), filename: "order",
52
+ :get, ["order/certificate", order_id].join("/"), filename: "order"
53
53
  )
54
54
  end
55
55
 
56
- def stub_digicert_order_list_api
56
+ def stub_digicert_order_list_api(params = {})
57
57
  stub_api_response(
58
- :get, "order/certificate", filename: "orders", status: 200,
58
+ :get,
59
+ path_with_query("order/certificate", params),
60
+ filename: "orders",
61
+ status: 200,
59
62
  )
60
63
  end
61
64
 
62
65
  def stub_digicert_certificate_order_fetch_api(order_id)
63
66
  stub_api_response(
64
- :get, ["order/certificate", order_id].join("/"), filename: "order",
67
+ :get, ["order/certificate", order_id].join("/"), filename: "order"
65
68
  )
66
69
  end
67
70
 
68
- def stub_digicert_organization_list_api
71
+ def stub_digicert_organization_list_api(params = {})
69
72
  stub_api_response(
70
- :get, "organization", filename: "organizations", status: 200,
73
+ :get,
74
+ path_with_query("organization", params),
75
+ filename: "organizations",
76
+ status: 200,
71
77
  )
72
78
  end
73
79
 
@@ -83,7 +89,7 @@ module Digicert
83
89
 
84
90
  def stub_digicert_organization_fetch_api(id)
85
91
  stub_api_response(
86
- :get, ["organization", id].join("/"), filename: "organization",
92
+ :get, ["organization", id].join("/"), filename: "organization"
87
93
  )
88
94
  end
89
95
 
@@ -117,13 +123,13 @@ module Digicert
117
123
 
118
124
  def stub_digicert_container_list_api
119
125
  stub_api_response(
120
- :get, "container", filename: "containers", status: 200,
126
+ :get, "container", filename: "containers", status: 200
121
127
  )
122
128
  end
123
129
 
124
130
  def stub_digicert_container_fetch_api(container_id)
125
131
  stub_api_response(
126
- :get, ["container", container_id].join("/"), filename: "container",
132
+ :get, ["container", container_id].join("/"), filename: "container"
127
133
  )
128
134
  end
129
135
 
@@ -139,7 +145,7 @@ module Digicert
139
145
 
140
146
  def stub_digicert_domain_list_api(filters = {})
141
147
  stub_api_response(
142
- :get, path_with_query("domain", filters), filename: "domains",
148
+ :get, path_with_query("domain", filters), filename: "domains"
143
149
  )
144
150
  end
145
151
 
@@ -283,7 +289,7 @@ module Digicert
283
289
  end
284
290
 
285
291
  def path_with_query(path, params)
286
- query_params = params.map { |key, value| "#{key}=#{value}" }.join("&")
292
+ query_params = Digicert::Util.to_query(params)
287
293
  [path, query_params].join("?")
288
294
  end
289
295
 
@@ -310,13 +316,13 @@ module Digicert
310
316
  def api_key_header
311
317
  {
312
318
  "Content-Type" => "application/json",
313
- "X-DC-DEVKEY" => Digicert.configuration.api_key
319
+ "X-DC-DEVKEY" => Digicert.configuration.api_key,
314
320
  }
315
321
  end
316
322
 
317
323
  def digicert_fixture(filename)
318
324
  file_name = [filename, "json"].join(".")
319
- file_path = ["../../", "fixtures", file_name].join("/")
325
+ file_path = File.join(Digicert.root, "spec", "fixtures", file_name)
320
326
 
321
327
  File.read(File.expand_path(file_path, __FILE__))
322
328
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digicert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: r509
@@ -173,10 +173,12 @@ files:
173
173
  - lib/digicert/product.rb
174
174
  - lib/digicert/request.rb
175
175
  - lib/digicert/response.rb
176
+ - lib/digicert/rspec.rb
176
177
  - lib/digicert/ssl_certificate/base.rb
177
178
  - lib/digicert/ssl_certificate/ssl_ev_plus.rb
178
179
  - lib/digicert/ssl_certificate/ssl_plus.rb
179
180
  - lib/digicert/ssl_certificate/ssl_wildcard.rb
181
+ - lib/digicert/util.rb
180
182
  - lib/digicert/version.rb
181
183
  - spec/acceptance/certificate_download_spec.rb
182
184
  - spec/acceptance/duplicating_certificate_spec.rb
@@ -211,6 +213,7 @@ files:
211
213
  - spec/digicert/ssl_certificate/ssl_ev_plus_spec.rb
212
214
  - spec/digicert/ssl_certificate/ssl_plus_spec.rb
213
215
  - spec/digicert/ssl_certificate/ssl_wildcard_spec.rb
216
+ - spec/digicert/util_spec.rb
214
217
  - spec/fixtures/certificate.pem
215
218
  - spec/fixtures/certificate.zip
216
219
  - spec/fixtures/certificate_request.json
@@ -247,6 +250,7 @@ files:
247
250
  - spec/requests/container_management_spec.rb
248
251
  - spec/requests/domain_management_spec.rb
249
252
  - spec/requests/order_client_email_security_plus_spec.rb
253
+ - spec/requests/order_client_premium_certificate_spec.rb
250
254
  - spec/requests/order_management_spec.rb
251
255
  - spec/requests/order_ssl_ev_plus_spec.rb
252
256
  - spec/requests/order_ssl_wildcard_spec.rb