prevoty 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +8 -0
- data/lib/prevoty.rb +31 -0
- data/lib/prevoty/client.rb +341 -0
- data/lib/prevoty/crypto.rb +33 -0
- data/lib/prevoty/exceptions/account_quota_exceeded.rb +4 -0
- data/lib/prevoty/exceptions/bad_api_key.rb +4 -0
- data/lib/prevoty/exceptions/bad_input_parameter.rb +4 -0
- data/lib/prevoty/exceptions/internal_error.rb +4 -0
- data/lib/prevoty/hash.rb +12 -0
- data/lib/prevoty/pattern.rb +18 -0
- data/lib/prevoty/responses/api_key_info.rb +12 -0
- data/lib/prevoty/responses/decrypt_result.rb +9 -0
- data/lib/prevoty/responses/delete_token.rb +10 -0
- data/lib/prevoty/responses/ecdsa_private_key.rb +19 -0
- data/lib/prevoty/responses/ecdsa_public_key.rb +19 -0
- data/lib/prevoty/responses/ecdsa_signature.rb +17 -0
- data/lib/prevoty/responses/encrypt_result.rb +25 -0
- data/lib/prevoty/responses/filter_content.rb +11 -0
- data/lib/prevoty/responses/filter_statistics.rb +28 -0
- data/lib/prevoty/responses/generate_token.rb +10 -0
- data/lib/prevoty/responses/hash_result.rb +9 -0
- data/lib/prevoty/responses/input_validation.rb +10 -0
- data/lib/prevoty/responses/query_analysis.rb +87 -0
- data/lib/prevoty/responses/rsa_private_key.rb +22 -0
- data/lib/prevoty/responses/rsa_public_key.rb +17 -0
- data/lib/prevoty/responses/rsa_signature.rb +15 -0
- data/lib/prevoty/responses/signature_verify.rb +13 -0
- data/lib/prevoty/responses/validate_token.rb +10 -0
- data/lib/prevoty/version.rb +3 -0
- data/prevoty.gemspec +25 -0
- data/test/specs/client_spec.rb +563 -0
- data/test/test_helper.rb +10 -0
- metadata +124 -0
data/prevoty.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'prevoty/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "prevoty"
|
8
|
+
spec.version = Prevoty::VERSION
|
9
|
+
spec.authors = ["Joe Rozner"]
|
10
|
+
spec.email = ["joe@prevoty.com"]
|
11
|
+
spec.summary = %q{Pevoty API client for Ruby}
|
12
|
+
spec.description = %q{Implementation of the Prevoty API}
|
13
|
+
spec.homepage = "https://www.prevoty.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty", "~> 0.13"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,563 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Prevoty::Client do
|
4
|
+
it 'should throw BadInputParameter for verify_api_key without an api key' do
|
5
|
+
client = Prevoty::Client.new(nil)
|
6
|
+
assert_raises Prevoty::BadInputParameter do
|
7
|
+
client.verify_api_key
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should throw BadAPIKey for verify_api_key with an invalid api key' do
|
12
|
+
client = Prevoty::Client.new('badapikey')
|
13
|
+
assert_raises Prevoty::BadAPIKey do
|
14
|
+
client.verify_api_key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return true for verify_api_key with a valid api key' do
|
19
|
+
client = Prevoty::Client.new(API_KEY)
|
20
|
+
response = client.verify_api_key
|
21
|
+
response.must_equal true
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should throw BadInputParameter for api_key_info without an api key' do
|
25
|
+
client = Prevoty::Client.new('')
|
26
|
+
assert_raises Prevoty::BadInputParameter do
|
27
|
+
client.api_key_info
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should throw BadAPIKey for api_key_info with an invalid api key' do
|
32
|
+
client = Prevoty::Client.new('badapikey')
|
33
|
+
assert_raises Prevoty::BadAPIKey do
|
34
|
+
client.api_key_info
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return an APIKeyInfo for api_key_info with a valid api key' do
|
39
|
+
client = Prevoty::Client.new(API_KEY)
|
40
|
+
response = client.api_key_info
|
41
|
+
response.class.must_equal Prevoty::APIKeyInfo
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should throw BadInputParameter for verify_content_configuration without an api key' do
|
45
|
+
client = Prevoty::Client.new('')
|
46
|
+
assert_raises Prevoty::BadInputParameter do
|
47
|
+
client.verify_content_configuration('')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should throw BadAPIKey for verify_content_configuration with an invalid api key' do
|
52
|
+
client = Prevoty::Client.new('badapikey')
|
53
|
+
assert_raises Prevoty::BadAPIKey do
|
54
|
+
client.verify_content_configuration('')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should throw BadInputParameter for verify_content_configuration with an invalid api key' do
|
59
|
+
client = Prevoty::Client.new(API_KEY)
|
60
|
+
assert_raises Prevoty::BadInputParameter do
|
61
|
+
client.verify_content_configuration('badkey')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return true for verify_content_configuration with a valid api key' do
|
66
|
+
client = Prevoty::Client.new(API_KEY)
|
67
|
+
response = client.verify_content_configuration(CONTENT_KEY)
|
68
|
+
response.must_equal true
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should throw BadInputParameter for filter_content without an api key' do
|
72
|
+
client = Prevoty::Client.new('')
|
73
|
+
assert_raises Prevoty::BadInputParameter do
|
74
|
+
client.filter_content(CONTENT_PAYLOAD, '')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should throw BadAPIKey for filter_content with an invalid api key' do
|
79
|
+
client = Prevoty::Client.new('badapikey')
|
80
|
+
assert_raises Prevoty::BadAPIKey do
|
81
|
+
client.filter_content(CONTENT_PAYLOAD, '')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should throw BadInputParameter for filter_content with an invalid content key' do
|
86
|
+
client = Prevoty::Client.new(API_KEY)
|
87
|
+
assert_raises Prevoty::BadInputParameter do
|
88
|
+
client.filter_content(CONTENT_PAYLOAD, 'badkey')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should return a valid response for filter_content with a valid api key and content_key' do
|
93
|
+
client = Prevoty::Client.new(API_KEY)
|
94
|
+
response = client.filter_content(CONTENT_PAYLOAD, CONTENT_KEY)
|
95
|
+
response.class.must_equal Prevoty::FilterContent
|
96
|
+
response.statistics.class.must_equal Prevoty::FilterStatistics
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should throw BadInputParameter for bulk_filter without an api key' do
|
100
|
+
client = Prevoty::Client.new('')
|
101
|
+
assert_raises Prevoty::BadInputParameter do
|
102
|
+
client.bulk_filter(CONTENT_PAYLOAD, '')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should throw BadAPIKey for bulk_filter with an invalid api key' do
|
107
|
+
client = Prevoty::Client.new('badapikey')
|
108
|
+
assert_raises Prevoty::BadAPIKey do
|
109
|
+
client.bulk_filter(CONTENT_PAYLOAD, '')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should throw BadInputParameter for bulk_filter with an invalid content key' do
|
114
|
+
client = Prevoty::Client.new(API_KEY)
|
115
|
+
assert_raises Prevoty::BadInputParameter do
|
116
|
+
client.bulk_filter(CONTENT_PAYLOAD, 'badkey')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should return a valid response for bulk_filter with a valid api key and content_key' do
|
121
|
+
client = Prevoty::Client.new(API_KEY)
|
122
|
+
response = client.bulk_filter(CONTENT_PAYLOAD, CONTENT_KEY)
|
123
|
+
response.class.must_equal Prevoty::FilterContent
|
124
|
+
response.statistics.class.must_equal Prevoty::FilterStatistics
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should throw BadInputParameter for generate_timed_token without an api key' do
|
128
|
+
client = Prevoty::Client.new('')
|
129
|
+
assert_raises Prevoty::BadInputParameter do
|
130
|
+
client.generate_timed_token('id', 'action', 3600)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should throw BadAPIKey for generate_timed_token with an invalid api key' do
|
135
|
+
client = Prevoty::Client.new('badapikey')
|
136
|
+
assert_raises Prevoty::BadAPIKey do
|
137
|
+
client.generate_timed_token('id', 'action', 3600)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should throw BadInputParameter for validate_timed_token without an api key' do
|
142
|
+
client = Prevoty::Client.new('')
|
143
|
+
assert_raises Prevoty::BadInputParameter do
|
144
|
+
client.validate_timed_token('id', 'action', 3600)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should throw BadAPIKey for validate_timed_token with an invalid api key' do
|
149
|
+
client = Prevoty::Client.new('badapikey')
|
150
|
+
assert_raises Prevoty::BadAPIKey do
|
151
|
+
client.validate_timed_token('id', 'action', 3600)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should throw BadInputParameter for delete_timed_token without an api key' do
|
156
|
+
client = Prevoty::Client.new('')
|
157
|
+
assert_raises Prevoty::BadInputParameter do
|
158
|
+
client.delete_timed_token('id', 'action', 3600)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should throw BadAPIKey for delete_timed_token with an invalid api key' do
|
163
|
+
client = Prevoty::Client.new('badapikey')
|
164
|
+
assert_raises Prevoty::BadAPIKey do
|
165
|
+
client.delete_timed_token('id', 'action', 3600)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should generate and validate a timed token' do
|
170
|
+
client = Prevoty::Client.new(API_KEY)
|
171
|
+
response = client.generate_timed_token('id', 'action', 3600)
|
172
|
+
response.class.must_equal Prevoty::GenerateToken
|
173
|
+
response = client.validate_timed_token('id', 'action', response.token)
|
174
|
+
response.class.must_equal Prevoty::ValidateToken
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should generate and delete a timed token' do
|
178
|
+
client = Prevoty::Client.new(API_KEY)
|
179
|
+
response = client.generate_timed_token('id', 'action', 3600)
|
180
|
+
response.class.must_equal Prevoty::GenerateToken
|
181
|
+
response = client.delete_timed_token('id', 'action', response.token)
|
182
|
+
response.class.must_equal Prevoty::DeleteToken
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
it 'should throw BadInputParameter for generate_persisted_token without an api key' do
|
188
|
+
client = Prevoty::Client.new('')
|
189
|
+
assert_raises Prevoty::BadInputParameter do
|
190
|
+
client.generate_persisted_token('id', 'action')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should throw BadAPIKey for generate_persisted_token with an invalid api key' do
|
195
|
+
client = Prevoty::Client.new('badapikey')
|
196
|
+
assert_raises Prevoty::BadAPIKey do
|
197
|
+
client.generate_persisted_token('id', 'action')
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should throw BadInputParameter for validate_persisted_token without an api key' do
|
202
|
+
client = Prevoty::Client.new('')
|
203
|
+
assert_raises Prevoty::BadInputParameter do
|
204
|
+
client.validate_persisted_token('id', 'action', 'token')
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should throw BadAPIKey for validate_persisted_token with an invalid api key' do
|
209
|
+
client = Prevoty::Client.new('badapikey')
|
210
|
+
assert_raises Prevoty::BadAPIKey do
|
211
|
+
client.validate_persisted_token('id', 'action', 'token')
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should throw BadInputParameter for delete_persisted_token without an api key' do
|
216
|
+
client = Prevoty::Client.new('')
|
217
|
+
assert_raises Prevoty::BadInputParameter do
|
218
|
+
client.delete_persisted_token('id', 'action', 'token')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should throw BadAPIKey for delete_persisted_token with an invalid api key' do
|
223
|
+
client = Prevoty::Client.new('badapikey')
|
224
|
+
assert_raises Prevoty::BadAPIKey do
|
225
|
+
client.delete_persisted_token('id', 'action', 'token')
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should generate and validate a persisted token' do
|
230
|
+
client = Prevoty::Client.new(API_KEY)
|
231
|
+
response = client.generate_persisted_token('id', 'action')
|
232
|
+
response.class.must_equal Prevoty::GenerateToken
|
233
|
+
response = client.validate_persisted_token('id', 'action', response.token)
|
234
|
+
response.class.must_equal Prevoty::ValidateToken
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'should generate and delete a persisted token' do
|
238
|
+
client = Prevoty::Client.new(API_KEY)
|
239
|
+
response = client.generate_persisted_token('id', 'action')
|
240
|
+
response.class.must_equal Prevoty::GenerateToken
|
241
|
+
response = client.delete_persisted_token('id', 'action', response.token)
|
242
|
+
response.class.must_equal Prevoty::DeleteToken
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should throw BadInputParameter for analyze_query without an api key' do
|
246
|
+
client = Prevoty::Client.new('')
|
247
|
+
assert_raises Prevoty::BadInputParameter do
|
248
|
+
client.analyze_query(CONTENT_PAYLOAD, '')
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'should throw BadAPIKey for analyze_query with an invalid api key' do
|
253
|
+
client = Prevoty::Client.new('badapikey')
|
254
|
+
assert_raises Prevoty::BadAPIKey do
|
255
|
+
client.analyze_query(CONTENT_PAYLOAD, '')
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'should throw BadInputParameter for analyze_query with an invalid query key' do
|
260
|
+
client = Prevoty::Client.new(API_KEY)
|
261
|
+
assert_raises Prevoty::BadInputParameter do
|
262
|
+
client.analyze_query(CONTENT_PAYLOAD, 'badkey')
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'should return a valid response for analyze_query with a valid api key and query_key' do
|
267
|
+
client = Prevoty::Client.new(API_KEY)
|
268
|
+
response = client.analyze_query(QUERY_PAYLOAD, QUERY_KEY)
|
269
|
+
response.class.must_equal Prevoty::QueryAnalysis
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
it 'should throw BadInputParameter for validate_pattern without an api key' do
|
274
|
+
client = Prevoty::Client.new('')
|
275
|
+
assert_raises Prevoty::BadInputParameter do
|
276
|
+
client.validate_pattern(Prevoty::Pattern::NUMERIC, '')
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should throw BadAPIKey for validate_pattern with an invalid api key' do
|
281
|
+
client = Prevoty::Client.new('badapikey')
|
282
|
+
assert_raises Prevoty::BadAPIKey do
|
283
|
+
client.validate_pattern(Prevoty::Pattern::NUMERIC, '')
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'should throw BadInputParameter for validate_pattern with an invalid pattern' do
|
288
|
+
client = Prevoty::Client.new(API_KEY)
|
289
|
+
response = client.validate_pattern('badpattern', '12345')
|
290
|
+
response.matched.must_equal false
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'should return a valid response for validate_pattern' do
|
294
|
+
client = Prevoty::Client.new(API_KEY)
|
295
|
+
response = client.validate_pattern(Prevoty::Pattern::NUMERIC, '12345')
|
296
|
+
response.class.must_equal Prevoty::InputValidation
|
297
|
+
response.matched.must_equal true
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'should throw BadInputParameter for validate_string without an api key' do
|
301
|
+
client = Prevoty::Client.new('')
|
302
|
+
assert_raises Prevoty::BadInputParameter do
|
303
|
+
client.validate_string('test', 0, 5, 4)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'should throw BadAPIKey for validate_string with an invalid api key' do
|
308
|
+
client = Prevoty::Client.new('badapikey')
|
309
|
+
assert_raises Prevoty::BadAPIKey do
|
310
|
+
client.validate_string('test', 0, 5, 4)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'should return a valid response for validate_string' do
|
315
|
+
client = Prevoty::Client.new(API_KEY)
|
316
|
+
response = client.validate_string('test', 0, 5, 4)
|
317
|
+
response.class.must_equal Prevoty::InputValidation
|
318
|
+
response.matched.must_equal true
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
it 'should throw BadInputParameter for hash without an api key' do
|
323
|
+
client = Prevoty::Client.new('')
|
324
|
+
assert_raises Prevoty::BadInputParameter do
|
325
|
+
client.hash('test', Prevoty::Hash::MD5)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'should throw BadAPIKey for hash with an invalid api key' do
|
330
|
+
client = Prevoty::Client.new('badapikey')
|
331
|
+
assert_raises Prevoty::BadAPIKey do
|
332
|
+
client.hash('test', Prevoty::Hash::MD5)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'should return a valid response for hash with a valid api key and hash' do
|
337
|
+
client = Prevoty::Client.new(API_KEY)
|
338
|
+
response = client.hash('test', Prevoty::Hash::MD5)
|
339
|
+
response.class.must_equal Prevoty::HashResult
|
340
|
+
response.hash.must_equal Digest::MD5.hexdigest('test')
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'should throw BadInputParameter for encrypt without an api key' do
|
344
|
+
client = Prevoty::Client.new('')
|
345
|
+
assert_raises Prevoty::BadInputParameter do
|
346
|
+
client.encrypt('test', Prevoty::Crypto::Algorithms::AES, Prevoty::Crypto::Modes::CBC)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'should throw BadAPIKey for encrypt with an invalid api key' do
|
351
|
+
client = Prevoty::Client.new('badapikey')
|
352
|
+
assert_raises Prevoty::BadAPIKey do
|
353
|
+
client.encrypt('test', Prevoty::Crypto::Algorithms::AES, Prevoty::Crypto::Modes::CBC)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'should return a valid response for encrypt with a valid api key' do
|
358
|
+
client = Prevoty::Client.new(API_KEY)
|
359
|
+
response = client.encrypt('testtesttesttesttesttesttesttest', Prevoty::Crypto::Algorithms::AES, Prevoty::Crypto::Modes::CBC)
|
360
|
+
response.class.must_equal Prevoty::EncryptResult
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'should throw BadInputParameter for decrypt without an api key' do
|
364
|
+
client = Prevoty::Client.new('')
|
365
|
+
assert_raises Prevoty::BadInputParameter do
|
366
|
+
client.decrypt(Prevoty::EncryptResult.new({}))
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
it 'should throw BadAPIKey for decrypt with an invalid api key' do
|
371
|
+
client = Prevoty::Client.new('badapikey')
|
372
|
+
assert_raises Prevoty::BadAPIKey do
|
373
|
+
client.decrypt(Prevoty::EncryptResult.new({}))
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'should return a valid response for decrypt with a valid api key' do
|
378
|
+
client = Prevoty::Client.new(API_KEY)
|
379
|
+
response = client.encrypt('testtesttesttesttesttesttesttest', Prevoty::Crypto::Algorithms::AES, Prevoty::Crypto::Modes::CBC)
|
380
|
+
response.class.must_equal Prevoty::EncryptResult
|
381
|
+
response = client.decrypt(response)
|
382
|
+
response.class.must_equal Prevoty::DecryptResult
|
383
|
+
response.plain_text.must_equal 'testtesttesttesttesttesttesttest'
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'should throw BadInputParameter for generate_rsa_keypair without an api key' do
|
387
|
+
client = Prevoty::Client.new('')
|
388
|
+
assert_raises Prevoty::BadInputParameter do
|
389
|
+
client.generate_rsa_keypair(1024)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'should throw BadAPIKey for generate_rsa_keypair with an invalid api key' do
|
394
|
+
client = Prevoty::Client.new('badapikey')
|
395
|
+
assert_raises Prevoty::BadAPIKey do
|
396
|
+
client.generate_rsa_keypair(1024)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
it 'should return a valid response for generate_rsa_keypair with a valid api key' do
|
401
|
+
client = Prevoty::Client.new(API_KEY)
|
402
|
+
response = client.generate_rsa_keypair(1024)
|
403
|
+
response.class.must_equal Prevoty::RSAPrivateKey
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'should throw BadInputParameter for generate_ecdsa_keypair without an api key' do
|
407
|
+
client = Prevoty::Client.new('')
|
408
|
+
assert_raises Prevoty::BadInputParameter do
|
409
|
+
client.generate_ecdsa_keypair(Prevoty::Crypto::Curves::P224)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'should throw BadAPIKey for generate_ecdsa_keypair with an invalid api key' do
|
414
|
+
client = Prevoty::Client.new('badapikey')
|
415
|
+
assert_raises Prevoty::BadAPIKey do
|
416
|
+
client.generate_ecdsa_keypair(Prevoty::Crypto::Curves::P224)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'should return a valid response for generate_ecdsa_keypair with a valid api key' do
|
421
|
+
client = Prevoty::Client.new(API_KEY)
|
422
|
+
response = client.generate_ecdsa_keypair(Prevoty::Crypto::Curves::P224)
|
423
|
+
response.class.must_equal Prevoty::ECDSAPrivateKey
|
424
|
+
end
|
425
|
+
|
426
|
+
it 'should throw BadInputParameter for rsa_pss_signature without an api key' do
|
427
|
+
client = Prevoty::Client.new('')
|
428
|
+
assert_raises Prevoty::BadInputParameter do
|
429
|
+
client.rsa_pss_signature('test', Prevoty::Hash::SHA1, Prevoty::RSAPrivateKey.new({}), nil)
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should throw BadAPIKey for rsa_pss_signature with an invalid api key' do
|
434
|
+
client = Prevoty::Client.new('badapikey')
|
435
|
+
assert_raises Prevoty::BadAPIKey do
|
436
|
+
client.rsa_pss_signature('test', Prevoty::Hash::SHA1, Prevoty::RSAPrivateKey.new({}), nil)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
it 'should return a valid response for rsa_pss_signature with a valid api key' do
|
441
|
+
client = Prevoty::Client.new(API_KEY)
|
442
|
+
response = client.generate_rsa_keypair(1024)
|
443
|
+
response.class.must_equal Prevoty::RSAPrivateKey
|
444
|
+
response = client.rsa_pss_signature('test', Prevoty::Hash::SHA1, response, Prevoty::Crypto::PSSSaltOptions::PSSSaltLengthAuto)
|
445
|
+
response.class.must_equal Prevoty::RSASignature
|
446
|
+
end
|
447
|
+
|
448
|
+
it 'should throw BadInputParameter for rsa_pkcs_signature without an api key' do
|
449
|
+
client = Prevoty::Client.new('')
|
450
|
+
assert_raises Prevoty::BadInputParameter do
|
451
|
+
client.rsa_pkcs_signature('test', Prevoty::Hash::SHA1, Prevoty::RSAPrivateKey.new({}))
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
it 'should throw BadAPIKey for rsa_pkcs_signature with an invalid api key' do
|
456
|
+
client = Prevoty::Client.new('badapikey')
|
457
|
+
assert_raises Prevoty::BadAPIKey do
|
458
|
+
client.rsa_pkcs_signature('test', Prevoty::Hash::SHA1, Prevoty::RSAPrivateKey.new({}))
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
it 'should return a valid response for rsa_pkcs_signature with a valid api key' do
|
463
|
+
client = Prevoty::Client.new(API_KEY)
|
464
|
+
response = client.generate_rsa_keypair(1024)
|
465
|
+
response.class.must_equal Prevoty::RSAPrivateKey
|
466
|
+
response = client.rsa_pkcs_signature('test', Prevoty::Hash::SHA1, response)
|
467
|
+
response.class.must_equal Prevoty::RSASignature
|
468
|
+
end
|
469
|
+
|
470
|
+
it 'should throw BadInputParameter for ecdsa_signature without an api key' do
|
471
|
+
client = Prevoty::Client.new('')
|
472
|
+
assert_raises Prevoty::BadInputParameter do
|
473
|
+
client.ecdsa_signature('test', Prevoty::Hash::SHA1, Prevoty::ECDSAPrivateKey.new({}))
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
it 'should throw BadAPIKey for ecdsa_signature with an invalid api key' do
|
478
|
+
client = Prevoty::Client.new('badapikey')
|
479
|
+
assert_raises Prevoty::BadAPIKey do
|
480
|
+
client.ecdsa_signature('test', Prevoty::Hash::SHA1, Prevoty::ECDSAPrivateKey.new({}))
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
it 'should return a valid response for ecdsa_signature with a valid api key' do
|
485
|
+
client = Prevoty::Client.new(API_KEY)
|
486
|
+
response = client.generate_ecdsa_keypair(Prevoty::Crypto::Curves::P224)
|
487
|
+
response.class.must_equal Prevoty::ECDSAPrivateKey
|
488
|
+
response = client.ecdsa_signature('test', Prevoty::Hash::SHA1, response)
|
489
|
+
response.class.must_equal Prevoty::ECDSASignature
|
490
|
+
end
|
491
|
+
|
492
|
+
it 'should throw BadInputParameter for verify_rsa_pss_signature without an api key' do
|
493
|
+
client = Prevoty::Client.new('')
|
494
|
+
assert_raises Prevoty::BadInputParameter do
|
495
|
+
client.rsa_pss_signature('test', Prevoty::Hash::SHA1, Prevoty::SignatureVerify.new({}), Prevoty::Crypto::PSSSaltOptions::PSSSaltLengthAuto)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
it 'should throw BadAPIKey for verify_rsa_pss_signature with an invalid api key' do
|
500
|
+
client = Prevoty::Client.new('badapikey')
|
501
|
+
assert_raises Prevoty::BadAPIKey do
|
502
|
+
client.rsa_pss_signature('test', Prevoty::Hash::SHA1, Prevoty::SignatureVerify.new({}), Prevoty::Crypto::PSSSaltOptions::PSSSaltLengthAuto)
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
it 'should return a valid response for verify_rsa_pss_signature with a valid api key' do
|
507
|
+
client = Prevoty::Client.new(API_KEY)
|
508
|
+
key = client.generate_rsa_keypair(1024)
|
509
|
+
key.class.must_equal Prevoty::RSAPrivateKey
|
510
|
+
response = client.rsa_pss_signature('test', Prevoty::Hash::SHA1, key, Prevoty::Crypto::PSSSaltOptions::PSSSaltLengthAuto)
|
511
|
+
response.class.must_equal Prevoty::RSASignature
|
512
|
+
response = client.verify_rsa_pss_signature('test', Prevoty::Hash::SHA1, key, response, Prevoty::Crypto::PSSSaltOptions::PSSSaltLengthAuto)
|
513
|
+
response.class.must_equal Prevoty::SignatureVerify
|
514
|
+
end
|
515
|
+
|
516
|
+
it 'should throw BadInputParameter for verify_rsa_pkcs_signature without an api key' do
|
517
|
+
client = Prevoty::Client.new('')
|
518
|
+
assert_raises Prevoty::BadInputParameter do
|
519
|
+
client.rsa_pkcs_signature('test', Prevoty::Hash::SHA1, Prevoty::SignatureVerify.new({}))
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
it 'should throw BadAPIKey for verify_rsa_pkcs_signature with an invalid api key' do
|
524
|
+
client = Prevoty::Client.new('badapikey')
|
525
|
+
assert_raises Prevoty::BadAPIKey do
|
526
|
+
client.rsa_pkcs_signature('test', Prevoty::Hash::SHA1, Prevoty::SignatureVerify.new({}))
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
it 'should return a valid response for verify_rsa_pss_signature with a valid api key' do
|
531
|
+
client = Prevoty::Client.new(API_KEY)
|
532
|
+
key = client.generate_rsa_keypair(1024)
|
533
|
+
key.class.must_equal Prevoty::RSAPrivateKey
|
534
|
+
response = client.rsa_pkcs_signature('test', Prevoty::Hash::SHA1, key)
|
535
|
+
response.class.must_equal Prevoty::RSASignature
|
536
|
+
response = client.verify_rsa_pkcs_signature('test', Prevoty::Hash::SHA1, key, response)
|
537
|
+
response.class.must_equal Prevoty::SignatureVerify
|
538
|
+
end
|
539
|
+
|
540
|
+
it 'should throw BadInputParameter for verify_ecdsa_signature without an api key' do
|
541
|
+
client = Prevoty::Client.new('')
|
542
|
+
assert_raises Prevoty::BadInputParameter do
|
543
|
+
client.ecdsa_signature('test', Prevoty::Hash::SHA1, Prevoty::SignatureVerify.new({}))
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
it 'should throw BadAPIKey for verify_ecdsa_signature with an invalid api key' do
|
548
|
+
client = Prevoty::Client.new('badapikey')
|
549
|
+
assert_raises Prevoty::BadAPIKey do
|
550
|
+
client.ecdsa_signature('test', Prevoty::Hash::SHA1, Prevoty::SignatureVerify.new({}))
|
551
|
+
end
|
552
|
+
end
|
553
|
+
|
554
|
+
it 'should return a valid response for verify_ecdsa_signature with a valid api key' do
|
555
|
+
client = Prevoty::Client.new(API_KEY)
|
556
|
+
key = client.generate_ecdsa_keypair(Prevoty::Crypto::Curves::P224)
|
557
|
+
key.class.must_equal Prevoty::ECDSAPrivateKey
|
558
|
+
response = client.ecdsa_signature('test', Prevoty::Hash::SHA1, key)
|
559
|
+
response.class.must_equal Prevoty::ECDSASignature
|
560
|
+
response = client.verify_ecdsa_signature('test', Prevoty::Hash::SHA1, key, response)
|
561
|
+
response.class.must_equal Prevoty::SignatureVerify
|
562
|
+
end
|
563
|
+
end
|