3 class BlobTest < ActiveSupport::TestCase
4 @@api_token = rand(2**512).to_s(36)[0..49]
5 @@key = rand(2**2048).to_s(36)
7 @@blob_locator = Digest::MD5.hexdigest(@@blob_data) +
8 '+' + @@blob_data.size.to_s
11 signed = Blob.sign_locator @@blob_locator, api_token: @@api_token, key: @@key
12 assert_equal true, Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
16 signed = Blob.sign_locator @@blob_locator, api_token: @@api_token, key: @@key, ttl: -1
17 assert_raise Blob::InvalidSignatureError do
18 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
22 test 'expired, but no raise' do
23 signed = Blob.sign_locator @@blob_locator, api_token: @@api_token, key: @@key, ttl: -1
24 assert_equal false, Blob.verify_signature(signed,
25 api_token: @@api_token,
29 test 'bogus, wrong block hash' do
30 signed = Blob.sign_locator @@blob_locator, api_token: @@api_token, key: @@key
31 assert_raise Blob::InvalidSignatureError do
32 Blob.verify_signature!(signed.sub('acbd','abcd'), api_token: @@api_token, key: @@key)
36 test 'bogus, expired' do
37 signed = 'acbd18db4cc2f85cedef654fccc4a4d8+3+Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@531641bf'
38 assert_raises Blob::InvalidSignatureError do
39 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
43 test 'bogus, wrong key' do
44 signed = Blob.sign_locator(@@blob_locator,
45 api_token: @@api_token,
47 assert_raise Blob::InvalidSignatureError do
48 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
52 test 'bogus, wrong api token' do
53 signed = Blob.sign_locator(@@blob_locator,
54 api_token: @@api_token.reverse,
56 assert_raise Blob::InvalidSignatureError do
57 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
61 test 'bogus, signature format 1' do
62 signed = 'acbd18db4cc2f85cedef654fccc4a4d8+3+Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@'
63 assert_raise Blob::InvalidSignatureError do
64 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
68 test 'bogus, signature format 2' do
69 signed = 'acbd18db4cc2f85cedef654fccc4a4d8+3+A@531641bf'
70 assert_raise Blob::InvalidSignatureError do
71 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
75 test 'bogus, signature format 3' do
76 signed = 'acbd18db4cc2f85cedef654fccc4a4d8+3+Axyzzy@531641bf'
77 assert_raise Blob::InvalidSignatureError do
78 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
82 test 'bogus, timestamp format' do
83 signed = 'acbd18db4cc2f85cedef654fccc4a4d8+3+Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@xyzzy'
84 assert_raise Blob::InvalidSignatureError do
85 Blob.verify_signature!(signed, api_token: @@api_token, key: @@key)
89 test 'no signature at all' do
90 assert_raise Blob::InvalidSignatureError do
91 Blob.verify_signature!(@@blob_locator, api_token: @@api_token, key: @@key)