44require 'minitest/autorun'
55require '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
1715end
1816
1917def 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*' )
3937end
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
108104end
0 commit comments