Commit 81202b9f139b941aa38f6d73effefc40e2a7c378
much more tests for various error cases
Dominic Tarr committed on 3/26/2018, 4:26:28 AMParent: 4b01dccf7446ceaacbb44af829f67f0739b9c46d
Files changed
test/invalid.js | changed |
test/invalid.js | ||
---|---|---|
@@ -54,12 +54,13 @@ | ||
54 | 54 … | |
55 | 55 … | //construct a message where host does not match |
56 | 56 … | var seed = hash('seed2') |
57 | 57 … | var keys = ssbKeys.generate(null, seed) |
58 … | + var wrong_seed = hash('wrong_seed') | |
58 | 59 … | var invalid = ssbKeys.signObj(keys, invite_key, { |
59 | 60 … | type: 'invite', |
60 | 61 … | invite: keys.id, //correct key |
61 | - reveal: u.box('cannot be decrypted due to wrong key', u.hash('wrong key')), | |
62 … | + reveal: u.box({hidden: true}, u.hash(u.hash(wrong_seed))), | |
62 | 63 … | host: alice.id |
63 | 64 … | }) |
64 | 65 … | var invite_msg = v.create(null, alice, null, invalid, new Date('2018-03-26T06:14:18.377Z')) |
65 | 66 … | |
@@ -70,8 +71,11 @@ | ||
70 | 71 … | }, 'user-invites:decrypt-reveal-failed') |
71 | 72 … | |
72 | 73 … | //say if the invitee creates a accept message anyway. |
73 | 74 … | |
75 … | + throws(t, function () { | |
76 … | + i.createAccept(invite_msg, wrong_seed, bob.id) | |
77 … | + }, 'user-invites:seed-must-match-invite') | |
74 | 78 … | |
75 | 79 … | |
76 | 80 … | throws(t, function () { |
77 | 81 … | i.createAccept(invite_msg, seed, bob.id) |
@@ -90,6 +94,88 @@ | ||
90 | 94 … | throws(t, function () { |
91 | 95 … | i.verifyAccept(accept_msg, invite_msg) |
92 | 96 … | }, 'user-invites:decrypt-accept-reveal-failed') |
93 | 97 … | |
98 … | + var accept2 = ssbKeys.signObj(ssbKeys.generate(null, seed), invite_key, { | |
99 … | + type: 'invite/accept', | |
100 … | + receipt: '%'+ssbKeys.hash(JSON.stringify(invite_msg, null, 2)), | |
101 … | + id: bob.id, | |
102 … | + key: u.hash('not the key') //what the reveal key should be. | |
103 … | + }) | |
104 … | + | |
105 … | + throws(t, function () { | |
106 … | + i.verifyAccept(accept_msg, invite_msg) | |
107 … | + }, 'user-invites:decrypt-accept-reveal-failed') | |
108 … | + | |
94 | 109 … | t.end() |
95 | 110 … | }) |
111 … | + | |
112 … | +tape('wrong invite', function (t) { | |
113 … | + var seed = hash('seed1') | |
114 … | + | |
115 … | + var invite1 = v.create(null, alice, null, i.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'}), new Date('2018-03-14T06:14:18.377Z')) | |
116 … | + | |
117 … | + t.deepEqual({ | |
118 … | + reveal: {name: 'bob'}, | |
119 … | + private: {text: 'welcome to ssb!'} | |
120 … | + }, i.verifyInvitePrivate(invite1, seed)) | |
121 … | + | |
122 … | + | |
123 … | + var accept_content = i.createAccept(invite1, seed, bob.id) | |
124 … | + var accept = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z')) | |
125 … | + | |
126 … | + var seed2 = hash('seed2') | |
127 … | + var invite2 = v.create(null, alice, null, i.createInvite(seed2, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'}), new Date('2018-03-14T06:14:18.377Z')) | |
128 … | + | |
129 … | + //just test we do not verify the incorrect invite | |
130 … | + throws(t, function () { | |
131 … | + i.verifyAccept(accept, invite2) | |
132 … | + }, 'user-invites:accept-wrong-invite') | |
133 … | + | |
134 … | + t.end() | |
135 … | + | |
136 … | +}) | |
137 … | + | |
138 … | +tape('wrong invite', function (t) { | |
139 … | + var seed = hash('seed1') | |
140 … | + | |
141 … | + var invite = v.create(null, alice, null, i.createInvite(seed, alice.id), new Date('2018-03-14T06:14:18.377Z')) | |
142 … | + var seed2 = hash('seed2') | |
143 … | + var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed2), invite_key, { | |
144 … | + type: 'invite/accept', | |
145 … | + receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)), | |
146 … | + id: bob.id, | |
147 … | + }) | |
148 … | + var accept2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z')) | |
149 … | + | |
150 … | + | |
151 … | + //just test we do not verify the incorrect invite | |
152 … | + throws(t, function () { | |
153 … | + i.verifyAccept(accept2, invite) | |
154 … | + }, 'user-invites:accept-invite-signature-failed') | |
155 … | + | |
156 … | + t.end() | |
157 … | +}) | |
158 … | + | |
159 … | + | |
160 … | +tape('wrong invite', function (t) { | |
161 … | + var seed = hash('seed1') | |
162 … | + | |
163 … | + var invite = v.create(null, alice, null, i.createInvite(seed, alice.id, 'REVEAL'), new Date('2018-03-14T06:14:18.377Z')) | |
164 … | + var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed), invite_key, { | |
165 … | + type: 'invite/accept', | |
166 … | + receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)), | |
167 … | + id: bob.id, | |
168 … | + //key is missing! | |
169 … | + }) | |
170 … | + var accept2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z')) | |
171 … | + | |
172 … | + | |
173 … | + //just test we do not verify the incorrect invite | |
174 … | + throws(t, function () { | |
175 … | + i.verifyAccept(accept2, invite) | |
176 … | + }, 'user-invites:accept-must-reveal-key') | |
177 … | + | |
178 … | + t.end() | |
179 … | +}) | |
180 … | + | |
181 … | + |
Built with git-ssb-web