Skip to content

Commit

Permalink
Merge pull request #1386 from nono/sharing-test-move-folder
Browse files Browse the repository at this point in the history
Test move folder in a sharing
  • Loading branch information
nono authored May 21, 2018
2 parents 90a97ed + 67585cd commit 198b097
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
3 changes: 3 additions & 0 deletions tests/sharing/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ gem "minitest"
gem "pry"
gem "pry-rescue"
gem "rest-client"

# Added at 2018-05-21 09:30:04 +0200 by nono:
gem "pry-stack_explorer", "~> 0.4.9"
7 changes: 7 additions & 0 deletions tests/sharing/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ GEM
remote: https://rubygems.org/
specs:
awesome_print (1.8.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
coderay (1.1.2)
concurrent-ruby (1.0.5)
debug_inspector (0.0.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
faker (1.8.7)
Expand All @@ -26,6 +29,9 @@ GEM
pry-rescue (1.4.5)
interception (>= 0.5)
pry
pry-stack_explorer (0.4.9.2)
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
Expand All @@ -44,6 +50,7 @@ DEPENDENCIES
minitest
pry
pry-rescue
pry-stack_explorer (~> 0.4.9)
rest-client

BUNDLED WITH
Expand Down
40 changes: 18 additions & 22 deletions tests/sharing/tests/integrity.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@
require 'minitest/autorun'
require 'pry-rescue/minitest' unless ENV['CI']

def make_xor_key()
def make_xor_key
random = Random.new.bytes(8)
res = Array.new(2*random.length)
i = 0
random.each_byte { |c|
res[2*i] = c & 0xf
res[2*i+1] = c >> 4
i += 1
}
res = []
random.each_byte do |c|
res << (c & 0xf)
res << (c >> 4)
end
res
end

def xor_id(id, key)
l = key.length
buf = id.bytes.to_a
buf.each_with_index { |c, i|
buf.each_with_index do |c, i|
if 48 <= c && c <= 57
c = (c - 48) ^ key[i%l].ord
elsif 97 <= c && c <= 102
Expand All @@ -34,7 +32,7 @@ def xor_id(id, key)
else
buf[i] = (c - 10) + 97
end
}
end
buf.pack('c*')
end

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

it "cannot reveal information on existing files" do

recipient_name = "Bob"

# Create the instance
inst = Instance.create name: "Alice"
inst_recipient = Instance.create name: recipient_name

# Create the folder
# Create the folder
folder = Folder.create inst
folder.couch_id.wont_be_empty
child1 = Folder.create inst, {dir_id: folder.couch_id}
child1 = Folder.create inst, dir_id: folder.couch_id
file = "../fixtures/wet-cozy_20160910__©M4Dz.jpg"
opts = CozyFile.options_from_fixture(file, dir_id: folder.couch_id)
file = CozyFile.create inst, opts
CozyFile.create inst, opts

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

# Create a folder on the recipient side, with a fixed id being the
# xor_id of the child1 folder
# Create a folder on the recipient side, with a fixed id being the
# xor_id of the child1 folder
doc = {
type: "directory",
name: name,
Expand All @@ -91,18 +88,17 @@ def xor_id(id, key)
inst_recipient.accept sharing
sleep 2

# Make an update
# Make an update
child1.rename inst, Faker::Internet.slug
sleep 4

# The child1 folder shouldn't be part of the sharing as its id exists
# The child1 folder shouldn't be part of the sharing as its id exists
# on the recipient side
child1_recipient = Folder.find inst_recipient, id
assert(child1.name != child1_recipient.name)
path = File.join Helpers.current_dir, inst_recipient.domain,
Helpers::SHARED_WITH_ME, sharing.rules.first.title,
child1_recipient.name
Helpers::SHARED_WITH_ME, sharing.rules.first.title,
child1_recipient.name
assert !Helpers.file_exists_in_fs(path)

end
end
13 changes: 8 additions & 5 deletions tests/sharing/tests/sync_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Create the folders
folder = Folder.create inst
folder.couch_id.wont_be_empty
child1 = Folder.create inst, {dir_id: folder.couch_id}
child1 = Folder.create inst, dir_id: folder.couch_id
file = "../fixtures/wet-cozy_20160910__©M4Dz.jpg"
opts = CozyFile.options_from_fixture(file, dir_id: folder.couch_id)
file = CozyFile.create inst, opts
Expand Down Expand Up @@ -47,9 +47,9 @@
assert_equal file.name, file_recipient.name

# Check the sync (create + update) sharer -> recipient
# TODO move folder
child1.rename inst, Faker::Internet.slug
child2 = Folder.create inst, {dir_id: folder.couch_id}
child2 = Folder.create inst, dir_id: folder.couch_id
child1.move_to inst, child2.couch_id
file.rename inst, "#{Faker::Internet.slug}.txt"
file.overwrite inst, {}
sleep 7
Expand All @@ -61,14 +61,16 @@
file_recipient = CozyFile.find inst_recipient, file_id_recipient
assert_equal child1.name, child1_recipient.name
assert_equal child2.name, child2_recipient.name
assert_equal child1_recipient.dir_id, child2_recipient.couch_id
assert_equal file.name, file_recipient.name
assert_equal file.md5sum, file_recipient.md5sum

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

sleep 7
child1 = Folder.find inst, child1.couch_id
Expand All @@ -77,6 +79,7 @@
file = CozyFile.find inst, file.couch_id
assert_equal child1_recipient.name, child1.name
assert_equal child3_recipient.name, child3.name
assert_equal child1.dir_id, child3.couch_id
assert_equal file_recipient.name, file.name
assert_equal file_recipient.md5sum, file.md5sum

Expand Down

0 comments on commit 198b097

Please sign in to comment.