geocerts 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.document +5 -0
  2. data/.gitignore +6 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +71 -0
  5. data/Rakefile +70 -0
  6. data/VERSION +1 -0
  7. data/autotest/discover.rb +39 -0
  8. data/geocerts.gemspec +144 -0
  9. data/lib/geo_certs.rb +57 -0
  10. data/lib/geo_certs/agreement.rb +18 -0
  11. data/lib/geo_certs/api.rb +29 -0
  12. data/lib/geo_certs/api_object.rb +111 -0
  13. data/lib/geo_certs/certificate.rb +88 -0
  14. data/lib/geo_certs/collection.rb +12 -0
  15. data/lib/geo_certs/csr.rb +31 -0
  16. data/lib/geo_certs/email.rb +8 -0
  17. data/lib/geo_certs/endpoints/agreements.rb +23 -0
  18. data/lib/geo_certs/endpoints/certificates.rb +73 -0
  19. data/lib/geo_certs/endpoints/events.rb +56 -0
  20. data/lib/geo_certs/endpoints/orders.rb +181 -0
  21. data/lib/geo_certs/endpoints/products.rb +30 -0
  22. data/lib/geo_certs/errors.rb +30 -0
  23. data/lib/geo_certs/event.rb +67 -0
  24. data/lib/geo_certs/exceptions.rb +124 -0
  25. data/lib/geo_certs/hash_extension.rb +50 -0
  26. data/lib/geo_certs/order.rb +369 -0
  27. data/lib/geo_certs/order/administrator.rb +23 -0
  28. data/lib/geo_certs/order/contact.rb +30 -0
  29. data/lib/geo_certs/order/extended_validation_approver.rb +23 -0
  30. data/lib/geo_certs/order/organization.rb +39 -0
  31. data/lib/geo_certs/order/renewal_information.rb +31 -0
  32. data/lib/geo_certs/parsers/order_parser.rb +8 -0
  33. data/lib/geo_certs/product.rb +67 -0
  34. data/test/config/initializers/_remote_tests.rb +15 -0
  35. data/test/config/initializers/fakeweb.rb +2 -0
  36. data/test/config/initializers/geocerts.rb +13 -0
  37. data/test/config/initializers/responses.rb +3 -0
  38. data/test/config/test_credentials.example.yml +2 -0
  39. data/test/factories.rb +15 -0
  40. data/test/fixtures/responses.rb +80 -0
  41. data/test/fixtures/responses/agreement.rb +136 -0
  42. data/test/fixtures/responses/certificate.rb +227 -0
  43. data/test/fixtures/responses/event.rb +60 -0
  44. data/test/fixtures/responses/order.rb +272 -0
  45. data/test/fixtures/responses/product.rb +77 -0
  46. data/test/integrations/agreement_test.rb +40 -0
  47. data/test/integrations/api_test.rb +33 -0
  48. data/test/integrations/certificate_test.rb +195 -0
  49. data/test/integrations/event_test.rb +167 -0
  50. data/test/integrations/order_test.rb +510 -0
  51. data/test/integrations/product_test.rb +72 -0
  52. data/test/test_helper.rb +68 -0
  53. data/test/units/certificate_test.rb +21 -0
  54. data/test/units/collection_test.rb +27 -0
  55. data/test/units/csr_test.rb +27 -0
  56. data/test/units/geo_certs_test.rb +19 -0
  57. data/test/units/order/administrator_test.rb +24 -0
  58. data/test/units/order/extended_validation_approver_test.rb +24 -0
  59. data/test/units/order/organization_test.rb +0 -0
  60. data/test/units/order/renewal_information_test.rb +36 -0
  61. data/test/units/order_test.rb +59 -0
  62. data/test/units/product_test.rb +21 -0
  63. metadata +220 -0
@@ -0,0 +1,77 @@
1
+ module Responses
2
+
3
+ module Product
4
+
5
+ All = %|HTTP/1.1 200 OK
6
+ Date: Tue, 08 Sep 2009 19:34:48 GMT
7
+ Server: Mongrel 1.1.3
8
+ Status: 200 OK
9
+ Cache-Control: no-cache
10
+ Content-Type: application/xml; charset=utf-8
11
+ Content-Length: 1751
12
+ Vary: Accept-Encoding
13
+ Connection: close
14
+
15
+ <?xml version="1.0" encoding="UTF-8"?>
16
+ <products>
17
+ <product>
18
+ <name>QuickSSL</name>
19
+ <sku>Q</sku>
20
+ <max-years type="integer">6</max-years>
21
+ </product>
22
+ <product>
23
+ <name>QuickSSL Premium</name>
24
+ <sku>QP</sku>
25
+ <max-years type="integer">6</max-years>
26
+ </product>
27
+ <product>
28
+ <name>True BusinessID</name>
29
+ <sku>TBID</sku>
30
+ <max-years type="integer">5</max-years>
31
+ </product>
32
+ <product>
33
+ <name>Wildcard SSL</name>
34
+ <sku>TW</sku>
35
+ <max-years type="integer">5</max-years>
36
+ </product>
37
+ <product>
38
+ <name>True BizID Extended Validation</name>
39
+ <sku>EV</sku>
40
+ <max-years type="integer">2</max-years>
41
+ </product>
42
+ <product>
43
+ <name>Power Server ID</name>
44
+ <sku>PSID</sku>
45
+ <max-years type="integer">6</max-years>
46
+ </product>
47
+ <product>
48
+ <name>True Biz Multi-Domain 10</name>
49
+ <sku>TBIDMD10</sku>
50
+ <max-years type="integer">5</max-years>
51
+ </product>
52
+ <product>
53
+ <name>True Biz Multi-Domain 15</name>
54
+ <sku>TBIDMD15</sku>
55
+ <max-years type="integer">5</max-years>
56
+ </product>
57
+ <product>
58
+ <name>True Biz Multi-Domain 20</name>
59
+ <sku>TBIDMD20</sku>
60
+ <max-years type="integer">5</max-years>
61
+ </product>
62
+ <product>
63
+ <name>True Biz Multi-Domain 25</name>
64
+ <sku>TBIDMD25</sku>
65
+ <max-years type="integer">5</max-years>
66
+ </product>
67
+ <product>
68
+ <name>Free Trial (QP)</name>
69
+ <sku>T</sku>
70
+ <max-years type="integer">1</max-years>
71
+ </product>
72
+ </products>
73
+ |
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class GeoCerts::AgreementTest < Test::Unit::TestCase
4
+
5
+ context 'GeoCerts::Agreement (using the API)' do
6
+
7
+ context 'user agreement' do
8
+
9
+ should 'return a GeoCerts::Agreement' do
10
+ managed_server_request :get, '/products.xml', :response => Responses::Product::All do
11
+ managed_server_request :get, '/products/Q/agreement.xml', :response => Responses::Agreement::Agreement do
12
+ assert_kind_of(GeoCerts::Agreement, GeoCerts::Product.find('Q').user_agreement)
13
+ end
14
+ end
15
+ end
16
+
17
+ should 'contain the server-provided agreement text' do
18
+ managed_server_request :get, '/products.xml', :response => Responses::Product::All do
19
+ managed_server_request :get, '/products/Q/agreement.xml', :response => Responses::Agreement::Agreement do
20
+ text = GeoCerts::Product.find('Q').user_agreement.text
21
+ assert_match(/GeoTrust\(R\) SSL Certificate Subscriber Agreement/, text)
22
+ assert_match(/YOU MUST READ THIS GEOTRUST SSL CERTIFICATE SUBSCRIBER AGREEMENT/, text)
23
+ assert_match(/GeoTrust SSL Certificate Subscriber Agreement Version 2.0/, text)
24
+ end
25
+ end
26
+ end
27
+
28
+ should 'return an error for an unrecognized product code' do
29
+ managed_server_request :get, '/products/BAD/agreement.xml', :response => Responses::Agreement::UnrecognizedProduct do
30
+ assert_responds_with_exception(GeoCerts::UnprocessableEntity, -90000) do
31
+ GeoCerts::Product.new(:sku => 'BAD').user_agreement
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class GeoCerts::APITest < Test::Unit::TestCase
4
+
5
+ context 'GeoCerts::API' do
6
+
7
+ should 'be unauthorized' do
8
+ managed_server_request :get, '/orders.xml', :response => Responses::Unauthorized do
9
+ assert_responds_with_exception(GeoCerts::Unauthorized) do
10
+ GeoCerts::Order.all
11
+ end
12
+ end
13
+ end
14
+
15
+ should 'raise a GeoCerts::RequestTimeout error when the connection times out' do
16
+ exclusively_mocked_request :get, '/orders.xml', :exception => Timeout::Error do
17
+ assert_responds_with_exception(GeoCerts::RequestTimeout) do
18
+ GeoCerts::Order.all
19
+ end
20
+ end
21
+ end
22
+
23
+ should 'raise a GeoCerts::RequestTimeout error when the connection gets reset' do
24
+ exclusively_mocked_request :get, '/orders.xml', :exception => Errno::ECONNRESET do
25
+ assert_responds_with_exception(GeoCerts::ConnectionError) do
26
+ GeoCerts::Order.all
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,195 @@
1
+ require 'test_helper'
2
+
3
+ class GeoCerts::CertificateTest < Test::Unit::TestCase
4
+
5
+ context 'Certificate (using the API)' do
6
+
7
+ context 'all' do
8
+
9
+ should 'return a collection of GeoCerts::Certificates' do
10
+ managed_server_request :get, '/certificates.xml', :response => Responses::Certificate::All do
11
+ assert GeoCerts::Certificate.all.all? { |item| item.kind_of?(GeoCerts::Certificate) }
12
+ end
13
+ end
14
+
15
+ should 'return two certificates' do
16
+ exclusively_mocked_request :get, '/certificates.xml', :response => Responses::Certificate::All do
17
+ assert_equal(2, GeoCerts::Certificate.all.size)
18
+ end
19
+ end
20
+
21
+ should 'properly populate the certificate data' do
22
+ exclusively_mocked_request :get, '/certificates.xml', :response => Responses::Certificate::All do
23
+ certificate = GeoCerts::Certificate.all.first
24
+ assert_equal(422815, certificate.order_id)
25
+ assert_equal('93520', certificate.geotrust_order_id)
26
+ assert_equal('Renewed', certificate.status)
27
+ assert_equal('www.example.com', certificate.common_name)
28
+ assert_equal('1E08', certificate.serial_number)
29
+ assert_equal('Atlanta', certificate.city)
30
+ assert_equal('Georgia', certificate.state)
31
+ assert_equal('US', certificate.country)
32
+ assert_equal('GeoCerts', certificate.organization)
33
+ assert_equal('Internet', certificate.organizational_unit)
34
+ assert_equal('ssladmin@example.com',certificate.approver_email)
35
+ assert_equal('test@example.com', certificate.reissue_email)
36
+ assert_equal(DateTime.parse('2009-08-11T19:28:18-04:00'), certificate.start_at)
37
+ assert_equal(DateTime.parse('2009-08-20T00:59:16-04:00'), certificate.end_at)
38
+ assert_match(%r{/orders/422815/certificate\.xml$}, certificate.url)
39
+ assert_equal("-----BEGIN CERTIFICATE-----\nMIIDATCCAmqgAwIBAgICHwkwDQYJKoZIhvcNAQEEBQAwSzELMAkGA1UEBhMCVVMx\nFTATBgNVBAoTDEdlb1RydXN0IEluYzElMCMGA1UEAxMcR2VvVHJ1c3QgUHJlLVBy\nb2R1Y3Rpb24gQ0EgMTAeFw0wOTA4MTEyMzI4MThaFw0wOTA4MjAwNDU5MTZaMIHI\nMQswCQYDVQQGEwJVUzEbMBkGA1UEChMSc3J2MDIud2F2ZXBhdGguY29tMRMwEQYD\nVQQLEwpHVDAzMTIzMjc1MTEwLwYDVQQLEyhTZWUgd3d3Lmdlb3RydXN0LmN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Vx\ndWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCBnzANBgkqhkiG9w0B\nAQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPRfM6f\nBeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+A\ncJkVV5MW8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC\nAwEAAaOCAQkwggEFMHAGA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQ\nMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm\naWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw\nODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvSspXXR9gj\nIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQF\nMAMBAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUA\nMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm\naWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw\n1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4\n-----END CERTIFICATE-----", certificate.ca_root)
41
+ assert !certificate.trial?
42
+ end
43
+ end
44
+
45
+ should 'set the end at time' do
46
+ exclusively_mocked_request :get, '/certificates.xml', :response => Responses::Certificate::All do
47
+ assert_equal DateTime.parse('2009-09-08T12:57:10-04:00'), GeoCerts::Certificate.all.end_at
48
+ end
49
+ end
50
+
51
+ should 'set the start at time' do
52
+ exclusively_mocked_request :get, '/certificates.xml', :response => Responses::Certificate::All do
53
+ assert_equal DateTime.parse('2009-08-09T12:57:10-04:00'), GeoCerts::Certificate.all.start_at
54
+ end
55
+ end
56
+
57
+ should 'modify the queried window of time' do
58
+ managed_server_request :get, '/certificates.xml?start_at=2009-01-01T00:00:00+00:00&end_at=2009-01-02T00:00:00+00:00', :response => Responses::Certificate::All do
59
+ GeoCerts::Certificate.all(:start_at => DateTime.parse('2009-01-01T00:00:00Z'), :end_at => DateTime.parse('2009-01-02T00:00:00Z'))
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ context 'find' do
66
+
67
+ setup do
68
+ managed_server_request :get, '/orders.xml', :response => Responses::Order::All do
69
+ @order_id = GeoCerts::Order.all.first.id
70
+ end
71
+ end
72
+
73
+ should 'return a GeoCerts::Certificate' do
74
+ managed_server_request :get, "/orders/#{@order_id}/certificate.xml", :response => Responses::Certificate::Certificate do
75
+ certificate = GeoCerts::Certificate.find(@order_id)
76
+ assert_kind_of(GeoCerts::Certificate, certificate)
77
+ assert_equal(@order_id, certificate.order_id)
78
+ end
79
+ end
80
+
81
+ should 'properly populate the certificate data' do
82
+ exclusively_mocked_request :get, '/orders/422815/certificate.xml', :response => Responses::Certificate::Certificate do
83
+ certificate = GeoCerts::Certificate.find(422815)
84
+ assert_equal(422815, certificate.order_id)
85
+ assert_equal('93520', certificate.geotrust_order_id)
86
+ assert_equal('Renewed', certificate.status)
87
+ assert_equal('www.example.com', certificate.common_name)
88
+ assert_equal('1E08', certificate.serial_number)
89
+ assert_equal('Atlanta', certificate.city)
90
+ assert_equal('Georgia', certificate.state)
91
+ assert_equal('US', certificate.country)
92
+ assert_equal('GeoCerts', certificate.organization)
93
+ assert_equal('Internet', certificate.organizational_unit)
94
+ assert_equal('ssladmin@example.com',certificate.approver_email)
95
+ assert_equal('test@example.com', certificate.reissue_email)
96
+ assert_equal(DateTime.parse('2009-08-11T19:28:18-04:00'), certificate.start_at)
97
+ assert_equal(DateTime.parse('2009-08-20T00:59:16-04:00'), certificate.end_at)
98
+ assert_match(%r{/orders/422815/certificate\.xml$}, certificate.url)
99
+ assert_equal("-----BEGIN CERTIFICATE-----\nMIIDATCCAmqgAwIBAgICHwkwDQYJKoZIhvcNAQEEBQAwSzELMAkGA1UEBhMCVVMx\nFTATBgNVBAoTDEdlb1RydXN0IEluYzElMCMGA1UEAxMcR2VvVHJ1c3QgUHJlLVBy\nb2R1Y3Rpb24gQ0EgMTAeFw0wOTA4MTEyMzI4MThaFw0wOTA4MjAwNDU5MTZaMIHI\nMQswCQYDVQQGEwJVUzEbMBkGA1UEChMSc3J2MDIud2F2ZXBhdGguY29tMRMwEQYD\nVQQLEwpHVDAzMTIzMjc1MTEwLwYDVQQLEyhTZWUgd3d3Lmdlb3RydXN0LmNvbS9y\nZXNvdXJjZXMvY3BzIChjKTA5MTcwNQYDVQQLEy5Eb21haW4gQ29udHJvbCBWYWxp\nZGF0ZWQgLSBRdWlja1NTTCBQcmVtaXVtKFIpMRswGQYDVQQDExJzcnYwMi53YXZl\ncGF0aC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOfnRzNL60aJdLL7\nSyJ7OFJPINg4yjLDLUJA7moeerN7QupUeJm68LHQ7juTRJ7lqkwTNK1hDRZuH7+6\nsM3ohFOjWv9D9hEWqR1tKAUBnhTJlTr8rYmvqbSNCWhUJZy53NqntiyDpg8kNOTM\nUVsY0cAn9e4vJHvh49t2AsMMAjtjAgMBAAGjdjB0MA4GA1UdDwEB/wQEAwIE8DBB\nBgNVHR8EOjA4MDagNKAyhjBodHRwOi8vdGVzdC1jcmwuZ2VvdHJ1c3QuY29tL2Ny\nbHMvcHJlcHJvZGNhMS5jcmwwHwYDVR0jBBgwFoAUSu1cZmsN8sJTHAsEc92rVZad\nv4cwDQYJKoZIhvcNAQEEBQADgYEAJyNUrcKjcbtVatngWw6KCCtogp1V2eEt9BJM\nUVsY0cAn9e4vJHvh49t2AsMMAjtjAgMBAAGjdjB0MA4GA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A0GCSqGSIb3DQEBBQUA\nMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm\naWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw\n1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4\n-----END CERTIFICATE-----", certificate.ca_root)
101
+ assert !certificate.trial?
102
+ end
103
+ end
104
+
105
+ should 'raise a ResourceNotFound error' do
106
+ managed_server_request :get, '/orders/999999999/certificate.xml', :response => Responses::InvalidOrderId do
107
+ assert_responds_with_exception(GeoCerts::ResourceNotFound, -90004) do
108
+ GeoCerts::Certificate.find(999999999)
109
+ end
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ context 'find_by_order_id' do
116
+
117
+ setup do
118
+ managed_server_request :get, '/orders.xml', :response => Responses::Order::All do
119
+ @order_id = GeoCerts::Order.all.first.id
120
+ end
121
+ end
122
+
123
+ should 'return a GeoCerts::Certificate' do
124
+ managed_server_request :get, "/orders/#{@order_id}/certificate.xml", :response => Responses::Certificate::Certificate do
125
+ certificate = GeoCerts::Certificate.find_by_order_id(@order_id)
126
+ assert_kind_of(GeoCerts::Certificate, certificate)
127
+ assert_equal(@order_id, certificate.order_id)
128
+ end
129
+ end
130
+
131
+ should 'properly populate the certificate data' do
132
+ exclusively_mocked_request :get, '/orders/422815/certificate.xml', :response => Responses::Certificate::Certificate do
133
+ certificate = GeoCerts::Certificate.find_by_order_id(422815)
134
+ assert_equal(422815, certificate.order_id)
135
+ assert_equal('93520', certificate.geotrust_order_id)
136
+ assert_equal('Renewed', certificate.status)
137
+ assert_equal('www.example.com', certificate.common_name)
138
+ assert_equal('1E08', certificate.serial_number)
139
+ assert_equal('Atlanta', certificate.city)
140
+ assert_equal('Georgia', certificate.state)
141
+ assert_equal('US', certificate.country)
142
+ assert_equal('GeoCerts', certificate.organization)
143
+ assert_equal('Internet', certificate.organizational_unit)
144
+ assert_equal('ssladmin@example.com',certificate.approver_email)
145
+ assert_equal('test@example.com', certificate.reissue_email)
146
+ assert_equal(DateTime.parse('2009-08-11T19:28:18-04:00'), certificate.start_at)
147
+ assert_equal(DateTime.parse('2009-08-20T00:59:16-04:00'), certificate.end_at)
148
+ assert_match(%r{/orders/422815/certificate\.xml$}, certificate.url)
149
+ assert_equal("-----BEGIN CERTIFICATE-----\nMIIDATCCAmqgAwIBAgICHwkwDQYJKoZIhvcNAQEEBQAwSzELMAkGA1UEBhMCVVMx\nFTATBgNVBAoTDEdlb1RydXN0IEluYzElMCMGA1UEAxMcR2VvVHJ1c3QgUHJlLVBy\nb2R1Y3Rpb24gQ0EgMTAeFw0wOTA4MTEyMzI4MThaFw0wOTA4MjAwNDU5MTZaMIHI\nMQswCQYDVQQGEwJVUzEbMBkGA1UEChMSc3J2MDIud2F2ZXBhdGguY29tMRMwEQYD\nVQQLEwpHVDAzMTIzMjc1MTEwLwYDVQQLEyhTZWUgd3d3Lmdlb3RydXN0LmNvbS9y\nZXNvdXJjZXMvY3BzIChjKTA5MTcwNQYDVQQLEy5Eb21haW4gQ29udHJvbCBWYWxp\nZGF0ZWQgLSBRdWlja1NTTCBQcmVtaXVtKFIpMRswGQYDVQQDExJzcnYwMi53YXZl\ncGF0aC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOfnRzNL60aJdLL7\nSyJ7OFJPINg4yjLDLUJA7moeerN7QupUeJm68LHQ7juTRJ7lqkwTNK1hDRZuH7+6\nsM3ohFOjWv9D9hEWqR1tKAUBnhTJlTr8rYmvqbSNCWhUJZy53NqntiyDpg8kNOTM\nUVsY0cAn9e4vJHvh49t2AsMMAjtjAgMBAAGjdjB0MA4GA1UdDwEB/wQEAwIE8DBB\nBgNVHR8EOjA4MDagNKAyhjBodHRwOi8vdGVzdC1jcmwuZ2VvdHJ1c3QuY29tL2Ny\nbHMvcHJlcHJvZGNhMS5jcmwwHwYDVR0jBBgwFoAUSu1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OZo+SvSspXXR9gj\nIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQF\nMAMBAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUA\nMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm\naWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw\n1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4\n-----END CERTIFICATE-----", certificate.ca_root)
151
+ assert !certificate.trial?
152
+ end
153
+ end
154
+
155
+ should 'not raise a ResourceNotFound error, instead returning nil' do
156
+ managed_server_request :get, '/orders/999999999/certificate.xml', :response => Responses::InvalidOrderId do
157
+ assert_responds_without_exception(GeoCerts::ResourceNotFound, -90004) do
158
+ assert_nil GeoCerts::Certificate.find_by_order_id(999999999)
159
+ end
160
+ end
161
+ end
162
+
163
+ end
164
+
165
+ context 'reissue' do
166
+
167
+ setup do
168
+ managed_server_request :get, '/orders.xml', :response => Responses::Order::All do
169
+ @order_id = GeoCerts::Order.all.first.id
170
+ end
171
+ end
172
+
173
+ should 'return a GeoCerts::Certificate when successful' do
174
+ managed_server_request :get, "/orders/#{@order_id}/certificate.xml", :response => Responses::Certificate::Certificate do
175
+ managed_server_request :post, "/orders/422815/certificate/reissue.xml?order[csr][body]=testbody", :response => Responses::Certificate::Certificate do
176
+ assert_kind_of(GeoCerts::Certificate, GeoCerts::Certificate.find(@order_id).reissue!(GeoCerts::CSR.new(:body => 'testbody')))
177
+ end
178
+ end
179
+ end
180
+
181
+ should 'raise an error with no CSR body provided' do
182
+ managed_server_request :get, "/orders/#{@order_id}/certificate.xml", :response => Responses::Certificate::Certificate do
183
+ managed_server_request :post, "/orders/#{@order_id}/certificate/reissue.xml?order[csr][body]=", :response => Responses::Certificate::MissingCSRBody do
184
+ assert_responds_with_exception(GeoCerts::UnprocessableEntity, -90010) do
185
+ GeoCerts::Certificate.find(@order_id).reissue!(GeoCerts::CSR.new(:body => nil))
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ end
192
+
193
+ end
194
+
195
+ end
@@ -0,0 +1,167 @@
1
+ require 'test_helper'
2
+
3
+ class GeoCerts::EventTest < Test::Unit::TestCase
4
+
5
+ context 'GeoCerts::Event (using the API)' do
6
+
7
+ context 'all' do
8
+
9
+ should 'return a collection of GeoCerts::Events' do
10
+ managed_server_request :get, '/events.xml', :response => Responses::Event::All do
11
+ events = GeoCerts::Event.all
12
+ assert_kind_of(GeoCerts::Collection, events)
13
+ assert events.all? { |event| event.kind_of?(GeoCerts::Event) }
14
+ end
15
+ end
16
+
17
+ should 'return 2 events' do
18
+ exclusively_mocked_request :get, '/events.xml', :response => Responses::Event::All do
19
+ assert_equal(2, GeoCerts::Event.all.size)
20
+ end
21
+ end
22
+
23
+ should 'properly populate the events' do
24
+ exclusively_mocked_request :get, '/events.xml', :response => Responses::Event::All do
25
+ event = GeoCerts::Event.all.first
26
+ assert_equal(795652, event.id)
27
+ assert_equal(422800, event.order_id)
28
+ assert_equal('Approver Confirmed', event.name)
29
+ assert_equal(DateTime.parse('2009-08-12T16:38:14-04:00'), event.created_at)
30
+ end
31
+ end
32
+
33
+ should 'modify the queried window of time' do
34
+ managed_server_request :get, '/events.xml?start_at=2009-01-01T00:00:00+00:00&end_at=2009-01-02T00:00:00+00:00', :response => Responses::Event::All do
35
+ GeoCerts::Event.all(:start_at => DateTime.parse('2009-01-01T00:00:00Z'), :end_at => DateTime.parse('2009-01-02T00:00:00Z'))
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ context 'find' do
42
+
43
+ setup do
44
+ managed_server_request :get, '/orders.xml', :response => Responses::Order::All do
45
+ @order_id = GeoCerts::Order.all.first.id
46
+ end
47
+ end
48
+
49
+ should 'return a collection of GeoCerts::Events' do
50
+ managed_server_request :get, "/orders/#{@order_id}/events.xml", :response => Responses::Event::Order do
51
+ events = GeoCerts::Event.find(@order_id)
52
+ assert_kind_of(GeoCerts::Collection, events)
53
+ assert events.all? { |event| event.kind_of?(GeoCerts::Event) }
54
+ end
55
+ end
56
+
57
+ should 'all reference the same order' do
58
+ managed_server_request :get, "/orders/#{@order_id}/events.xml", :response => Responses::Event::Order do
59
+ assert GeoCerts::Event.find(@order_id).all? { |event| event.order_id == @order_id }
60
+ end
61
+ end
62
+
63
+ should 'return 2 events' do
64
+ exclusively_mocked_request :get, '/orders/422815/events.xml', :response => Responses::Event::Order do
65
+ assert_equal(2, GeoCerts::Event.find(422815).size)
66
+ end
67
+ end
68
+
69
+ should 'properly populate the events' do
70
+ exclusively_mocked_request :get, '/orders/422815/events.xml', :response => Responses::Event::Order do
71
+ event = GeoCerts::Event.find(422815).first
72
+ assert_equal(795652, event.id)
73
+ assert_equal(422815, event.order_id)
74
+ assert_equal('Approver Confirmed', event.name)
75
+ assert_equal(DateTime.parse('2009-08-12T16:38:14-04:00'), event.created_at)
76
+ end
77
+ end
78
+
79
+ should 'be accessible via a GeoCerts::Order' do
80
+ exclusively_mocked_request :get, "/orders/422815.xml", :response => Responses::Order::Order do
81
+ exclusively_mocked_request :get, '/orders/422815/events.xml', :response => Responses::Event::Order do
82
+ assert_kind_of(GeoCerts::Event, GeoCerts::Order.find(422815).events.first)
83
+ end
84
+ end
85
+ end
86
+
87
+ should 'modify the queried window of time' do
88
+ exclusively_mocked_request :get, '/orders/422815/events.xml?start_at=2009-01-01T00:00:00+00:00&end_at=2009-01-02T00:00:00+00:00', :response => Responses::Certificate::All do
89
+ GeoCerts::Event.find(422815, :start_at => DateTime.parse('2009-01-01T00:00:00Z'), :end_at => DateTime.parse('2009-01-02T00:00:00Z'))
90
+ end
91
+ end
92
+
93
+ should 'raise a GeoCerts::ResourceNotFound error' do
94
+ managed_server_request :get, '/orders/422815/events.xml', :response => Responses::InvalidOrderId do
95
+ assert_responds_with_exception(GeoCerts::ResourceNotFound, -90004) do
96
+ GeoCerts::Event.find(422815)
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ context 'find_by_order_id' do
104
+
105
+ setup do
106
+ managed_server_request :get, '/orders.xml', :response => Responses::Order::All do
107
+ @order_id = GeoCerts::Order.all.first.id
108
+ end
109
+ end
110
+
111
+ should 'return a collection of GeoCerts::Events' do
112
+ managed_server_request :get, "/orders/#{@order_id}/events.xml", :response => Responses::Event::Order do
113
+ events = GeoCerts::Event.find_by_order_id(@order_id)
114
+ assert_kind_of(GeoCerts::Collection, events)
115
+ assert events.all? { |event| event.kind_of?(GeoCerts::Event) }
116
+ end
117
+ end
118
+
119
+ should 'all reference the same order' do
120
+ managed_server_request :get, "/orders/#{@order_id}/events.xml", :response => Responses::Event::Order do
121
+ assert GeoCerts::Event.find_by_order_id(@order_id).all? { |event| event.order_id == @order_id }
122
+ end
123
+ end
124
+
125
+ should 'return 2 events' do
126
+ exclusively_mocked_request :get, '/orders/422815/events.xml', :response => Responses::Event::Order do
127
+ assert_equal(2, GeoCerts::Event.find_by_order_id(422815).size)
128
+ end
129
+ end
130
+
131
+ should 'properly populate the events' do
132
+ exclusively_mocked_request :get, '/orders/422815/events.xml', :response => Responses::Event::Order do
133
+ event = GeoCerts::Event.find_by_order_id(422815).first
134
+ assert_equal(795652, event.id)
135
+ assert_equal(422815, event.order_id)
136
+ assert_equal('Approver Confirmed', event.name)
137
+ assert_equal(DateTime.parse('2009-08-12T16:38:14-04:00'), event.created_at)
138
+ end
139
+ end
140
+
141
+ should 'be accessible via a GeoCerts::Order' do
142
+ exclusively_mocked_request :get, "/orders/422815.xml", :response => Responses::Order::Order do
143
+ exclusively_mocked_request :get, '/orders/422815/events.xml', :response => Responses::Event::Order do
144
+ assert_kind_of(GeoCerts::Event, GeoCerts::Order.find(422815).events.first)
145
+ end
146
+ end
147
+ end
148
+
149
+ should 'modify the queried window of time' do
150
+ exclusively_mocked_request :get, '/orders/422815/events.xml?start_at=2009-01-01T00:00:00+00:00&end_at=2009-01-02T00:00:00+00:00', :response => Responses::Certificate::All do
151
+ GeoCerts::Event.find_by_order_id(422815, :start_at => DateTime.parse('2009-01-01T00:00:00Z'), :end_at => DateTime.parse('2009-01-02T00:00:00Z'))
152
+ end
153
+ end
154
+
155
+ should 'not raise a GeoCerts::ResourceNotFound error, instead returning an empty set' do
156
+ managed_server_request :get, '/orders/422815/events.xml', :response => Responses::InvalidOrderId do
157
+ assert_responds_without_exception(GeoCerts::ResourceNotFound) do
158
+ assert_equal([], GeoCerts::Event.find_by_order_id(422815))
159
+ end
160
+ end
161
+ end
162
+
163
+ end
164
+
165
+ end
166
+
167
+ end