dropzone_ruby 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Drop Zone - An Anonymous Peer-To-Peer Local Contraband Marketplace.pdf +0 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +69 -0
- data/README.md +62 -0
- data/bin/dropzone +487 -0
- data/dropzone-screenshot.jpg +0 -0
- data/dropzone_ruby.gemspec +31 -0
- data/lib/blockrio_ext.rb +52 -0
- data/lib/dropzone/buyer.rb +21 -0
- data/lib/dropzone/command.rb +488 -0
- data/lib/dropzone/communication.rb +43 -0
- data/lib/dropzone/connection.rb +312 -0
- data/lib/dropzone/invoice.rb +23 -0
- data/lib/dropzone/item.rb +160 -0
- data/lib/dropzone/listing.rb +64 -0
- data/lib/dropzone/message_base.rb +178 -0
- data/lib/dropzone/payment.rb +36 -0
- data/lib/dropzone/profile.rb +86 -0
- data/lib/dropzone/record_base.rb +34 -0
- data/lib/dropzone/seller.rb +21 -0
- data/lib/dropzone/session.rb +161 -0
- data/lib/dropzone/state_accumulator.rb +39 -0
- data/lib/dropzone/version.rb +4 -0
- data/lib/dropzone_ruby.rb +14 -0
- data/lib/veto_checks.rb +74 -0
- data/spec/bitcoin_spec.rb +115 -0
- data/spec/buyer_profile_spec.rb +279 -0
- data/spec/buyer_spec.rb +109 -0
- data/spec/command_spec.rb +353 -0
- data/spec/config.yml +5 -0
- data/spec/invoice_spec.rb +129 -0
- data/spec/item_spec.rb +294 -0
- data/spec/lib/fake_connection.rb +97 -0
- data/spec/listing_spec.rb +150 -0
- data/spec/payment_spec.rb +152 -0
- data/spec/seller_profile_spec.rb +290 -0
- data/spec/seller_spec.rb +120 -0
- data/spec/session_spec.rb +303 -0
- data/spec/sham/buyer.rb +5 -0
- data/spec/sham/invoice.rb +5 -0
- data/spec/sham/item.rb +8 -0
- data/spec/sham/payment.rb +13 -0
- data/spec/sham/seller.rb +7 -0
- data/spec/spec_helper.rb +49 -0
- metadata +267 -0
data/spec/seller_spec.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require_relative 'sham/seller'
|
4
|
+
|
5
|
+
describe Dropzone::Seller do
|
6
|
+
include_context 'globals'
|
7
|
+
|
8
|
+
describe "defaults" do
|
9
|
+
it "has accessors" do
|
10
|
+
seller = Dropzone::Seller.sham!(:build)
|
11
|
+
|
12
|
+
expect(seller.description).to eq("abc")
|
13
|
+
expect(seller.alias).to eq("Satoshi")
|
14
|
+
expect(seller.communications_pkey).to eq('n3EMs5L3sHcZqRy35cmoPFgw5AzAtWSDUv')
|
15
|
+
expect(seller.transfer_pkey).to be_nil
|
16
|
+
expect(seller.receiver_addr).to eq(test_pubkey)
|
17
|
+
expect(seller.sender_addr).to eq(nil)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "serialization" do
|
22
|
+
it "serializes to_transaction" do
|
23
|
+
expect(Dropzone::Seller.sham!.to_transaction).to eq({
|
24
|
+
tip: 20000,
|
25
|
+
receiver_addr: test_pubkey,
|
26
|
+
data: "SLUPDT\x01d\x03abc\x01a\aSatoshi\x01p\x14\xEE/^\xDE\x81(1\x8F-\x8C3S_\x95\xEB\xD0\xB13\xB0F".force_encoding('ASCII-8BIT') })
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "database" do
|
31
|
+
after{ clear_blockchain! }
|
32
|
+
|
33
|
+
it ".save() and .find()" do
|
34
|
+
seller_id = Dropzone::Seller.sham!(:build).save!(test_privkey)
|
35
|
+
expect(seller_id).to be_kind_of(String)
|
36
|
+
|
37
|
+
seller = Dropzone::Seller.find seller_id
|
38
|
+
expect(seller.description).to eq("abc")
|
39
|
+
expect(seller.alias).to eq("Satoshi")
|
40
|
+
expect(seller.communications_pkey).to eq('n3EMs5L3sHcZqRy35cmoPFgw5AzAtWSDUv')
|
41
|
+
expect(seller.transfer_pkey).to be_nil
|
42
|
+
expect(seller.receiver_addr).to eq(test_pubkey)
|
43
|
+
expect(seller.sender_addr).to eq(test_pubkey)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "validations" do
|
48
|
+
it "validates default build" do
|
49
|
+
expect(Dropzone::Seller.sham!(:build).valid?).to eq(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "validates minimal seller" do
|
53
|
+
seller = Dropzone::Seller.new(
|
54
|
+
receiver_addr: test_pubkey)
|
55
|
+
|
56
|
+
expect(seller.valid?).to eq(true)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "validates output address must be present" do
|
60
|
+
seller = Dropzone::Seller.sham! receiver_addr: nil
|
61
|
+
|
62
|
+
expect(seller.valid?).to eq(false)
|
63
|
+
expect(seller.errors.count).to eq(1)
|
64
|
+
expect(seller.errors.on(:receiver_addr)).to eq(['is not present'])
|
65
|
+
end
|
66
|
+
|
67
|
+
it "description must be string" do
|
68
|
+
seller = Dropzone::Seller.sham! description: 1
|
69
|
+
|
70
|
+
expect(seller.valid?).to eq(false)
|
71
|
+
expect(seller.errors.count).to eq(1)
|
72
|
+
expect(seller.errors.on(:description)).to eq(['is not a string'])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "alias must be string" do
|
76
|
+
seller = Dropzone::Seller.sham! alias: 1
|
77
|
+
|
78
|
+
expect(seller.valid?).to eq(false)
|
79
|
+
expect(seller.errors.count).to eq(1)
|
80
|
+
expect(seller.errors.on(:alias)).to eq(['is not a string'])
|
81
|
+
end
|
82
|
+
|
83
|
+
it "communications_pkey must be public_key" do
|
84
|
+
seller = Dropzone::Seller.sham! communications_pkey: 'Not-a-key'
|
85
|
+
|
86
|
+
expect(seller.valid?).to eq(false)
|
87
|
+
expect(seller.errors.count).to eq(1)
|
88
|
+
expect(seller.errors.on(:communications_pkey)).to eq(['is not a public key'])
|
89
|
+
end
|
90
|
+
|
91
|
+
it "transfer_pkey must be public_key" do
|
92
|
+
seller = Dropzone::Seller.sham! transfer_pkey: 'Not-a-key'
|
93
|
+
|
94
|
+
expect(seller.valid?).to eq(false)
|
95
|
+
expect(seller.errors.count).to eq(2)
|
96
|
+
expect(seller.errors.on(:transfer_pkey)).to eq(["does not match receiver_addr",
|
97
|
+
'is not a public key' ])
|
98
|
+
end
|
99
|
+
|
100
|
+
it "transfer_pkey must be receiver_addr" do
|
101
|
+
seller = Dropzone::Seller.sham! transfer_pkey: TESTER2_PUBLIC_KEY
|
102
|
+
|
103
|
+
expect(seller.valid?).to eq(false)
|
104
|
+
expect(seller.errors.count).to eq(1)
|
105
|
+
expect(seller.errors.on(:transfer_pkey)).to eq(['does not match receiver_addr'])
|
106
|
+
end
|
107
|
+
|
108
|
+
it "declaration must be addressed to self" do
|
109
|
+
id = Dropzone::Seller.sham!(receiver_addr: TESTER2_PUBLIC_KEY).save! test_privkey
|
110
|
+
|
111
|
+
seller = Dropzone::Seller.find id
|
112
|
+
|
113
|
+
expect(seller.valid?).to eq(false)
|
114
|
+
expect(seller.errors.count).to eq(1)
|
115
|
+
expect(seller.errors.on(:receiver_addr)).to eq(['does not match sender_addr'])
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
|
4
|
+
describe Dropzone::Session do
|
5
|
+
include_context 'globals'
|
6
|
+
|
7
|
+
SESSION_DER = "30818702818100e655cc9e04f3bebae76ecca77143ef5c4451876615a9f8b4f712b8f3bdf47ee7f717c09bb5b2b66450831367d9dcf85f9f0528bcd5318fb1dab2f23ce77c48b6b7381eed13e80a14cca6b30b5e37ffe53db15e2d6b727a2efcee51893678d50e9a89166a359e574c4c3ca5e59fae79924fe6f186b36a2ebde9bf09fe4de50453020102"
|
8
|
+
|
9
|
+
BUYER_SESSION_SECRET = "6d6a8a364e604e43380653497b153015476e4254d5b4d79f695cf28cd5ad479a511b6cb5251ab258aa474b56b58a087ccc66acb4d067826a19d16c5f9611b573e8978e09baf36e4e8f08413acc5e21fa6e1c06783396d6ebeba3f34e96a5d35ed820d5d4306ceeed524cd55990d41d5ed8d0bd84922ddef9f861a54aa337abeb"
|
10
|
+
|
11
|
+
BUYER_SESSION_PUBKEY = "2ae9b83b42fe22615e5d378737a6ff883c87bf4eb1e513cde77a2ed557c6e7c3fd37e19d69d55ffbd5d6000a90e94a07abc094139456f82a015640610698ffdf96ca3026fc378653e32974e8fa364f7edb3affc225fe1869aae1f4015c4cb792f3eb88e672aeb860be1a019178ec20268eef1fffe9f8c01abb9da2deeebee757"
|
12
|
+
|
13
|
+
SELLER_SESSION_SECRET = "44d3075ced3cb24f84101e3c0a0d23115638c2730d87b93429147181ae381b09420a155c3b6c03c4b323ea99e72c65851bde0f952ac66b2f950dc0e4bffe5238ab17372e62abe2c2e353b4a8b431aa78661f7379750a6602266705ada943d9f34a5de90892253ad802b8b4a8d6ec71b73d647570ce6f59b6576b6337b8913243"
|
14
|
+
|
15
|
+
SELLER_SESSION_PUBKEY = "ad0588a0cdc2f2b21a296bed80fc303a72e1222e2adc50f2fc2d041f834c5ddf4c0abc79d76d2faece62d547094fd6a1c9017adaf965209616c3b11d35ba577bb9196d1a52fdf89c3f3e8a89fd61749a2b911cb101c7633fad9335f2b1a989ed92784af4fba749dd6c3de1e1aa5a693c6c2d0089ce2287f317ec1d7b55b6bd91"
|
16
|
+
|
17
|
+
SYMM_KEY = "80cacfadf10361f1dff7ce87d257a91b5eddd1e41d17f36c9c4b89fb132a7c2b9d570827283afc928d2c4fb99b1210d34140efdbe7e4ed4fdd9ea5f750b57efffb3fd89625458dd6cbba06fdf9ecdc0ab12d73a746613fc25ecead056ea362f68cd05bcbb4ac8a627b7c973863ec162e995134d1fc4a0b2fcd3b1c88dfbd173a"
|
18
|
+
|
19
|
+
def random_secret
|
20
|
+
SecureRandom.random_bytes(128).unpack('H*').first
|
21
|
+
end
|
22
|
+
|
23
|
+
after{ clear_blockchain! }
|
24
|
+
|
25
|
+
it "simple non-deterministic chat test" do
|
26
|
+
# Note that Der's and IV's are generated randomly on every iteration of this
|
27
|
+
# test, which is unlike the extended test.
|
28
|
+
|
29
|
+
buyer_to_seller = Dropzone::Session.new test_privkey,
|
30
|
+
BUYER_SESSION_SECRET, receiver_addr: TESTER2_PUBLIC_KEY
|
31
|
+
|
32
|
+
buyer_to_seller.authenticate!
|
33
|
+
|
34
|
+
seller_to_buyer = Dropzone::Session.new TESTER2_PRIVATE_KEY, SELLER_SESSION_SECRET,
|
35
|
+
with: Dropzone::Session.all(TESTER2_PUBLIC_KEY).first
|
36
|
+
|
37
|
+
seller_to_buyer.authenticate!
|
38
|
+
|
39
|
+
seller_to_buyer << "Hello Buyer"
|
40
|
+
buyer_to_seller << "Hello Seller"
|
41
|
+
|
42
|
+
expect(seller_to_buyer.communications.collect(&:contents_plain)).to eq([
|
43
|
+
"Hello Seller", "Hello Buyer" ])
|
44
|
+
expect(buyer_to_seller.communications.collect(&:contents_plain)).to eq([
|
45
|
+
"Hello Seller", "Hello Buyer" ])
|
46
|
+
end
|
47
|
+
|
48
|
+
it "extended deterministic chat test" do
|
49
|
+
buyer_to_seller = Dropzone::Session.new TESTER2_PRIVATE_KEY,
|
50
|
+
BUYER_SESSION_SECRET, receiver_addr: test_pubkey
|
51
|
+
|
52
|
+
expect(buyer_to_seller.sender_addr).to eq(TESTER2_PUBLIC_KEY)
|
53
|
+
expect(buyer_to_seller.priv_key).to eq(TESTER2_PRIVATE_KEY)
|
54
|
+
|
55
|
+
## Step One: Buyer initializes channel.
|
56
|
+
|
57
|
+
# Der is not actually required, but since we're keeping the tests
|
58
|
+
# deterministic, I'm passing it here. Additionally, this speeds up testing:
|
59
|
+
buyer_auth_id = buyer_to_seller.authenticate! [SESSION_DER].pack('H*')
|
60
|
+
|
61
|
+
# Test the initialization:
|
62
|
+
buyer_init_comm = Dropzone::Communication.find buyer_auth_id
|
63
|
+
|
64
|
+
expect(buyer_init_comm.valid?).to be_truthy
|
65
|
+
expect(buyer_init_comm.receiver_addr).to eq(test_pubkey)
|
66
|
+
expect(buyer_init_comm.sender_addr).to eq(TESTER2_PUBLIC_KEY)
|
67
|
+
expect(buyer_init_comm.der.unpack('H*').first).to eq(SESSION_DER)
|
68
|
+
expect(buyer_init_comm.session_pkey.unpack('H*').first).to eq(BUYER_SESSION_PUBKEY)
|
69
|
+
expect(buyer_init_comm.iv).to eq(nil)
|
70
|
+
expect(buyer_init_comm.contents).to eq(nil)
|
71
|
+
|
72
|
+
expect(buyer_to_seller.authenticated?).to be_falsey
|
73
|
+
|
74
|
+
## Step Two: Seller authenticates request.
|
75
|
+
seller_sessions = Dropzone::Session.all(test_pubkey)
|
76
|
+
|
77
|
+
expect(seller_sessions.length).to eq(1)
|
78
|
+
|
79
|
+
seller_to_buyer = Dropzone::Session.new test_privkey, SELLER_SESSION_SECRET,
|
80
|
+
with: seller_sessions.first
|
81
|
+
|
82
|
+
expect(seller_to_buyer.authenticated?).to be_falsey
|
83
|
+
expect(buyer_to_seller.authenticated?).to be_falsey
|
84
|
+
|
85
|
+
seller_auth_id = seller_to_buyer.authenticate!
|
86
|
+
|
87
|
+
# Test the communication:
|
88
|
+
seller_init_comm = Dropzone::Communication.find seller_auth_id
|
89
|
+
|
90
|
+
expect(seller_init_comm.valid?).to be_truthy
|
91
|
+
expect(seller_init_comm.receiver_addr).to eq(TESTER2_PUBLIC_KEY)
|
92
|
+
expect(seller_init_comm.sender_addr).to eq(test_pubkey)
|
93
|
+
expect(seller_init_comm.der).to be_nil
|
94
|
+
expect(seller_init_comm.session_pkey.unpack('H*').first).to eq(SELLER_SESSION_PUBKEY)
|
95
|
+
expect(seller_init_comm.iv).to eq(nil)
|
96
|
+
expect(seller_init_comm.contents).to eq(nil)
|
97
|
+
|
98
|
+
# Now test the shared secrets:
|
99
|
+
expect(buyer_to_seller.communications.length).to eq(0)
|
100
|
+
expect(seller_to_buyer.communications.length).to eq(0)
|
101
|
+
|
102
|
+
# And ensure that we authenticated:
|
103
|
+
expect(buyer_to_seller.symm_key.unpack('H*').first).to eq(SYMM_KEY)
|
104
|
+
expect(buyer_to_seller.authenticated?).to be_truthy
|
105
|
+
expect(seller_to_buyer.symm_key.unpack('H*').first).to eq(SYMM_KEY)
|
106
|
+
expect(seller_to_buyer.authenticated?).to be_truthy
|
107
|
+
|
108
|
+
## Step Three: Seller Says Hi To Buyer.
|
109
|
+
seller_hello_id = seller_to_buyer.send( "Hello Buyer",
|
110
|
+
['4941fbbf24517885502b85a0f3285659'].pack('H*') )
|
111
|
+
|
112
|
+
seller_hello_comm = Dropzone::Communication.find seller_hello_id
|
113
|
+
|
114
|
+
expect(seller_hello_comm.valid?).to be_truthy
|
115
|
+
expect(seller_hello_comm.receiver_addr).to eq(TESTER2_PUBLIC_KEY)
|
116
|
+
expect(seller_hello_comm.sender_addr).to eq(test_pubkey)
|
117
|
+
expect(seller_hello_comm.der).to be_nil
|
118
|
+
expect(seller_hello_comm.session_pkey).to be_nil
|
119
|
+
expect(seller_hello_comm.iv.unpack('H*').first).to eq(
|
120
|
+
'4941fbbf24517885502b85a0f3285659')
|
121
|
+
expect(seller_hello_comm.contents.unpack('H*').first).to eq(
|
122
|
+
'2924a61b305a8070c0c41496482d1a3a')
|
123
|
+
|
124
|
+
## Step Four: Buyer Says Hello to Seller.
|
125
|
+
buyer_hello_id = buyer_to_seller.send "Hello Seller",
|
126
|
+
['02ff94080d10f3361d69e9770dca9982'].pack('H*')
|
127
|
+
|
128
|
+
buyer_hello_comm = Dropzone::Communication.find buyer_hello_id
|
129
|
+
|
130
|
+
expect(buyer_hello_comm.valid?).to be_truthy
|
131
|
+
expect(buyer_hello_comm.receiver_addr).to eq(test_pubkey)
|
132
|
+
expect(buyer_hello_comm.sender_addr).to eq(TESTER2_PUBLIC_KEY)
|
133
|
+
expect(buyer_hello_comm.der).to be_nil
|
134
|
+
expect(buyer_hello_comm.session_pkey).to be_nil
|
135
|
+
expect(buyer_hello_comm.iv.unpack('H*').first).to eq(
|
136
|
+
'02ff94080d10f3361d69e9770dca9982')
|
137
|
+
expect(buyer_hello_comm.contents.unpack('H*').first).to eq(
|
138
|
+
'fa753c555ae1d87b22ee40d0879d0ee0')
|
139
|
+
|
140
|
+
# Now test the shared secrets:
|
141
|
+
expect(seller_to_buyer.communications.collect(&:contents_plain)).to eq([
|
142
|
+
"Hello Seller", "Hello Buyer" ])
|
143
|
+
expect(buyer_to_seller.communications.collect(&:contents_plain)).to eq([
|
144
|
+
"Hello Seller", "Hello Buyer" ])
|
145
|
+
end
|
146
|
+
|
147
|
+
it "Requires that session must authenticate before chatting" do
|
148
|
+
# Create a session, authenticate it, and then try opening it with a bad pass
|
149
|
+
buyer_to_seller = Dropzone::Session.new test_privkey,
|
150
|
+
BUYER_SESSION_SECRET, receiver_addr: TESTER2_PUBLIC_KEY
|
151
|
+
|
152
|
+
expect{buyer_to_seller << "Hello Buyer"}.to raise_error(
|
153
|
+
Dropzone::Session::Unauthenticated )
|
154
|
+
|
155
|
+
buyer_to_seller.authenticate!
|
156
|
+
|
157
|
+
expect{buyer_to_seller << "Hello Buyer"}.to raise_error(
|
158
|
+
Dropzone::Session::Unauthenticated )
|
159
|
+
|
160
|
+
seller_to_buyer = Dropzone::Session.new TESTER2_PRIVATE_KEY, SELLER_SESSION_SECRET,
|
161
|
+
with: Dropzone::Session.all(TESTER2_PUBLIC_KEY).first
|
162
|
+
|
163
|
+
# This should error:
|
164
|
+
expect{seller_to_buyer << "Hello Buyer"}.to raise_error(
|
165
|
+
Dropzone::Session::Unauthenticated )
|
166
|
+
end
|
167
|
+
|
168
|
+
it "supports multiple chats sessions by a seller" do
|
169
|
+
## Buyers Say hello:
|
170
|
+
buyer1_to_seller = Dropzone::Session.new TESTER2_PRIVATE_KEY,
|
171
|
+
random_secret, receiver_addr: test_pubkey
|
172
|
+
buyer1_to_seller.authenticate!
|
173
|
+
|
174
|
+
buyer2_to_seller = Dropzone::Session.new TESTER3_PRIVATE_KEY,
|
175
|
+
random_secret, receiver_addr: test_pubkey
|
176
|
+
buyer2_to_seller.authenticate!
|
177
|
+
|
178
|
+
## Seller Authenticates:
|
179
|
+
seller_sessions = Dropzone::Session.all(test_pubkey)
|
180
|
+
|
181
|
+
expect(seller_sessions.length).to eq(2)
|
182
|
+
|
183
|
+
seller_to_buyer2 = Dropzone::Session.new test_privkey, random_secret,
|
184
|
+
with: seller_sessions.first
|
185
|
+
|
186
|
+
seller_to_buyer1 = Dropzone::Session.new test_privkey, random_secret,
|
187
|
+
with: seller_sessions.last
|
188
|
+
|
189
|
+
seller_to_buyer1.authenticate!
|
190
|
+
seller_to_buyer2.authenticate!
|
191
|
+
|
192
|
+
## Chats commence:
|
193
|
+
seller_to_buyer1 << "Hello Buyer1"
|
194
|
+
buyer1_to_seller << "Hello from Buyer1"
|
195
|
+
|
196
|
+
seller_to_buyer2 << "Hello Buyer2"
|
197
|
+
buyer2_to_seller << "Hello from Buyer2"
|
198
|
+
|
199
|
+
# Test:
|
200
|
+
expect(seller_to_buyer1.communications.collect(&:contents_plain)).to eq([
|
201
|
+
"Hello from Buyer1", "Hello Buyer1" ])
|
202
|
+
expect(buyer1_to_seller.communications.collect(&:contents_plain)).to eq([
|
203
|
+
"Hello from Buyer1", "Hello Buyer1" ])
|
204
|
+
expect(seller_to_buyer2.communications.collect(&:contents_plain)).to eq([
|
205
|
+
"Hello from Buyer2", "Hello Buyer2" ])
|
206
|
+
expect(buyer2_to_seller.communications.collect(&:contents_plain)).to eq([
|
207
|
+
"Hello from Buyer2", "Hello Buyer2" ])
|
208
|
+
end
|
209
|
+
|
210
|
+
it "supports multiple chat sessions by a buyer" do
|
211
|
+
## Buyers Say hello:
|
212
|
+
buyer_to_seller1 = Dropzone::Session.new test_privkey, random_secret,
|
213
|
+
receiver_addr: TESTER2_PUBLIC_KEY
|
214
|
+
buyer_to_seller1.authenticate!
|
215
|
+
|
216
|
+
buyer_to_seller2 = Dropzone::Session.new test_privkey, random_secret,
|
217
|
+
receiver_addr: TESTER3_PUBLIC_KEY
|
218
|
+
buyer_to_seller2.authenticate!
|
219
|
+
|
220
|
+
## Sellers Authenticate:
|
221
|
+
seller1_to_buyer = Dropzone::Session.new TESTER2_PRIVATE_KEY, random_secret,
|
222
|
+
with: Dropzone::Session.all(TESTER2_PUBLIC_KEY).first
|
223
|
+
seller1_to_buyer.authenticate!
|
224
|
+
|
225
|
+
seller2_to_buyer = Dropzone::Session.new TESTER3_PRIVATE_KEY, random_secret,
|
226
|
+
with: Dropzone::Session.all(TESTER3_PUBLIC_KEY).first
|
227
|
+
seller2_to_buyer.authenticate!
|
228
|
+
|
229
|
+
## Chats commence:
|
230
|
+
buyer_to_seller1 << "Hello Seller1"
|
231
|
+
seller1_to_buyer << "Hello from Seller1"
|
232
|
+
|
233
|
+
buyer_to_seller2 << "Hello Seller2"
|
234
|
+
seller2_to_buyer << "Hello from Seller2"
|
235
|
+
|
236
|
+
# Now test:
|
237
|
+
expect(seller1_to_buyer.communications.collect(&:contents_plain)).to eq([
|
238
|
+
"Hello from Seller1", "Hello Seller1" ])
|
239
|
+
expect(buyer_to_seller1.communications.collect(&:contents_plain)).to eq([
|
240
|
+
"Hello from Seller1", "Hello Seller1" ])
|
241
|
+
expect(seller2_to_buyer.communications.collect(&:contents_plain)).to eq([
|
242
|
+
"Hello from Seller2", "Hello Seller2" ])
|
243
|
+
expect(buyer_to_seller2.communications.collect(&:contents_plain)).to eq([
|
244
|
+
"Hello from Seller2", "Hello Seller2" ])
|
245
|
+
end
|
246
|
+
|
247
|
+
it "supports multiple chat sessions between two users" do
|
248
|
+
## Session One:
|
249
|
+
buyer_to_seller1_secret = random_secret
|
250
|
+
seller_to_buyer1_secret = random_secret
|
251
|
+
|
252
|
+
buyer_to_seller1 = Dropzone::Session.new test_privkey,
|
253
|
+
buyer_to_seller1_secret, receiver_addr: TESTER2_PUBLIC_KEY
|
254
|
+
|
255
|
+
buyer_to_seller1.authenticate!
|
256
|
+
|
257
|
+
seller_to_buyer1 = Dropzone::Session.new TESTER2_PRIVATE_KEY,
|
258
|
+
seller_to_buyer1_secret,
|
259
|
+
with: Dropzone::Session.all(TESTER2_PUBLIC_KEY).first
|
260
|
+
|
261
|
+
seller_to_buyer1.authenticate!
|
262
|
+
|
263
|
+
|
264
|
+
seller_to_buyer1 << "Hello Buyer S1"
|
265
|
+
buyer_to_seller1 << "Hello Seller S1"
|
266
|
+
|
267
|
+
increment_block_height!
|
268
|
+
|
269
|
+
## Session Two:
|
270
|
+
buyer_to_seller2 = Dropzone::Session.new test_privkey, random_secret,
|
271
|
+
receiver_addr: TESTER2_PUBLIC_KEY
|
272
|
+
|
273
|
+
buyer_to_seller2.authenticate!
|
274
|
+
|
275
|
+
seller_to_buyer2 = Dropzone::Session.new TESTER2_PRIVATE_KEY, random_secret,
|
276
|
+
with: Dropzone::Session.all(TESTER2_PUBLIC_KEY).first
|
277
|
+
|
278
|
+
expect(seller_to_buyer2.authenticated?).to be_falsey
|
279
|
+
|
280
|
+
seller_to_buyer2.authenticate!
|
281
|
+
|
282
|
+
increment_block_height!
|
283
|
+
|
284
|
+
seller_sessions = Dropzone::Session.all(TESTER2_PUBLIC_KEY)
|
285
|
+
|
286
|
+
expect(seller_sessions.length).to eq(2)
|
287
|
+
|
288
|
+
# Ensure that we authenticated:
|
289
|
+
expect(buyer_to_seller2.symm_key).to eq(seller_to_buyer2.symm_key)
|
290
|
+
expect(buyer_to_seller1.symm_key).to_not eq(seller_to_buyer2.symm_key)
|
291
|
+
expect(seller_to_buyer2.authenticated?).to be_truthy
|
292
|
+
|
293
|
+
seller_to_buyer2 << "Hello Buyer S2"
|
294
|
+
buyer_to_seller2 << "Hello Seller S2"
|
295
|
+
|
296
|
+
# Now test the shared secrets:
|
297
|
+
expect(seller_to_buyer2.communications.collect(&:contents_plain)).to eq([
|
298
|
+
"Hello Seller S2", "Hello Buyer S2" ])
|
299
|
+
expect(buyer_to_seller2.communications.collect(&:contents_plain)).to eq([
|
300
|
+
"Hello Seller S2", "Hello Buyer S2" ])
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
data/spec/sham/buyer.rb
ADDED
data/spec/sham/item.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'invoice'
|
2
|
+
|
3
|
+
Sham.config(Dropzone::Payment) do |c|
|
4
|
+
c.attributes do
|
5
|
+
# Tester2 generates an invoice to Tester1
|
6
|
+
invoice_id = Dropzone::Invoice.sham!(:build).save! TESTER2_PRIVATE_KEY
|
7
|
+
|
8
|
+
# Tester 1 marks payment to Tester 2
|
9
|
+
{ description: 'abc', invoice_txid: invoice_id,
|
10
|
+
delivery_quality: 8, product_quality: 8, communications_quality: 8,
|
11
|
+
receiver_addr: TESTER2_PUBLIC_KEY}
|
12
|
+
end
|
13
|
+
end
|