megar 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -2
- data/README.rdoc +110 -5
- data/lib/megar.rb +1 -0
- data/lib/megar/adapters.rb +1 -0
- data/lib/megar/adapters/file_downloader.rb +132 -0
- data/lib/megar/catalog/catalog_item.rb +54 -12
- data/lib/megar/catalog/file.rb +13 -0
- data/lib/megar/catalog/files.rb +0 -8
- data/lib/megar/catalog/folder.rb +12 -0
- data/lib/megar/catalog/folders.rb +0 -8
- data/lib/megar/crypto.rb +1 -399
- data/lib/megar/crypto/support.rb +422 -0
- data/lib/megar/exception.rb +3 -0
- data/lib/megar/session.rb +35 -19
- data/lib/megar/shell.rb +21 -3
- data/lib/megar/version.rb +1 -1
- data/spec/fixtures/crypto_expectations/megar_test_sample_1.txt.enc +1 -0
- data/spec/fixtures/crypto_expectations/megar_test_sample_2.png.enc +0 -0
- data/spec/fixtures/crypto_expectations/sample_user.json +90 -6
- data/spec/fixtures/sample_files/megar_test_sample_1.txt +1 -0
- data/spec/fixtures/sample_files/megar_test_sample_2.png +0 -0
- data/spec/support/crypto_expectations_helper.rb +81 -8
- data/spec/support/mocks_helper.rb +26 -4
- data/spec/unit/adapters/file_downloader_spec.rb +100 -0
- data/spec/unit/catalog/file_spec.rb +22 -5
- data/spec/unit/catalog/folder_spec.rb +54 -3
- data/spec/unit/{crypto_spec.rb → crypto/support_spec.rb} +33 -6
- data/spec/unit/exception_spec.rb +8 -0
- data/spec/unit/session_spec.rb +41 -0
- data/spec/unit/shell_spec.rb +28 -0
- metadata +18 -5
data/lib/megar/shell.rb
CHANGED
@@ -27,9 +27,9 @@ class Megar::Shell
|
|
27
27
|
raise "Failed to connect!" unless session.connected?
|
28
28
|
case args.first
|
29
29
|
when /ls/i
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
ls
|
31
|
+
when /get/i
|
32
|
+
get(args[1])
|
33
33
|
else
|
34
34
|
$stderr.puts "Connected!"
|
35
35
|
end
|
@@ -62,6 +62,7 @@ Options:
|
|
62
62
|
Commands:
|
63
63
|
(none) : will perform a basic connection test only
|
64
64
|
ls : returns a full file listing
|
65
|
+
get file_id : downloads the file with id file_id
|
65
66
|
|
66
67
|
Examples:
|
67
68
|
megar --email=my@mail.com --password=MyPassword ls
|
@@ -76,6 +77,23 @@ EOS
|
|
76
77
|
self.class.usage
|
77
78
|
end
|
78
79
|
|
80
|
+
def ls
|
81
|
+
session.files.each do |file|
|
82
|
+
puts file
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def get(file_id)
|
87
|
+
if file = session.files.find_by_id(file_id)
|
88
|
+
$stderr.puts "Downloading #{file_id} to #{file.name}.."
|
89
|
+
File.open(file.name,'wb') do |f|
|
90
|
+
f.write file.body
|
91
|
+
end
|
92
|
+
else
|
93
|
+
$stderr.puts "I couldn't find the file with ID #{file_id}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
79
97
|
def session
|
80
98
|
@session ||= Megar::Session.new(email: email, password: password)
|
81
99
|
end
|
data/lib/megar/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
E�ɐ�^P���@(�d�l�^�j�7��Z�Zc����~
|
Binary file
|
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"email": "megartest@gmail.com",
|
3
3
|
"email_mixed_case": "Megartest@gmail.com",
|
4
|
-
"password": "
|
4
|
+
"password": "ToLlw2D748TqCVAmrc8laio1",
|
5
5
|
"autoconnect": false,
|
6
6
|
"login_response_data": {
|
7
|
-
"csid": "
|
7
|
+
"csid": "CAA1bK6vGGR02BJCb8CfkaeI7F1kIUyvLSXZFXzlFIrsWIp0kw7GgCUZbqN_zE9z4_eV-g5Vl8GyC--TYwUZ1JigVwNPTWEncqk0qdUmmv1SpOcbOu-Z0Z5-GWnTK2oxSp8nKPBn0UGBvf98hQ3KD1uhjEFBrJbNdAgbHc8BGTaYvE0dHNtIE1Zz7bulDDg798Rjj1eGH5bC1vEZDQ_uI7l-wBRtXsCCdXAo6GZEyzr-dcpYInPL-Sy8ZY10RU67E-x_-v_sEUqyN69EHyENk97XzL0arGvXbnGNVH4OhdjynQ1csIlcmvbNQ5kAe9KjJTIT9NeVnmSAjao3AAbIfvRj",
|
8
8
|
"privk": "4Iurk4vQ0BlLEEvEyaRUX8QnYzJFIedm0RVKe2pLh4wTzBBtgmafnszD_dP3Y40P-DSNLEGfWghL-0_BIW4XP8tfGNFkMg7mnYgQYC91ccz58BbhGEDf7-j97dstckf3OSSsT9D9H-cocXzyt1m231w9d7YLX23c3KAGz3vxdnl66F4jsFGO9AdIyb1KTEEt7NHkljtbz3WgWlk6W6wBawuEbJvLPHPx2L16i0iacbbkQi8ZF4pmddswMa9yWOSXwUribGDbdgx_jDGjBoKJUJI-7Aa-aOaRPEoVUTft2R2lNAVErvYwD_GIsIhQiCcJWul-KqPhI3vquvzUHd2rHHvKyTLyvXKyIDeVdBGXTaqFA2ni9xsjUNMOX14ftBZ4_fgDce0jvrZzYRs5IuOMt3K9gKMpBpUWtnlaBYbnYdL2zJuFlrM77PlcYab2uLLqlSe4hh-FxMAc_p_8tDAoU4dPgpgOpU3GRR8i7oszu_MKibzNpRBeAX1UtwKwQepjPnipu9aQlPy9OtgB-5KmGi34EcMKBPg8BN6vHRYg0Za_lk_TtTQ4WbkllAqR3Fla5-RBjzB7f3dWae4ES3VX4f-dI-UYrrKDQkqaS0R_xLaMPNG6_GQMDM7L5Fsa8I3hFjdgfs9rV4Xf_uIFrhUjm25EuT5JCdobNmwBi9VU5nCbk0LQJdrXDNYV3fmD-Y_p_KV8x_-opRnXUV03SCopOD6DhitsFtpv065QXcG1SNDu0mM-kgDh9E-QddtQQtXLLPuKFyX5o1ts08EqXTxHsZo5tIsevbExZoz9hxSRrr-V5swEDcJXoV78_k6sR3iniZ_m77JVo9QU572av2MvNhyu5YeTXyc0m6Me7cPGiO0",
|
9
|
-
"k": "
|
9
|
+
"k": "x1EvGzxu16FpfYajxFSFWQ"
|
10
10
|
},
|
11
11
|
"master_key": [
|
12
12
|
384287193,
|
@@ -14,8 +14,8 @@
|
|
14
14
|
554881366,
|
15
15
|
530403344
|
16
16
|
],
|
17
|
-
"expected_uh": "
|
18
|
-
"sid": "
|
17
|
+
"expected_uh": "4h8kPReRUug",
|
18
|
+
"sid": "tRUhX2shZiPr8hl2KRGXJ3pBOEN6Q2Y5dFp3lh5A8mZnlSFgTcLOChMkLg",
|
19
19
|
"rsa_private_key_b64": "BACOQ7VCjwkiwYCKhqRRvPTMBaQ5Yx2_sszj6ILrxrTBOJ2bu-9LsOSvaGz0HpnM2lXpJg3h6QWJdlQBOhwvfeafHg7rcEaaDuUWONifv5ABpQgeoAij6cgARMvFiOdjarMvu954Eduup8PHcgfjsBSu76qpu3UqkZCpBpByAYU1oQQA1i5oxuA9i7qsXxhJRsBeceI7hZSnNYAQzsWfFD0kDW8GsJBuK-CST6oNNp0z7MQ5Qof6DZ8x9wt5ZJR43HFmD2VtTQUZLvIeemC4URuR74UWn25CETyzQdIhdNSEibaCRvi0sNwb-ikCZVxxo4-O7ZBQPw0egrQOJW06HlCQUykH_00EIoiBRcbJLS6W3nJ8KhddDf_4glZYPz6fBpqu1jIdIBGOGQf4Ttn_DmdAgkLxWF7AF6k59D45J9kxfANRJIBGSWUsI1bQBlrwFtois4O14uQkQ40Jh_d5BCrLPe599zrliGH1SsECx_xYGWcWY_GPsPa99d_St56BB9oUtDW3A1clEx2uVS8OWqRPgVimu6MXs_TEEnjWGRFofHpl_8qGeAoPbNkXsTMQb6uUK4NCYq3UzVfreByEnOqxuQcu2jlF4Ey0UH9w_KjkRyT8xu--kyZAbktYaw4EZmGUxZIlkZLk_OAGaW8KWPZhdGxjfi8K7WeZK2HtLe4At48DC_ED_20pNtkTCrB6-FQlMj6a4O2C1sE6pSdrIPofcK-HpaefOXqYKWpRM-Wnp_qHnuJgEtgodQ-pw74nXkOsVFZoJzVGCepZKoa2xhevAu3CfXMfR97LIski17PPwWV9n7yQ7onSKDmJP-q4mO7PG7LICE22WkgJkk_T1W4UkDTkCxZE_t64F6JOryg",
|
20
20
|
"decomposed_rsa_private_key": [
|
21
21
|
99901518447147034909201847419097315968297147437151469508360346463543063455874100243913856315732601845631262435262260706834732781343251117295631282035669718956849603873760427510697419513879951677293141811802298231979984193675329310799949319780256427743430868153430092107435691279045586737323088097814348379553,
|
@@ -89,6 +89,26 @@
|
|
89
89
|
"k": "zA8CzCf9tZw:Iz6fsJ_qIgmS4uC4eirPnfaZOcLOoQA2t_5wTtfqp7Y",
|
90
90
|
"s": 137080,
|
91
91
|
"ts": 1361697194
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"h": "Cg50GQLT",
|
95
|
+
"p": "ywJVFBKB",
|
96
|
+
"u": "zA8CzCf9tZw",
|
97
|
+
"t": 0,
|
98
|
+
"a": "lv-LcMAl0dvpdxQFWNVZ7m9-mFT79mS0Mi_fH9InTqtBgcpe8kRVDGQ5Hj4BrXrc",
|
99
|
+
"k": "zA8CzCf9tZw:dmnxCL7Z2x3zFcrGcD9FdbUiMJ9EvCCPdGY39whRv2g",
|
100
|
+
"s": 39,
|
101
|
+
"ts": 1361925890
|
102
|
+
},
|
103
|
+
{
|
104
|
+
"h": "S0pkHArB",
|
105
|
+
"p": "ywJVFBKB",
|
106
|
+
"u": "zA8CzCf9tZw",
|
107
|
+
"t": 0,
|
108
|
+
"a": "OFTM18eQGxUTcJP2BQWXBo23vnjqs4b9QzmNZtDqekz4GZESVNiYlqKtasZqdVHN",
|
109
|
+
"k": "zA8CzCf9tZw:cnpz0cav9fLAJHK1TbL3MD5n9R7VvedDwbFRVp4qQh4",
|
110
|
+
"s": 137080,
|
111
|
+
"ts": 1361925899
|
92
112
|
}
|
93
113
|
],
|
94
114
|
"ok": [
|
@@ -104,6 +124,70 @@
|
|
104
124
|
"m": "megartest@gmail.com"
|
105
125
|
}
|
106
126
|
],
|
107
|
-
"sn": "
|
127
|
+
"sn": "2q4ZpNDFGNA"
|
128
|
+
},
|
129
|
+
"sample_files": {
|
130
|
+
"megar_test_sample_1.txt": {
|
131
|
+
"file_download_url_response": {
|
132
|
+
"s": 39,
|
133
|
+
"at": "lv-LcMAl0dvpdxQFWNVZ7m9-mFT79mS0Mi_fH9InTqtBgcpe8kRVDGQ5Hj4BrXrc",
|
134
|
+
"g": "http://gfs262n164.userstorage.mega.co.nz/dl/mri5tfEwyd0zbAImLAPBzTeWY8_A6olaAjn4rztgo3cQZ_ovfobz7A5X4vhHxU6xDWX3Gcxkozxb0acSEOyC-wRl7gO3jZrJzqLT13812fUfghQvwQ"
|
135
|
+
},
|
136
|
+
"key": [
|
137
|
+
2080156050,
|
138
|
+
393781808,
|
139
|
+
-1482092335,
|
140
|
+
-760625383,
|
141
|
+
758940180,
|
142
|
+
1555777008,
|
143
|
+
-1644788558,
|
144
|
+
-1184834090
|
145
|
+
],
|
146
|
+
"decomposed_key": [
|
147
|
+
1455434630,
|
148
|
+
1271130048,
|
149
|
+
979342435,
|
150
|
+
1808341711
|
151
|
+
],
|
152
|
+
"size": 39,
|
153
|
+
"iv": [
|
154
|
+
758940180,
|
155
|
+
1555777008,
|
156
|
+
0,
|
157
|
+
0
|
158
|
+
],
|
159
|
+
"initial_counter_value": 60129435948344049243162590180076945408
|
160
|
+
},
|
161
|
+
"megar_test_sample_2.png": {
|
162
|
+
"file_download_url_response": {
|
163
|
+
"s": 137080,
|
164
|
+
"at": "OFTM18eQGxUTcJP2BQWXBo23vnjqs4b9QzmNZtDqekz4GZESVNiYlqKtasZqdVHN",
|
165
|
+
"g": "http://gfs262n170.userstorage.mega.co.nz/dl/dpAQXYa5Q7qOQQKAWgqcNsmyPfr8As0DEJlX2LCKmTAvRVlvWpW6F3Hw-xV2Ou2ynF_bfjIcGG5ZO0vi3hf-6rFOx3jAu-FNNSKnvEA1irjUy4hT7g"
|
166
|
+
},
|
167
|
+
"key": [
|
168
|
+
1029178532,
|
169
|
+
1095006796,
|
170
|
+
361733076,
|
171
|
+
-1656803926,
|
172
|
+
1405858242,
|
173
|
+
1396716347,
|
174
|
+
870048465,
|
175
|
+
-473559286
|
176
|
+
],
|
177
|
+
"decomposed_key": [
|
178
|
+
1855173990,
|
179
|
+
302270839,
|
180
|
+
643070213,
|
181
|
+
2130256544
|
182
|
+
],
|
183
|
+
"size": 137080,
|
184
|
+
"iv": [
|
185
|
+
1405858242,
|
186
|
+
1396716347,
|
187
|
+
0,
|
188
|
+
0
|
189
|
+
],
|
190
|
+
"initial_counter_value": 111383565294958830569229712241211736064
|
191
|
+
}
|
108
192
|
}
|
109
193
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
Just about the simplest file possible..
|
Binary file
|
@@ -7,15 +7,57 @@ module CryptoExpectationsHelper
|
|
7
7
|
Pathname.new(File.dirname(__FILE__)).join('..','fixtures','crypto_expectations')
|
8
8
|
end
|
9
9
|
|
10
|
-
def crypto_expectations_sample_path(sample_name)
|
11
|
-
crypto_expectations_path.join("#{sample_name}
|
10
|
+
def crypto_expectations_sample_path(sample_name,ext='.json')
|
11
|
+
crypto_expectations_path.join("#{sample_name}#{ext}")
|
12
12
|
end
|
13
13
|
|
14
14
|
# Returns the JSON representation of +sample_name+ expectations
|
15
|
-
def crypto_expectations(sample_name)
|
15
|
+
def crypto_expectations(sample_name='sample_user')
|
16
16
|
JSON.parse(crypto_expectations_sample_path(sample_name).read)
|
17
17
|
end
|
18
18
|
|
19
|
+
def crypto_sample_encrypted_file_stream(filename)
|
20
|
+
File.open(crypto_expectations_sample_path(filename,'.enc'),'rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the expected raw (encrypted) content for +filename+
|
24
|
+
def crypto_sample_encrypted_file_content(filename)
|
25
|
+
crypto_sample_encrypted_file_stream(filename).read
|
26
|
+
end
|
27
|
+
|
28
|
+
def crypto_sample_files_path
|
29
|
+
Pathname.new(File.dirname(__FILE__)).join('..','fixtures','sample_files')
|
30
|
+
end
|
31
|
+
|
32
|
+
def crypto_sample_file_path(filename)
|
33
|
+
crypto_sample_files_path.join(filename)
|
34
|
+
end
|
35
|
+
|
36
|
+
def crypto_sample_file_stream(filename)
|
37
|
+
File.open(crypto_sample_file_path(filename),'rb')
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the expected (decrypted) content for +filename+
|
41
|
+
def crypto_sample_decrypted_content(filename)
|
42
|
+
crypto_sample_file_path(filename).read
|
43
|
+
end
|
44
|
+
|
45
|
+
# Writes the crypto expectations file and returns the file name used
|
46
|
+
def write_crypto_expectations(content,sample_name='sample_user')
|
47
|
+
filename = crypto_expectations_sample_path(sample_name)
|
48
|
+
File.open(filename,'w') do |f|
|
49
|
+
f.write JSON.pretty_generate(content)
|
50
|
+
end
|
51
|
+
filename
|
52
|
+
end
|
53
|
+
|
54
|
+
def write_file_download_sample(filename,raw_content)
|
55
|
+
fn = crypto_expectations_sample_path(filename,'.enc')
|
56
|
+
File.open(fn,'wb') do |f|
|
57
|
+
f.write raw_content
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
19
61
|
def generate_crypto_expectations(email,password)
|
20
62
|
STDERR.puts "\nGenerating crypto_expectations for #{email}..."
|
21
63
|
e = {email: email.downcase, email_mixed_case: email.capitalize, password: password, autoconnect: false }
|
@@ -28,17 +70,48 @@ module CryptoExpectationsHelper
|
|
28
70
|
e[:rsa_private_key_b64] = session.rsa_private_key_b64
|
29
71
|
e[:decomposed_rsa_private_key] = session.decomposed_rsa_private_key
|
30
72
|
e[:files_response_data] = session.send(:get_files_response)
|
73
|
+
session.send(:handle_files_response,e[:files_response_data])
|
74
|
+
megar_test_sample_1 = session.files.find_by_name('megar_test_sample_1.txt')
|
75
|
+
megar_test_sample_2 = session.files.find_by_name('megar_test_sample_2.png')
|
76
|
+
if megar_test_sample_1 && megar_test_sample_2
|
77
|
+
downloader = megar_test_sample_1.downloader
|
78
|
+
sample_1 = {
|
79
|
+
file_download_url_response: downloader.download_url_response,
|
80
|
+
key: megar_test_sample_1.key,
|
81
|
+
decomposed_key: megar_test_sample_1.decomposed_key,
|
82
|
+
size: downloader.download_size,
|
83
|
+
iv: downloader.iv,
|
84
|
+
initial_counter_value: downloader.initial_counter_value
|
85
|
+
}
|
86
|
+
write_file_download_sample(megar_test_sample_1.name,downloader.raw_content)
|
87
|
+
|
88
|
+
downloader = megar_test_sample_2.downloader
|
89
|
+
sample_2 = {
|
90
|
+
file_download_url_response: downloader.download_url_response,
|
91
|
+
key: megar_test_sample_2.key,
|
92
|
+
decomposed_key: megar_test_sample_2.decomposed_key,
|
93
|
+
size: downloader.download_size,
|
94
|
+
iv: downloader.iv,
|
95
|
+
initial_counter_value: downloader.initial_counter_value
|
96
|
+
}
|
97
|
+
write_file_download_sample(megar_test_sample_2.name,downloader.raw_content)
|
98
|
+
|
99
|
+
e[:sample_files] = {
|
100
|
+
megar_test_sample_1.name => sample_1,
|
101
|
+
megar_test_sample_2.name => sample_2
|
102
|
+
}
|
103
|
+
else
|
104
|
+
raise "\n\nI can't find the expected samples files for testing in this account. Please upload the sample files in 'spec/fixtures/sample_files' and try this again.."
|
105
|
+
end
|
31
106
|
end
|
32
|
-
|
33
|
-
|
34
|
-
ef.write JSON.pretty_generate(e)
|
35
|
-
ef.close
|
36
|
-
STDERR.puts "\nDone! New crypto_expectations for unit test written to:\n#{efn}\n\n"
|
107
|
+
filename = write_crypto_expectations(e)
|
108
|
+
STDERR.puts "\nDone! New crypto_expectations for unit test written to:\n#{filename}\n\n"
|
37
109
|
end
|
38
110
|
|
39
111
|
end
|
40
112
|
|
41
113
|
|
42
114
|
RSpec.configure do |conf|
|
115
|
+
conf.extend CryptoExpectationsHelper # so that these methods are available outside of individual tests
|
43
116
|
conf.include CryptoExpectationsHelper
|
44
117
|
end
|
@@ -1,19 +1,41 @@
|
|
1
1
|
module MocksHelper
|
2
2
|
|
3
|
-
def session_with_mocked_api_responses(options, mock_dataset='sample_user')
|
3
|
+
def session_with_mocked_api_responses(options={}, mock_dataset='sample_user')
|
4
4
|
test_data = crypto_expectations(mock_dataset)
|
5
|
-
|
5
|
+
base_options = {
|
6
|
+
email: test_data['email'],
|
7
|
+
password: test_data['password']
|
8
|
+
}
|
9
|
+
session = Megar::Session.new(base_options.merge(options).merge(autoconnect: false))
|
6
10
|
session.stub(:get_login_response).and_return(test_data['login_response_data'])
|
7
11
|
session.stub(:get_files_response).and_return(test_data['files_response_data'])
|
8
12
|
session
|
9
13
|
end
|
10
14
|
|
11
|
-
def connected_session_with_mocked_api_responses(options, mock_dataset='sample_user')
|
12
|
-
session = session_with_mocked_api_responses(options, mock_dataset
|
15
|
+
def connected_session_with_mocked_api_responses(options={}, mock_dataset='sample_user')
|
16
|
+
session = session_with_mocked_api_responses(options, mock_dataset)
|
13
17
|
session.connect!
|
14
18
|
session
|
15
19
|
end
|
16
20
|
|
21
|
+
def dummy_session_with_files_and_folders
|
22
|
+
session = Megar::Session.new(autoconnect: false)
|
23
|
+
session.stub(:api_request).and_return(nil) # just to be sure it wont work
|
24
|
+
session.reset_files!
|
25
|
+
session.folders.add(id: 'rootid', type: 2) # Root
|
26
|
+
session.folders.add(id: 'inboxid', type: 3) # Inbox
|
27
|
+
session.folders.add(id: 'trashid', type: 4) # Trash
|
28
|
+
session.folders.add(id: 'dir1', type: 1, name: 'User Folder 1')
|
29
|
+
session.folders.add(id: 'dir2', type: 1, name: 'User Folder 2')
|
30
|
+
session.folders.add(id: 'dir3', type: 1, name: 'User Folder 3', parent_folder_id: 'dir1')
|
31
|
+
|
32
|
+
session.files.add(id: 'file1', type: 0, name: 'User File 1', parent_folder_id: 'dir1')
|
33
|
+
session.files.add(id: 'file2', type: 0, name: 'User File 2', parent_folder_id: 'dir1')
|
34
|
+
session.files.add(id: 'file3', type: 0, name: 'User File 3', parent_folder_id: 'dir3')
|
35
|
+
|
36
|
+
session
|
37
|
+
end
|
38
|
+
|
17
39
|
end
|
18
40
|
|
19
41
|
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Megar::FileDownloader do
|
4
|
+
let(:model_class) { Megar::FileDownloader }
|
5
|
+
let(:instance) { model_class.new(attributes) }
|
6
|
+
let(:attributes) { {} }
|
7
|
+
|
8
|
+
describe "#get_chunks (protected)" do
|
9
|
+
subject { instance.send(:get_chunks,size) }
|
10
|
+
{
|
11
|
+
122000 => [[0, 122000]],
|
12
|
+
332000 => [[0, 131072], [131072, 200928]],
|
13
|
+
500000 => [[0, 131072], [131072, 262144], [393216, 106784]],
|
14
|
+
800000 => [[0, 131072], [131072, 262144], [393216, 393216], [786432, 13568]],
|
15
|
+
1800000 => [[0, 131072], [131072, 262144], [393216, 393216], [786432, 524288], [1310720, 489280]],
|
16
|
+
2000000 => [[0, 131072], [131072, 262144], [393216, 393216], [786432, 524288], [1310720, 655360], [1966080, 33920]],
|
17
|
+
2800000 => [[0, 131072], [131072, 262144], [393216, 393216], [786432, 524288], [1310720, 655360], [1966080, 786432], [2752512, 47488]],
|
18
|
+
3800000 => [[0, 131072], [131072, 262144], [393216, 393216], [786432, 524288], [1310720, 655360], [1966080, 786432], [2752512, 917504], [3670016, 129984]],
|
19
|
+
4800000 => [[0, 131072], [131072, 262144], [393216, 393216], [786432, 524288], [1310720, 655360], [1966080, 786432], [2752512, 917504], [3670016, 1048576], [4718592, 81408]],
|
20
|
+
20800000 => [[0, 131072], [131072, 262144], [393216, 393216], [786432, 524288], [1310720, 655360], [1966080, 786432], [2752512, 917504], [3670016, 1048576], [4718592, 1048576], [5767168, 1048576], [6815744, 1048576], [7864320, 1048576], [8912896, 1048576], [9961472, 1048576], [11010048, 1048576], [12058624, 1048576], [13107200, 1048576], [14155776, 1048576], [15204352, 1048576], [16252928, 1048576], [17301504, 1048576], [18350080, 1048576], [19398656, 1048576], [20447232, 352768]],
|
21
|
+
}.each do |size,chunks|
|
22
|
+
context "when size=#{size}" do
|
23
|
+
let(:size) { size }
|
24
|
+
let(:expected) { chunks }
|
25
|
+
it { should eql(chunks) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
crypto_expectations['sample_files'].keys.each do |sample_file_name|
|
31
|
+
context "with an active session testing download of #{sample_file_name}" do
|
32
|
+
|
33
|
+
let(:file_name) { sample_file_name }
|
34
|
+
let(:file_expectation) { crypto_expectations['sample_files'][file_name] }
|
35
|
+
|
36
|
+
let(:sample_encrypted_content) { crypto_sample_encrypted_file_content(file_name) }
|
37
|
+
let(:sample_encrypted_content_digest) { Digest::SHA1.hexdigest(sample_encrypted_content) }
|
38
|
+
|
39
|
+
let(:sample_decrypted_content) { crypto_sample_decrypted_content(file_name) }
|
40
|
+
let(:sample_decrypted_content_digest) { Digest::SHA1.hexdigest(sample_decrypted_content) }
|
41
|
+
|
42
|
+
let(:session) { connected_session_with_mocked_api_responses }
|
43
|
+
let(:file) { session.files.find_by_name(file_name) }
|
44
|
+
let(:attributes) { { file: file } }
|
45
|
+
|
46
|
+
before do
|
47
|
+
session.stub(:get_file_download_url_response).and_return(file_expectation['file_download_url_response'])
|
48
|
+
instance.stub(:stream).and_return(crypto_sample_encrypted_file_stream(file_name))
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#download_url_response" do
|
52
|
+
let(:expected) { file_expectation['file_download_url_response'] }
|
53
|
+
subject { instance.download_url_response }
|
54
|
+
it { should eql(expected) }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#download_url" do
|
58
|
+
let(:expected) { /mega\.co\.nz\/dl/ }
|
59
|
+
subject { instance.download_url }
|
60
|
+
it { should match(expected) }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#download_size" do
|
64
|
+
let(:expected) { file_expectation['size'] }
|
65
|
+
subject { instance.download_size }
|
66
|
+
it { should eql(expected) }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#download_attributes" do
|
70
|
+
let(:expected) { { 'n' => file_name } }
|
71
|
+
subject { instance.download_attributes }
|
72
|
+
it { should eql(expected) }
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#iv" do
|
76
|
+
let(:expected) { file_expectation['iv'] }
|
77
|
+
subject { instance.iv }
|
78
|
+
it { should eql(expected) }
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#initial_counter_value" do
|
82
|
+
let(:expected) { file_expectation['initial_counter_value'] }
|
83
|
+
subject { instance.initial_counter_value }
|
84
|
+
it { should eql(expected) }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#raw_content" do
|
88
|
+
subject { Digest::SHA1.hexdigest(instance.raw_content) }
|
89
|
+
it { should eql(sample_encrypted_content_digest) }
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#content" do
|
93
|
+
subject { Digest::SHA1.hexdigest(instance.content) }
|
94
|
+
it { should eql(sample_decrypted_content_digest) }
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -7,11 +7,13 @@ describe Megar::File do
|
|
7
7
|
|
8
8
|
context "when initialised" do
|
9
9
|
let(:id) { 'some id' }
|
10
|
+
let(:parent_folder_id) { 'some parent id' }
|
10
11
|
let(:name) { 'some name' }
|
11
12
|
let(:type) { 0 }
|
12
13
|
let(:size) { 33 }
|
13
14
|
let(:payload) { {
|
14
|
-
's' => size
|
15
|
+
's' => size,
|
16
|
+
'p' => parent_folder_id
|
15
17
|
} }
|
16
18
|
let(:attributes) { {
|
17
19
|
id: id,
|
@@ -21,11 +23,26 @@ describe Megar::File do
|
|
21
23
|
'n' => name
|
22
24
|
}
|
23
25
|
} }
|
26
|
+
|
24
27
|
subject { instance }
|
25
|
-
|
26
|
-
its(:
|
27
|
-
its(:
|
28
|
-
its(:
|
28
|
+
|
29
|
+
its(:id) { should eql(id) }
|
30
|
+
its(:name) { should eql(name) }
|
31
|
+
its(:type) { should eql(type) }
|
32
|
+
its(:size) { should eql(size) }
|
33
|
+
its(:parent_folder_id) { should eql(parent_folder_id) }
|
34
|
+
its(:body) { should be_nil }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with an active session" do
|
38
|
+
let(:session) { connected_session_with_mocked_api_responses }
|
39
|
+
let(:file) { session.files.find_by_name('megar_test_sample_1.txt') }
|
40
|
+
|
41
|
+
describe "#downloader" do
|
42
|
+
subject { instance.downloader }
|
43
|
+
it { should be_a(Megar::FileDownloader) }
|
44
|
+
end
|
45
|
+
|
29
46
|
end
|
30
47
|
|
31
48
|
end
|