digicert 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.hound.yml +3 -0
  4. data/.rspec +0 -1
  5. data/.rubocop.yml +629 -0
  6. data/.sample.env +4 -0
  7. data/.sample.pryrc +3 -0
  8. data/.travis.yml +5 -2
  9. data/LICENSE.txt +21 -0
  10. data/README.md +812 -9
  11. data/bin/console +2 -5
  12. data/bin/rspec +17 -0
  13. data/digicert.gemspec +7 -14
  14. data/lib/digicert.rb +40 -2
  15. data/lib/digicert/actions.rb +9 -0
  16. data/lib/digicert/actions/all.rb +27 -0
  17. data/lib/digicert/actions/base.rb +11 -0
  18. data/lib/digicert/actions/create.rb +25 -0
  19. data/lib/digicert/actions/fetch.rb +21 -0
  20. data/lib/digicert/actions/update.rb +25 -0
  21. data/lib/digicert/base.rb +35 -0
  22. data/lib/digicert/base_order.rb +39 -0
  23. data/lib/digicert/certificate.rb +43 -0
  24. data/lib/digicert/certificate_downloader.rb +137 -0
  25. data/lib/digicert/certificate_request.rb +19 -0
  26. data/lib/digicert/client_certificate/base.rb +17 -0
  27. data/lib/digicert/client_certificate/digital_signature_plus.rb +13 -0
  28. data/lib/digicert/client_certificate/email_security_plus.rb +13 -0
  29. data/lib/digicert/client_certificate/premium.rb +17 -0
  30. data/lib/digicert/config.rb +21 -0
  31. data/lib/digicert/configuration.rb +26 -0
  32. data/lib/digicert/container.rb +35 -0
  33. data/lib/digicert/container_template.rb +32 -0
  34. data/lib/digicert/csr_generator.rb +43 -0
  35. data/lib/digicert/debugger.rb +34 -0
  36. data/lib/digicert/domain.rb +59 -0
  37. data/lib/digicert/duplicate_certificate.rb +21 -0
  38. data/lib/digicert/duplicate_certificate_finder.rb +42 -0
  39. data/lib/digicert/email_validation.rb +35 -0
  40. data/lib/digicert/errors.rb +30 -0
  41. data/lib/digicert/errors/forbidden.rb +9 -0
  42. data/lib/digicert/errors/request_error.rb +37 -0
  43. data/lib/digicert/errors/server_error.rb +9 -0
  44. data/lib/digicert/errors/unauthorized.rb +9 -0
  45. data/lib/digicert/expiring_order.rb +21 -0
  46. data/lib/digicert/findable.rb +33 -0
  47. data/lib/digicert/order.rb +81 -0
  48. data/lib/digicert/order_cancellation.rb +25 -0
  49. data/lib/digicert/order_duplicator.rb +11 -0
  50. data/lib/digicert/order_manager.rb +39 -0
  51. data/lib/digicert/order_reissuer.rb +11 -0
  52. data/lib/digicert/organization.rb +43 -0
  53. data/lib/digicert/product.rb +14 -0
  54. data/lib/digicert/request.rb +123 -0
  55. data/lib/digicert/response.rb +30 -0
  56. data/lib/digicert/ssl_certificate/base.rb +9 -0
  57. data/lib/digicert/ssl_certificate/ssl_ev_plus.rb +13 -0
  58. data/lib/digicert/ssl_certificate/ssl_plus.rb +13 -0
  59. data/lib/digicert/ssl_certificate/ssl_wildcard.rb +13 -0
  60. data/lib/digicert/version.rb +23 -1
  61. data/spec/acceptance/certificate_download_spec.rb +68 -0
  62. data/spec/acceptance/duplicating_certificate_spec.rb +86 -0
  63. data/spec/acceptance/reissuing_certificate_spec.rb +104 -0
  64. data/spec/digicert/actions/all_spec.rb +26 -0
  65. data/spec/digicert/actions/create_spec.rb +47 -0
  66. data/spec/digicert/actions/fetch_spec.rb +28 -0
  67. data/spec/digicert/actions/update_spec.rb +39 -0
  68. data/spec/digicert/certificate_downloader_spec.rb +89 -0
  69. data/spec/digicert/certificate_request_spec.rb +49 -0
  70. data/spec/digicert/certificate_spec.rb +93 -0
  71. data/spec/digicert/client_certificate/digital_signature_plus_spec.rb +32 -0
  72. data/spec/digicert/client_certificate/email_security_plus_spec.rb +36 -0
  73. data/spec/digicert/client_certificate/premium_spec.rb +34 -0
  74. data/spec/digicert/config_spec.rb +39 -0
  75. data/spec/digicert/container_spec.rb +44 -0
  76. data/spec/digicert/container_template_spec.rb +32 -0
  77. data/spec/digicert/csr_generator_spec.rb +31 -0
  78. data/spec/digicert/domain_spec.rb +89 -0
  79. data/spec/digicert/duplicate_certificate_finder_spec.rb +27 -0
  80. data/spec/digicert/duplicate_certificate_spec.rb +15 -0
  81. data/spec/digicert/email_validation_spec.rb +26 -0
  82. data/spec/digicert/expiring_order_spec.rb +16 -0
  83. data/spec/digicert/findable_spec.rb +19 -0
  84. data/spec/digicert/order_cancellation_spec.rb +24 -0
  85. data/spec/digicert/order_duplicator_spec.rb +35 -0
  86. data/spec/digicert/order_reissuer_spec.rb +35 -0
  87. data/spec/digicert/order_spec.rb +134 -0
  88. data/spec/digicert/organization_spec.rb +61 -0
  89. data/spec/digicert/product_spec.rb +28 -0
  90. data/spec/digicert/request_spec.rb +47 -0
  91. data/spec/digicert/ssl_certificate/ssl_ev_plus_spec.rb +35 -0
  92. data/spec/digicert/ssl_certificate/ssl_plus_spec.rb +36 -0
  93. data/spec/digicert/ssl_certificate/ssl_wildcard_spec.rb +35 -0
  94. data/spec/fixtures/certificate.pem +79 -0
  95. data/spec/fixtures/certificate.zip +0 -0
  96. data/spec/fixtures/certificate_request.json +116 -0
  97. data/spec/fixtures/certificate_requests.json +59 -0
  98. data/spec/fixtures/certificate_revoked.json +13 -0
  99. data/spec/fixtures/container.json +15 -0
  100. data/spec/fixtures/container_created.json +3 -0
  101. data/spec/fixtures/container_template.json +15 -0
  102. data/spec/fixtures/container_templates.json +14 -0
  103. data/spec/fixtures/containers.json +14 -0
  104. data/spec/fixtures/domain.json +71 -0
  105. data/spec/fixtures/domain_created.json +3 -0
  106. data/spec/fixtures/domains.json +49 -0
  107. data/spec/fixtures/email_validations.json +17 -0
  108. data/spec/fixtures/empty.json +0 -0
  109. data/spec/fixtures/errors.json +6 -0
  110. data/spec/fixtures/expiring_orders.json +20 -0
  111. data/spec/fixtures/order.json +107 -0
  112. data/spec/fixtures/order_created.json +9 -0
  113. data/spec/fixtures/order_duplicated.json +8 -0
  114. data/spec/fixtures/order_duplications.json +57 -0
  115. data/spec/fixtures/order_reissued.json +8 -0
  116. data/spec/fixtures/orders.json +93 -0
  117. data/spec/fixtures/organization.json +35 -0
  118. data/spec/fixtures/organization_created.json +3 -0
  119. data/spec/fixtures/organizations.json +84 -0
  120. data/spec/fixtures/ping.json +3 -0
  121. data/spec/fixtures/product.json +71 -0
  122. data/spec/fixtures/products.json +100 -0
  123. data/spec/fixtures/rsa4096.key +51 -0
  124. data/spec/requests/certificate_duplication_spec.rb +41 -0
  125. data/spec/requests/certificate_generation_spec.rb +93 -0
  126. data/spec/requests/certificate_reissuing_spec.rb +38 -0
  127. data/spec/requests/container_management_spec.rb +36 -0
  128. data/spec/requests/domain_management_spec.rb +64 -0
  129. data/spec/requests/order_client_email_security_plus_spec.rb +38 -0
  130. data/spec/requests/order_management_spec.rb +24 -0
  131. data/spec/requests/order_ssl_ev_plus_spec.rb +57 -0
  132. data/spec/requests/order_ssl_wildcard_spec.rb +57 -0
  133. data/spec/requests/organization_management_spec.rb +22 -0
  134. data/spec/requests/product_management_spec.rb +24 -0
  135. data/spec/requests/request_management_spec.rb +24 -0
  136. data/spec/spec_helper.rb +35 -0
  137. data/spec/support/fake_digicert_api.rb +324 -0
  138. metadata +162 -5
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Order SSLWildcard" do
4
+ describe "ordering ssl wildcard certificate", api_call: true do
5
+ it "creates a new order for ssl wildcard certificate" do
6
+ product_name_id = "ssl_wildcard"
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("WildCard Plus")
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
+ "*.ribosetest.com"
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
+ csr: csr_content_for_ribosetest,
48
+ server_platform: { id: 2 },
49
+ }
50
+ end
51
+
52
+ def csr_content_for_ribosetest
53
+ @csr_content ||= Digicert::CSRGenerator.generate(
54
+ common_name: common_name, organization: ribose_inc,
55
+ )
56
+ end
57
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Organization Management" do
4
+ describe "fetching an organization", api_call: true do
5
+ it "fetches the organization details" do
6
+ organizations = Digicert::Organization.all
7
+ organization = Digicert::Organization.fetch(organizations.first.id)
8
+
9
+ expect(organization.name).to eq("Ribose Inc.")
10
+ expect(organization.id).to eq(organization_id)
11
+ expect(organization.container.id).to eq(container_id)
12
+ end
13
+ end
14
+
15
+ def container_id
16
+ @container_id ||= ENV["DIGICERT_CONTAINER_ID"].to_i
17
+ end
18
+
19
+ def organization_id
20
+ @organization_id ||= ENV["DIGICERT_ORGANIZATION_ID"].to_i
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Product Management" do
4
+ describe "fetching a specific product", api_call: true do
5
+ it "fetches the details for a specific product" do
6
+ product = Digicert::Product.fetch(product_name_id)
7
+
8
+ expect(product.name).to eq("SSL Plus")
9
+ expect(product.allowed_validity_years).to eq([1, 2, 3])
10
+ expect(product.signature_hash_types.default_hash_type_id).to eq("sha256")
11
+ end
12
+ end
13
+
14
+ def product_name_id
15
+ @name_id ||= products.first.name_id
16
+ end
17
+
18
+ def products
19
+ # We are intentionally making this api call to verify
20
+ # the `.all` interface is working as it should have.
21
+ #
22
+ @products ||= Digicert::Product.all
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Request Management" do
4
+ describe "fetching a specific request", api_call: true do
5
+ it "fetches the details for a specific request" do
6
+ request = Digicert::CertificateRequest.fetch(request_id)
7
+
8
+ expect(request.status).to eq("approved")
9
+ expect(request.order.organization.name).to eq("Ribose Inc.")
10
+ expect(request.order.certificate.common_name).to eq("ribosetest.com")
11
+ end
12
+ end
13
+
14
+ def request_id
15
+ @request_id ||= requests.first.id
16
+ end
17
+
18
+ def requests
19
+ # We are intentionally making this API call to ensure
20
+ # the `.all` interface is working as it should have.
21
+ #
22
+ @requests ||= Digicert::CertificateRequest.all
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ require "dotenv/load"
2
+ require "webmock/rspec"
3
+ require "bundler/setup"
4
+ require "digicert"
5
+
6
+ Dir["./spec/support/**/*.rb"].sort.each { |file| require file }
7
+
8
+ RSpec.configure do |config|
9
+ # Enable flags like --only-failures and --next-failure
10
+ config.example_status_persistence_file_path = ".rspec_status"
11
+
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+
16
+ config.before :all do
17
+ Digicert.configure do |digicert_config|
18
+ digicert_config.debug_mode = false
19
+ digicert_config.api_key = ENV["SECRET_DEV_API_KEY"] || "SECRET_KEY"
20
+ end
21
+ end
22
+
23
+ # Skip the actual API calls by default
24
+ config.filter_run_excluding api_call: true
25
+
26
+ # Allow the net_connection when we actually want to
27
+ # perform an actual API reques
28
+ #
29
+ config.before :each, api_call: true do
30
+ Digicert.configuration.debug_mode = true
31
+ WebMock.allow_net_connect!
32
+ end
33
+
34
+ config.include Digicert::FakeDigicertApi
35
+ end
@@ -0,0 +1,324 @@
1
+ module Digicert
2
+ module FakeDigicertApi
3
+ def stub_digicert_product_list_api
4
+ stub_api_response(
5
+ :get, "product", filename: "products", status: 200,
6
+ )
7
+ end
8
+
9
+ def stub_digicert_product_fetch_api(name_id)
10
+ stub_api_response(
11
+ :get, ["product", name_id].join("/"), filename: "product", status: 200,
12
+ )
13
+ end
14
+
15
+ def stub_digicert_certificate_request_list_api
16
+ stub_api_response(
17
+ :get, "request", filename: "certificate_requests", status: 200,
18
+ )
19
+ end
20
+
21
+ def stub_digicert_certificate_request_fetch_api(request_id)
22
+ stub_api_response(
23
+ :get,
24
+ ["request", request_id].join("/"),
25
+ filename: "certificate_request",
26
+ status: 200,
27
+ )
28
+ end
29
+
30
+ def stub_digicert_certificate_request_update_api(request_id, attributes)
31
+ stub_api_response(
32
+ :put,
33
+ ["request", request_id, "status"].join("/"),
34
+ data: attributes,
35
+ filename: "empty",
36
+ status: 204,
37
+ )
38
+ end
39
+
40
+ def stub_digicert_order_create_api(certificate_type, attributes)
41
+ stub_api_response(
42
+ :post,
43
+ ["order/certificate", certificate_type].join("/"),
44
+ data: attributes,
45
+ filename: "order_created",
46
+ status: 201,
47
+ )
48
+ end
49
+
50
+ def stub_digicert_order_fetch_api(order_id)
51
+ stub_api_response(
52
+ :get, ["order/certificate", order_id].join("/"), filename: "order",
53
+ )
54
+ end
55
+
56
+ def stub_digicert_order_list_api
57
+ stub_api_response(
58
+ :get, "order/certificate", filename: "orders", status: 200,
59
+ )
60
+ end
61
+
62
+ def stub_digicert_certificate_order_fetch_api(order_id)
63
+ stub_api_response(
64
+ :get, ["order/certificate", order_id].join("/"), filename: "order",
65
+ )
66
+ end
67
+
68
+ def stub_digicert_organization_list_api
69
+ stub_api_response(
70
+ :get, "organization", filename: "organizations", status: 200,
71
+ )
72
+ end
73
+
74
+ def stub_digicert_organization_create_api(organization_attributes)
75
+ stub_api_response(
76
+ :post,
77
+ "organization",
78
+ data: organization_attributes,
79
+ filename: "organization_created",
80
+ status: 201,
81
+ )
82
+ end
83
+
84
+ def stub_digicert_organization_fetch_api(id)
85
+ stub_api_response(
86
+ :get, ["organization", id].join("/"), filename: "organization",
87
+ )
88
+ end
89
+
90
+ def stub_digicert_container_template_list_api(container_id)
91
+ stub_api_response(
92
+ :get,
93
+ ["container", container_id, "template"].join("/"),
94
+ filename: "container_templates",
95
+ status: 200,
96
+ )
97
+ end
98
+
99
+ def stub_digicert_container_template_fetch_api(template_id, container_id)
100
+ stub_api_response(
101
+ :get,
102
+ ["container", container_id, "template", template_id].join("/"),
103
+ filename: "container_template",
104
+ status: 200,
105
+ )
106
+ end
107
+
108
+ def stub_digicert_container_create_api(container_id:, **attributes)
109
+ stub_api_response(
110
+ :post,
111
+ ["container", container_id, "children"].join("/"),
112
+ data: attributes,
113
+ filename: "container_created",
114
+ status: 201,
115
+ )
116
+ end
117
+
118
+ def stub_digicert_container_list_api
119
+ stub_api_response(
120
+ :get, "container", filename: "containers", status: 200,
121
+ )
122
+ end
123
+
124
+ def stub_digicert_container_fetch_api(container_id)
125
+ stub_api_response(
126
+ :get, ["container", container_id].join("/"), filename: "container",
127
+ )
128
+ end
129
+
130
+ def stub_digicert_domain_create_api(attributes)
131
+ stub_api_response(
132
+ :post,
133
+ "domain",
134
+ data: attributes,
135
+ filename: "domain_created",
136
+ status: 201,
137
+ )
138
+ end
139
+
140
+ def stub_digicert_domain_list_api(filters = {})
141
+ stub_api_response(
142
+ :get, path_with_query("domain", filters), filename: "domains",
143
+ )
144
+ end
145
+
146
+ def stub_digicert_domain_fetch_api(domain_id, filters)
147
+ stub_api_response(
148
+ :get,
149
+ path_with_query(["domain", domain_id].join("/"), filters),
150
+ filename: "domain",
151
+ status: 200,
152
+ )
153
+ end
154
+
155
+ def stub_digicert_domain_activate_api(domain_id)
156
+ stub_api_response(
157
+ :put,
158
+ ["domain", domain_id, "activate"].join("/"),
159
+ filename: "empty",
160
+ status: 204,
161
+ )
162
+ end
163
+
164
+ def stub_digicert_domain_deactivate_api(domain_id)
165
+ stub_api_response(
166
+ :put,
167
+ ["domain", domain_id, "deactivate"].join("/"),
168
+ filename: "empty",
169
+ status: 204,
170
+ )
171
+ end
172
+
173
+ def stub_digicert_email_validations_api(order_id)
174
+ stub_api_response(
175
+ :get,
176
+ ["order", "certificate", order_id, "email-validation"].join("/"),
177
+ filename: "email_validations",
178
+ status: 200,
179
+ )
180
+ end
181
+
182
+ def stub_digicert_email_validations_validate_api(token:, email:)
183
+ stub_api_response(
184
+ :put,
185
+ path_with_query("email-validation/#{token}", email: email),
186
+ filename: "empty",
187
+ status: 204,
188
+ )
189
+ end
190
+
191
+ def stub_digicert_order_reissue_api(order_id, attributes)
192
+ stub_api_response(
193
+ :post,
194
+ ["order", "certificate", order_id, "reissue"].join("/"),
195
+ data: attributes,
196
+ filename: "order_reissued",
197
+ status: 201,
198
+ )
199
+ end
200
+
201
+ def stub_digicert_order_duplicate_api(order_id, attributes)
202
+ stub_api_response(
203
+ :post,
204
+ ["order", "certificate", order_id, "duplicate"].join("/"),
205
+ data: attributes,
206
+ filename: "order_duplicated",
207
+ status: 201,
208
+ )
209
+ end
210
+
211
+ def stub_digicert_order_duplications_api(order_id)
212
+ stub_api_response(
213
+ :get,
214
+ ["order", "certificate", order_id, "duplicate"].join("/"),
215
+ filename: "order_duplications",
216
+ status: 200,
217
+ )
218
+ end
219
+
220
+ def stub_digicert_order_cancellation_api(order_id, attributes)
221
+ stub_api_response(
222
+ :put,
223
+ ["order", "certificate", order_id, "status"].join("/"),
224
+ data: attributes,
225
+ filename: "empty",
226
+ status: 204,
227
+ )
228
+ end
229
+
230
+ def stub_digicert_order_expiring_api(container_id)
231
+ stub_api_response(
232
+ :get,
233
+ ["report", "order", container_id, "expiring"].join("/"),
234
+ filename: "expiring_orders",
235
+ status: 200,
236
+ )
237
+ end
238
+
239
+ def stub_digicert_certificate_revoke_api(id, attributes)
240
+ stub_api_response(
241
+ :put,
242
+ ["certificate", id, "revoke"].join("/"),
243
+ data: attributes,
244
+ filename: "certificate_revoked",
245
+ status: 201,
246
+ )
247
+ end
248
+
249
+ def stub_digicert_certificate_download_by_format(id, format, ext = "zip")
250
+ stub_api_response_with_io(
251
+ :get,
252
+ ["certificate", id, "download", "format", format].join("/"),
253
+ filename: ["certificate", ext].join("."),
254
+ status: 200,
255
+ )
256
+ end
257
+
258
+ def stub_digicert_certificate_download_by_platform(id, platform = nil)
259
+ stub_api_response_with_io(
260
+ :get,
261
+ ["certificate", id, "download", "platform", platform].compact.join("/"),
262
+ filename: "certificate.zip",
263
+ status: 200,
264
+ )
265
+ end
266
+
267
+ def stub_api_response(method, end_point, filename:, status: 200, data: nil)
268
+ stub_request(method, digicert_api_end_point(end_point)).
269
+ with(digicert_api_request_headers(data: data)).
270
+ to_return(response_with(filename: filename, status: status))
271
+ end
272
+
273
+ def stub_api_response_with_io(method, end_point, filename:, status: 200)
274
+ stub_request(method, digicert_api_end_point(end_point)).
275
+ with(digicert_api_request_headers(data: nil)).
276
+ to_return(response_with_file(file: filename, status: status))
277
+ end
278
+
279
+ private
280
+
281
+ def digicert_api_end_point(end_point)
282
+ ["https://www.digicert.com/services/v2", end_point].join("/")
283
+ end
284
+
285
+ def path_with_query(path, params)
286
+ query_params = params.map { |key, value| "#{key}=#{value}" }.join("&")
287
+ [path, query_params].join("?")
288
+ end
289
+
290
+ def digicert_api_request_headers(data: nil)
291
+ Hash.new.tap do |request_headers|
292
+ request_headers[:headers] = api_key_header
293
+ unless data.nil?
294
+ request_headers[:body] = data.to_json
295
+ end
296
+ end
297
+ end
298
+
299
+ def response_with(filename:, status:)
300
+ { body: digicert_fixture(filename), status: status }
301
+ end
302
+
303
+ def response_with_file(file:, status:)
304
+ {
305
+ status: status,
306
+ body: File.new(File.expand_path("../../fixtures/#{file}", __FILE__)),
307
+ }
308
+ end
309
+
310
+ def api_key_header
311
+ {
312
+ "Content-Type" => "application/json",
313
+ "X-DC-DEVKEY" => Digicert.configuration.api_key
314
+ }
315
+ end
316
+
317
+ def digicert_fixture(filename)
318
+ file_name = [filename, "json"].join(".")
319
+ file_path = ["../../", "fixtures", file_name].join("/")
320
+
321
+ File.read(File.expand_path(file_path, __FILE__))
322
+ end
323
+ end
324
+ end