Skip to content

Commit 198b097

Browse files
authored
Merge pull request #1386 from nono/sharing-test-move-folder
Test move folder in a sharing
2 parents 90a97ed + 67585cd commit 198b097

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

tests/sharing/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ gem "minitest"
77
gem "pry"
88
gem "pry-rescue"
99
gem "rest-client"
10+
11+
# Added at 2018-05-21 09:30:04 +0200 by nono:
12+
gem "pry-stack_explorer", "~> 0.4.9"

tests/sharing/Gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ GEM
22
remote: https://rubygems.org/
33
specs:
44
awesome_print (1.8.0)
5+
binding_of_caller (0.8.0)
6+
debug_inspector (>= 0.0.1)
57
coderay (1.1.2)
68
concurrent-ruby (1.0.5)
9+
debug_inspector (0.0.3)
710
domain_name (0.5.20170404)
811
unf (>= 0.0.5, < 1.0.0)
912
faker (1.8.7)
@@ -26,6 +29,9 @@ GEM
2629
pry-rescue (1.4.5)
2730
interception (>= 0.5)
2831
pry
32+
pry-stack_explorer (0.4.9.2)
33+
binding_of_caller (>= 0.7)
34+
pry (>= 0.9.11)
2935
rest-client (2.0.2)
3036
http-cookie (>= 1.0.2, < 2.0)
3137
mime-types (>= 1.16, < 4.0)
@@ -44,6 +50,7 @@ DEPENDENCIES
4450
minitest
4551
pry
4652
pry-rescue
53+
pry-stack_explorer (~> 0.4.9)
4754
rest-client
4855

4956
BUNDLED WITH

tests/sharing/tests/integrity.rb

100644100755
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44
require 'minitest/autorun'
55
require 'pry-rescue/minitest' unless ENV['CI']
66

7-
def make_xor_key()
7+
def make_xor_key
88
random = Random.new.bytes(8)
9-
res = Array.new(2*random.length)
10-
i = 0
11-
random.each_byte { |c|
12-
res[2*i] = c & 0xf
13-
res[2*i+1] = c >> 4
14-
i += 1
15-
}
9+
res = []
10+
random.each_byte do |c|
11+
res << (c & 0xf)
12+
res << (c >> 4)
13+
end
1614
res
1715
end
1816

1917
def xor_id(id, key)
2018
l = key.length
2119
buf = id.bytes.to_a
22-
buf.each_with_index { |c, i|
20+
buf.each_with_index do |c, i|
2321
if 48 <= c && c <= 57
2422
c = (c - 48) ^ key[i%l].ord
2523
elsif 97 <= c && c <= 102
@@ -34,7 +32,7 @@ def xor_id(id, key)
3432
else
3533
buf[i] = (c - 10) + 97
3634
end
37-
}
35+
end
3836
buf.pack('c*')
3937
end
4038

@@ -43,20 +41,19 @@ def xor_id(id, key)
4341
Helpers.start_mailhog
4442

4543
it "cannot reveal information on existing files" do
46-
4744
recipient_name = "Bob"
4845

4946
# Create the instance
5047
inst = Instance.create name: "Alice"
5148
inst_recipient = Instance.create name: recipient_name
5249

53-
# Create the folder
50+
# Create the folder
5451
folder = Folder.create inst
5552
folder.couch_id.wont_be_empty
56-
child1 = Folder.create inst, {dir_id: folder.couch_id}
53+
child1 = Folder.create inst, dir_id: folder.couch_id
5754
file = "../fixtures/wet-cozy_20160910__©M4Dz.jpg"
5855
opts = CozyFile.options_from_fixture(file, dir_id: folder.couch_id)
59-
file = CozyFile.create inst, opts
56+
CozyFile.create inst, opts
6057

6158
# Create the sharing
6259
contact = Contact.create inst, givenName: recipient_name
@@ -68,12 +65,12 @@ def xor_id(id, key)
6865
# Manually set the xor_key
6966
db = Helpers.db_name inst.domain, Sharing.doctype
7067
doc = Helpers.couch.get_doc db, sharing.couch_id
71-
key = make_xor_key()
68+
key = make_xor_key
7269
doc["credentials"][0]["xor_key"] = key
7370
Helpers.couch.update_doc db, doc
7471

75-
# Create a folder on the recipient side, with a fixed id being the
76-
# xor_id of the child1 folder
72+
# Create a folder on the recipient side, with a fixed id being the
73+
# xor_id of the child1 folder
7774
doc = {
7875
type: "directory",
7976
name: name,
@@ -91,18 +88,17 @@ def xor_id(id, key)
9188
inst_recipient.accept sharing
9289
sleep 2
9390

94-
# Make an update
91+
# Make an update
9592
child1.rename inst, Faker::Internet.slug
9693
sleep 4
9794

98-
# The child1 folder shouldn't be part of the sharing as its id exists
95+
# The child1 folder shouldn't be part of the sharing as its id exists
9996
# on the recipient side
10097
child1_recipient = Folder.find inst_recipient, id
10198
assert(child1.name != child1_recipient.name)
10299
path = File.join Helpers.current_dir, inst_recipient.domain,
103-
Helpers::SHARED_WITH_ME, sharing.rules.first.title,
104-
child1_recipient.name
100+
Helpers::SHARED_WITH_ME, sharing.rules.first.title,
101+
child1_recipient.name
105102
assert !Helpers.file_exists_in_fs(path)
106-
107103
end
108104
end

tests/sharing/tests/sync_folder.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Create the folders
1919
folder = Folder.create inst
2020
folder.couch_id.wont_be_empty
21-
child1 = Folder.create inst, {dir_id: folder.couch_id}
21+
child1 = Folder.create inst, dir_id: folder.couch_id
2222
file = "../fixtures/wet-cozy_20160910__©M4Dz.jpg"
2323
opts = CozyFile.options_from_fixture(file, dir_id: folder.couch_id)
2424
file = CozyFile.create inst, opts
@@ -47,9 +47,9 @@
4747
assert_equal file.name, file_recipient.name
4848

4949
# Check the sync (create + update) sharer -> recipient
50-
# TODO move folder
5150
child1.rename inst, Faker::Internet.slug
52-
child2 = Folder.create inst, {dir_id: folder.couch_id}
51+
child2 = Folder.create inst, dir_id: folder.couch_id
52+
child1.move_to inst, child2.couch_id
5353
file.rename inst, "#{Faker::Internet.slug}.txt"
5454
file.overwrite inst, {}
5555
sleep 7
@@ -61,14 +61,16 @@
6161
file_recipient = CozyFile.find inst_recipient, file_id_recipient
6262
assert_equal child1.name, child1_recipient.name
6363
assert_equal child2.name, child2_recipient.name
64+
assert_equal child1_recipient.dir_id, child2_recipient.couch_id
6465
assert_equal file.name, file_recipient.name
6566
assert_equal file.md5sum, file_recipient.md5sum
6667

6768
# Check the sync (create + update) recipient -> sharer
6869
child1_recipient.rename inst_recipient, Faker::Internet.slug
69-
child3_recipient = Folder.create inst_recipient, {dir_id: folder_id_recipient}
70+
child3_recipient = Folder.create inst_recipient, dir_id: folder_id_recipient
71+
child1_recipient.move_to inst_recipient, child3_recipient.couch_id
7072
file_recipient.rename inst_recipient, "#{Faker::Internet.slug}.txt"
71-
file_recipient.overwrite inst_recipient, {content: "New content from recipient"}
73+
file_recipient.overwrite inst_recipient, content: "New content from recipient"
7274

7375
sleep 7
7476
child1 = Folder.find inst, child1.couch_id
@@ -77,6 +79,7 @@
7779
file = CozyFile.find inst, file.couch_id
7880
assert_equal child1_recipient.name, child1.name
7981
assert_equal child3_recipient.name, child3.name
82+
assert_equal child1.dir_id, child3.couch_id
8083
assert_equal file_recipient.name, file.name
8184
assert_equal file_recipient.md5sum, file.md5sum
8285

0 commit comments

Comments
 (0)