megar 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -7,9 +7,11 @@ describe Megar::Folder 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) { 1 }
|
12
13
|
let(:payload) { {
|
14
|
+
'p' => parent_folder_id
|
13
15
|
} }
|
14
16
|
let(:attributes) { {
|
15
17
|
id: id,
|
@@ -19,10 +21,59 @@ describe Megar::Folder do
|
|
19
21
|
'n' => name
|
20
22
|
}
|
21
23
|
} }
|
24
|
+
|
22
25
|
subject { instance }
|
23
|
-
|
24
|
-
its(:
|
25
|
-
its(:
|
26
|
+
|
27
|
+
its(:id) { should eql(id) }
|
28
|
+
its(:name) { should eql(name) }
|
29
|
+
its(:type) { should eql(type) }
|
30
|
+
its(:parent_folder_id) { should eql(parent_folder_id) }
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#folders" do
|
35
|
+
let(:session) { dummy_session_with_files_and_folders }
|
36
|
+
|
37
|
+
subject { folder.folders }
|
38
|
+
|
39
|
+
context "when child folders present" do
|
40
|
+
let(:folder) { session.folders.find_by_id('dir1') }
|
41
|
+
its(:count) { should eql(1) }
|
42
|
+
describe "child folder" do
|
43
|
+
subject { folder.folders.first }
|
44
|
+
its(:id) { should eql('dir3') }
|
45
|
+
its(:parent_folder) { should eql(folder) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when child folders not present" do
|
50
|
+
let(:folder) { session.folders.find_by_id('dir2') }
|
51
|
+
its(:count) { should eql(0) }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#files" do
|
57
|
+
let(:session) { dummy_session_with_files_and_folders }
|
58
|
+
|
59
|
+
subject { folder.files }
|
60
|
+
|
61
|
+
context "when child files present" do
|
62
|
+
let(:folder) { session.folders.find_by_id('dir1') }
|
63
|
+
its(:count) { should eql(2) }
|
64
|
+
describe "child file" do
|
65
|
+
subject { folder.files.first }
|
66
|
+
its(:id) { should eql('file1') }
|
67
|
+
its(:parent_folder) { should eql(folder) }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when child files not present" do
|
72
|
+
let(:folder) { session.folders.find_by_id('dir2') }
|
73
|
+
its(:count) { should eql(0) }
|
74
|
+
end
|
75
|
+
|
26
76
|
end
|
27
77
|
|
78
|
+
|
28
79
|
end
|
@@ -1,11 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
include Megar::
|
3
|
+
class CryptoSupportTestHarness
|
4
|
+
include Megar::CryptoSupport
|
5
5
|
end
|
6
6
|
|
7
|
-
describe Megar::
|
8
|
-
let(:harness) {
|
7
|
+
describe Megar::CryptoSupport do
|
8
|
+
let(:harness) { CryptoSupportTestHarness.new }
|
9
|
+
|
10
|
+
describe "#crypto_requirements_met?" do
|
11
|
+
subject { harness.crypto_requirements_met? }
|
12
|
+
it "must be true - which implies OpenSSL has the required modes including CTR" do
|
13
|
+
should be_true
|
14
|
+
end
|
15
|
+
end
|
9
16
|
|
10
17
|
describe "#str_to_a32" do
|
11
18
|
subject { harness.str_to_a32(string) }
|
@@ -451,8 +458,27 @@ describe Megar::Crypto do
|
|
451
458
|
|
452
459
|
end
|
453
460
|
|
461
|
+
describe "#decompose_file_key" do
|
462
|
+
# expectation generation in javascript:
|
463
|
+
# dl_key = [1281139164, 1127317712, 263279788, 1988157168, 402822759, 1958040625, 716219392, 465402751]
|
464
|
+
# expected_key = [dl_key[0]^dl_key[4],dl_key[1]^dl_key[5],dl_key[2]^dl_key[6],dl_key[3]^dl_key[7]]
|
465
|
+
# => [1415460795, 931452129, 620884140, 1832756623]
|
466
|
+
subject { harness.decompose_file_key(key) }
|
467
|
+
[
|
468
|
+
{
|
469
|
+
key: [1281139164, 1127317712, 263279788, 1988157168, 402822759, 1958040625, 716219392, 465402751],
|
470
|
+
expected_key: [1415460795, 931452129, 620884140, 1832756623]
|
471
|
+
}
|
472
|
+
].each do |expectations|
|
473
|
+
context "given #{expectations[:key]}" do
|
474
|
+
let(:key) { expectations[:key] }
|
475
|
+
it { should eql(expectations[:expected_key])}
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
454
480
|
describe "#decrypt_file_attributes" do
|
455
|
-
subject { harness.decrypt_file_attributes(
|
481
|
+
subject { harness.decrypt_file_attributes(attributes,key) }
|
456
482
|
{
|
457
483
|
'simple_folder' => {
|
458
484
|
f: { 't' => 1, 'a' => "US0wKXcni_p8dnqRvhR_Otafji3ioNJ5IsgSHB5zhOw" },
|
@@ -467,7 +493,8 @@ describe Megar::Crypto do
|
|
467
493
|
}.each do |test_name,expectations|
|
468
494
|
context test_name do
|
469
495
|
let(:f) { expectations[:f] }
|
470
|
-
let(:
|
496
|
+
let(:attributes) { f['a'] }
|
497
|
+
let(:key) { f['t'] == 0 ? harness.decompose_file_key(expectations[:key]) : expectations[:key] }
|
471
498
|
it { should eql(expectations[:expected_attributes])}
|
472
499
|
end
|
473
500
|
end
|
data/spec/unit/exception_spec.rb
CHANGED
@@ -10,6 +10,14 @@ describe "Megar Exceptions" do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
describe "Megar::CryptoSupportRequirementsError" do
|
14
|
+
let(:exception_class) { Megar::CryptoSupportRequirementsError }
|
15
|
+
subject { raise exception_class.new("test") }
|
16
|
+
it "should raise correctly" do
|
17
|
+
expect { subject }.to raise_error(exception_class)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
describe "Megar::MegaRequestError" do
|
14
22
|
let(:exception_class) { Megar::MegaRequestError }
|
15
23
|
{
|
data/spec/unit/session_spec.rb
CHANGED
@@ -14,6 +14,14 @@ describe Megar::Session do
|
|
14
14
|
let(:expected_rsa_private_key_b64) { test_data['rsa_private_key_b64'] }
|
15
15
|
let(:expected_decomposed_rsa_private_key) { test_data['decomposed_rsa_private_key'] }
|
16
16
|
|
17
|
+
context "when OpenSSL requirements are not met" do
|
18
|
+
before do
|
19
|
+
OpenSSL::Cipher.stub(:ciphers).and_return([])
|
20
|
+
end
|
21
|
+
it "should raise an error when instantiated" do
|
22
|
+
expect { Megar::Session.new }.to raise_error(Megar::CryptoSupportRequirementsError)
|
23
|
+
end
|
24
|
+
end
|
17
25
|
|
18
26
|
context "with username and password" do
|
19
27
|
let(:session) { Megar::Session.new(options) }
|
@@ -131,6 +139,39 @@ describe Megar::Session do
|
|
131
139
|
subject { session.folders }
|
132
140
|
it { should be_a(Megar::Folders) }
|
133
141
|
its(:collection) { should_not be_empty }
|
142
|
+
|
143
|
+
describe "#root" do
|
144
|
+
let(:root) { session.folders.root }
|
145
|
+
subject { root }
|
146
|
+
its(:name) { should eql("Cloud Drive") }
|
147
|
+
its(:parent_folder) { should be_nil }
|
148
|
+
describe "#folders" do
|
149
|
+
subject { root.folders }
|
150
|
+
it { should_not be_empty }
|
151
|
+
its(:first) { should be_a(Megar::Folder) }
|
152
|
+
end
|
153
|
+
describe "#files" do
|
154
|
+
subject { root.files }
|
155
|
+
it { should_not be_empty }
|
156
|
+
its(:first) { should be_a(Megar::File) }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
describe "#inbox" do
|
160
|
+
subject { session.folders.inbox }
|
161
|
+
its(:name) { should eql("Inbox") }
|
162
|
+
its(:parent_folder) { should be_nil }
|
163
|
+
end
|
164
|
+
describe "#trash" do
|
165
|
+
subject { session.folders.trash }
|
166
|
+
its(:name) { should eql("Trash Bin") }
|
167
|
+
its(:parent_folder) { should be_nil }
|
168
|
+
end
|
169
|
+
describe "random user folder" do
|
170
|
+
subject { session.folders.find_by_type(1) }
|
171
|
+
its(:name) { should_not be_empty }
|
172
|
+
its(:parent_folder) { should be_a(Megar::Folder) }
|
173
|
+
end
|
174
|
+
|
134
175
|
end
|
135
176
|
describe "#files" do
|
136
177
|
subject { session.files }
|
data/spec/unit/shell_spec.rb
CHANGED
@@ -6,6 +6,10 @@ describe Megar::Shell do
|
|
6
6
|
let(:getoptions) { GetOptions.new(Megar::Shell::OPTIONS, options) }
|
7
7
|
let(:shell) { Megar::Shell.new(getoptions,argv) }
|
8
8
|
|
9
|
+
before do
|
10
|
+
$stderr.stub(:puts) # silence console feedback chatter
|
11
|
+
end
|
12
|
+
|
9
13
|
describe "#usage" do
|
10
14
|
let(:options) { ['-h'] }
|
11
15
|
let(:argv) { [] }
|
@@ -15,4 +19,28 @@ describe Megar::Shell do
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
22
|
+
describe "#ls" do
|
23
|
+
let(:options) { ['-e=email','-p=pwd'] }
|
24
|
+
let(:argv) { ['ls'] }
|
25
|
+
it "should invoke ls" do
|
26
|
+
mock_session = mock()
|
27
|
+
mock_session.stub(:connected?).and_return(true)
|
28
|
+
shell.stub(:session).and_return(mock_session)
|
29
|
+
shell.should_receive(:ls)
|
30
|
+
shell.run
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#get" do
|
35
|
+
let(:options) { ['-e=email','-p=pwd'] }
|
36
|
+
let(:argv) { ['get', 'file_id'] }
|
37
|
+
it "should invoke get" do
|
38
|
+
mock_session = mock()
|
39
|
+
mock_session.stub(:connected?).and_return(true)
|
40
|
+
shell.stub(:session).and_return(mock_session)
|
41
|
+
shell.should_receive(:get).with(argv[1])
|
42
|
+
shell.run
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
18
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02
|
12
|
+
date: 2013-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: getoptions
|
@@ -170,6 +170,8 @@ files:
|
|
170
170
|
- lib/js_ref_impl/sjcl_1.js
|
171
171
|
- lib/js_ref_impl/upload_10.js
|
172
172
|
- lib/megar.rb
|
173
|
+
- lib/megar/adapters.rb
|
174
|
+
- lib/megar/adapters/file_downloader.rb
|
173
175
|
- lib/megar/catalog.rb
|
174
176
|
- lib/megar/catalog/catalog_item.rb
|
175
177
|
- lib/megar/catalog/file.rb
|
@@ -178,21 +180,27 @@ files:
|
|
178
180
|
- lib/megar/catalog/folders.rb
|
179
181
|
- lib/megar/connection.rb
|
180
182
|
- lib/megar/crypto.rb
|
183
|
+
- lib/megar/crypto/support.rb
|
181
184
|
- lib/megar/exception.rb
|
182
185
|
- lib/megar/session.rb
|
183
186
|
- lib/megar/shell.rb
|
184
187
|
- lib/megar/version.rb
|
185
188
|
- megar.gemspec
|
189
|
+
- spec/fixtures/crypto_expectations/megar_test_sample_1.txt.enc
|
190
|
+
- spec/fixtures/crypto_expectations/megar_test_sample_2.png.enc
|
186
191
|
- spec/fixtures/crypto_expectations/sample_user.json
|
192
|
+
- spec/fixtures/sample_files/megar_test_sample_1.txt
|
193
|
+
- spec/fixtures/sample_files/megar_test_sample_2.png
|
187
194
|
- spec/spec_helper.rb
|
188
195
|
- spec/support/crypto_expectations_helper.rb
|
189
196
|
- spec/support/mocks_helper.rb
|
197
|
+
- spec/unit/adapters/file_downloader_spec.rb
|
190
198
|
- spec/unit/catalog/file_spec.rb
|
191
199
|
- spec/unit/catalog/files_spec.rb
|
192
200
|
- spec/unit/catalog/folder_spec.rb
|
193
201
|
- spec/unit/catalog/folders_spec.rb
|
194
202
|
- spec/unit/connection_spec.rb
|
195
|
-
- spec/unit/
|
203
|
+
- spec/unit/crypto/support_spec.rb
|
196
204
|
- spec/unit/exception_spec.rb
|
197
205
|
- spec/unit/extensions/math_spec.rb
|
198
206
|
- spec/unit/session_spec.rb
|
@@ -217,21 +225,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
225
|
version: '0'
|
218
226
|
requirements: []
|
219
227
|
rubyforge_project:
|
220
|
-
rubygems_version: 1.8.
|
228
|
+
rubygems_version: 1.8.23
|
221
229
|
signing_key:
|
222
230
|
specification_version: 3
|
223
231
|
summary: A Ruby wrapper and command-line tool for the Mega API (mega.co.nz)
|
224
232
|
test_files:
|
233
|
+
- spec/fixtures/crypto_expectations/megar_test_sample_1.txt.enc
|
234
|
+
- spec/fixtures/crypto_expectations/megar_test_sample_2.png.enc
|
225
235
|
- spec/fixtures/crypto_expectations/sample_user.json
|
236
|
+
- spec/fixtures/sample_files/megar_test_sample_1.txt
|
237
|
+
- spec/fixtures/sample_files/megar_test_sample_2.png
|
226
238
|
- spec/spec_helper.rb
|
227
239
|
- spec/support/crypto_expectations_helper.rb
|
228
240
|
- spec/support/mocks_helper.rb
|
241
|
+
- spec/unit/adapters/file_downloader_spec.rb
|
229
242
|
- spec/unit/catalog/file_spec.rb
|
230
243
|
- spec/unit/catalog/files_spec.rb
|
231
244
|
- spec/unit/catalog/folder_spec.rb
|
232
245
|
- spec/unit/catalog/folders_spec.rb
|
233
246
|
- spec/unit/connection_spec.rb
|
234
|
-
- spec/unit/
|
247
|
+
- spec/unit/crypto/support_spec.rb
|
235
248
|
- spec/unit/exception_spec.rb
|
236
249
|
- spec/unit/extensions/math_spec.rb
|
237
250
|
- spec/unit/session_spec.rb
|