diff options
author | Yigit Sever | 2022-04-16 18:05:37 +0300 |
---|---|---|
committer | Yigit Sever | 2022-04-16 18:05:37 +0300 |
commit | 43ad693490d3c2770bdcad7f59be50d6f1aa79dc (patch) | |
tree | bc4f75101941bf369a82ab62e756c91ecbbbfd44 /tests/route_tests.rs | |
parent | 96d34952c1fb2cf096b6c907feada60b0db27a8f (diff) | |
download | gradecoin-43ad693490d3c2770bdcad7f59be50d6f1aa79dc.tar.gz gradecoin-43ad693490d3c2770bdcad7f59be50d6f1aa79dc.tar.bz2 gradecoin-43ad693490d3c2770bdcad7f59be50d6f1aa79dc.zip |
temporarily remove tests
Diffstat (limited to 'tests/route_tests.rs')
-rw-r--r-- | tests/route_tests.rs | 435 |
1 files changed, 0 insertions, 435 deletions
diff --git a/tests/route_tests.rs b/tests/route_tests.rs deleted file mode 100644 index a449b0b..0000000 --- a/tests/route_tests.rs +++ /dev/null | |||
@@ -1,435 +0,0 @@ | |||
1 | #[cfg(test)] | ||
2 | mod tests { | ||
3 | use gradecoin::schema::{Block, Db, InitialAuthRequest, MetuId, Transaction, User}; | ||
4 | use pretty_assertions::assert_eq; | ||
5 | |||
6 | use gradecoin::routes::consensus_routes; | ||
7 | use warp::http::StatusCode; | ||
8 | |||
9 | /// Create a mock database to be used in tests | ||
10 | fn mocked_db() -> Db { | ||
11 | let db = Db::new(); | ||
12 | |||
13 | db.users.write().insert( | ||
14 | "fingerprint_of_some_guy".to_owned(), | ||
15 | User { | ||
16 | user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(), | ||
17 | public_key: "-----BEGIN PUBLIC KEY----- | ||
18 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5yWTMeFqr2nvOC9oR5Wq | ||
19 | /nzcNlwCIaziojt7rJ4BBvuwkT0tERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXG | ||
20 | ekrGzvC8jHQMKHyNoWzUlpQJ9UMtdQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2 | ||
21 | /ef6abkdj+XWg/slYtrFeOf3ktc1l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH | ||
22 | 8LFPX4bO9lJ9mAoMZFec6XVwumn/uqu9jyWQL6qh6gtwQHgN+A9wGvzVvltJ9h8s | ||
23 | shSHWWtBD0M19ilbXhKyBsHSSZkpx+TAvFhfQ8JURw7KqahUPVlCwJ5OIKccJ/6F | ||
24 | FQIDAQAB | ||
25 | -----END PUBLIC KEY-----" | ||
26 | .to_owned(), | ||
27 | balance: 30, | ||
28 | is_bot: false, | ||
29 | }, | ||
30 | ); | ||
31 | |||
32 | db.users.write().insert( | ||
33 | "fingerprint_of_foo".to_owned(), | ||
34 | User { | ||
35 | user_id: MetuId::new("e223715".to_owned(), "1H5QuOYI1b2r9ET".to_owned()).unwrap(), | ||
36 | public_key: "NOT_USED_FOR_THIS_USER".to_owned(), | ||
37 | balance: 0, | ||
38 | is_bot: false, | ||
39 | }, | ||
40 | ); | ||
41 | |||
42 | /* | ||
43 | -----BEGIN RSA PRIVATE KEY----- | ||
44 | MIIEpAIBAAKCAQEA5yWTMeFqr2nvOC9oR5Wq/nzcNlwCIaziojt7rJ4BBvuwkT0t | ||
45 | ERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXGekrGzvC8jHQMKHyNoWzUlpQJ9UMt | ||
46 | dQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2/ef6abkdj+XWg/slYtrFeOf3ktc1 | ||
47 | l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH8LFPX4bO9lJ9mAoMZFec6XVwumn/ | ||
48 | uqu9jyWQL6qh6gtwQHgN+A9wGvzVvltJ9h8sshSHWWtBD0M19ilbXhKyBsHSSZkp | ||
49 | x+TAvFhfQ8JURw7KqahUPVlCwJ5OIKccJ/6FFQIDAQABAoIBADTZGnZlG4dPqSon | ||
50 | bKgxSA83bQHgt3wLkyWUhApLdeCq2wvZ+NvWDG/s7yT11IZ991ZJIJGfjTtoIALz | ||
51 | J3rAX8jGH/5gfDuArOb000z9HP3wivZQjawa9gqlNC7s5INkQ9iHdsaIqeoYtpMX | ||
52 | qg8uLPiQeWiCsoeb/Rff7ARWEKA7udoZ2uZcZFMHTKx+mBpk8IiepQAJPBRVwmXk | ||
53 | x/3LTaezi6Tkvp/k/gf4IeSICiRGFRmm2Vxciduj11/CrdTHPQLz/Rh5/IN8Bkry | ||
54 | xdQdQxxhwxF/ap6OJIJyguq7gximn2uK0jbHY3nRmrF8SsEtIT+Gd7I46L/goR8c | ||
55 | jQOQRmECgYEA9RJSOBUkZMLoUcC2LGJBZOAnJZ7WToCVdu3LrPceRYtQHwcznW4O | ||
56 | NAHF+blQRzqvbMi11ap8NVpkDDu0ki/Yi2VdSVjQmlaOcpAXjN6T5ZrKoz61xj4g | ||
57 | 2T2/K6d6ypkZRKPhKCC1iI419rq/APVEZHYCl7jZp4iD2izHiegZYccCgYEA8XRK | ||
58 | rfVuPiYsaB07eJrRKKjuoM1Jcr19jZyXY8sbALRcExaTX2CRaPA7binVeDBXayQ1 | ||
59 | I0+kA1nV1EI+ROegV+b6gs2YaUmMJzI1yLqMqGDgHFxFvhkDsZaI+/V+G9eOLEt4 | ||
60 | 5ic5tImfZITLE/GSC8b+C16gxMGUN4t9gHq2okMCgYAKyNedaDDFzl3y2wwpP9mo | ||
61 | 2sReP3Mm2Tm6lhRUdDt8y/impOZ8kw9E8p8HskP6HncBzoNR98KnhmbIswfrNvfM | ||
62 | ipVkWOg1IoH6QKUIqfLQM9OfA290Xd+ML89t2Fzq9XnLL3sFDQtwCvIM/YLSQ/jS | ||
63 | gu7yRkwttzA2NapCQ1h6mQKBgQClwBwn8Qyd01y2mCKkNzsP+2/cqTAbeSNAXFe8 | ||
64 | pMfDowx1+hBu7/7CF+/kPwmQuTa5kSB9PgWsWzYjwNm4OX1j+mbL9lEDLf7tRVWQ | ||
65 | lydJyz7tmRYzWj6j4V/l/u90M3QgyiqTbCf73GG0AkjaRwHn3dG1gl9A0lZqDvK3 | ||
66 | iQXouwKBgQCrx6SCnEkhLISSZpzdDehtWmyCQJIwcdlRQlAmFLVn+TJHTXR7xUm2 | ||
67 | VpTrPTfaYWx83OQUn/OZqY5gIQ+jlfwqnVg+PDQQ/P09/4xygRCLvjL6NCSvtkj1 | ||
68 | MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg== | ||
69 | -----END RSA PRIVATE KEY----- | ||
70 | */ | ||
71 | |||
72 | db.pending_transactions.write().insert( | ||
73 | "fingerprint_of_foo".to_owned(), | ||
74 | Transaction { | ||
75 | source: "fingerprint_of_foo".to_owned(), | ||
76 | target: "fingerprint_of_foo".to_owned(), | ||
77 | amount: 2, | ||
78 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), | ||
79 | }, | ||
80 | ); | ||
81 | |||
82 | *db.blockchain.write() = Block { | ||
83 | transaction_list: vec![ | ||
84 | "foo_public_key_signature".to_owned(), | ||
85 | "bar_public_key_signature".to_owned(), | ||
86 | "baz_public_key_signature".to_owned(), | ||
87 | ], | ||
88 | nonce: 6920405, | ||
89 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 00), | ||
90 | hash: "0000009745f2f09c968c095af75e8ab87eba9be90a93e5df464f83ea7ec08537".to_owned(), | ||
91 | }; | ||
92 | |||
93 | db | ||
94 | } | ||
95 | |||
96 | /// Test simple GET request to /transaction, an endpoint that exists | ||
97 | /// https://tools.ietf.org/html/rfc7231#section-6.3.1 | ||
98 | /// We should get the only pending transaction available in the database as json | ||
99 | #[tokio::test] | ||
100 | async fn get_pending_transactions() { | ||
101 | let db = mocked_db(); | ||
102 | |||
103 | let reply = consensus_routes(db); | ||
104 | |||
105 | let res = warp::test::request() | ||
106 | .method("GET") | ||
107 | .path("/transaction") | ||
108 | .reply(&reply) | ||
109 | .await; | ||
110 | |||
111 | assert_eq!(res.status(), StatusCode::OK); | ||
112 | |||
113 | let expected_json_body = r#"{"fingerprint_of_foo":{"source":"fingerprint_of_foo","target":"fingerprint_of_foo","amount":2,"timestamp":"2021-04-13T20:55:30"}}"#; | ||
114 | |||
115 | assert_eq!(res.body(), expected_json_body); | ||
116 | } | ||
117 | |||
118 | /// Test simple GET request to /block, an enpoint that exists | ||
119 | /// | ||
120 | /// https://tools.ietf.org/html/rfc7231#section-6.3.1 | ||
121 | /// | ||
122 | /// Should return the single block available in the database as json | ||
123 | #[tokio::test] | ||
124 | async fn get_blockchain() { | ||
125 | let db = mocked_db(); | ||
126 | let filter = consensus_routes(db); | ||
127 | |||
128 | let res = warp::test::request() | ||
129 | .method("GET") | ||
130 | .path("/block") | ||
131 | .reply(&filter) | ||
132 | .await; | ||
133 | |||
134 | assert_eq!(res.status(), StatusCode::OK); | ||
135 | |||
136 | let expected_json_body = r#"{"transaction_list":["foo_public_key_signature","bar_public_key_signature","baz_public_key_signature"],"nonce":6920405,"timestamp":"2021-04-13T20:55:00","hash":"0000009745f2f09c968c095af75e8ab87eba9be90a93e5df464f83ea7ec08537"}"#; | ||
137 | assert_eq!(res.body(), expected_json_body); | ||
138 | } | ||
139 | |||
140 | /// Test a simple GET request to a nonexisting path | ||
141 | /// https://tools.ietf.org/html/rfc7231#section-6.5.4 | ||
142 | /// Should respond with 404 and stop | ||
143 | #[tokio::test] | ||
144 | async fn get_nonexisting_path_404() { | ||
145 | let db = mocked_db(); | ||
146 | let filter = consensus_routes(db); | ||
147 | |||
148 | let res = warp::test::request() | ||
149 | .method("GET") | ||
150 | .path("/this_path_does_not_exist") | ||
151 | .reply(&filter) | ||
152 | .await; | ||
153 | |||
154 | assert_eq!(res.status(), StatusCode::NOT_FOUND); | ||
155 | } | ||
156 | |||
157 | /// Test a POST request to /transaction, an endpoint that exists | ||
158 | /// | ||
159 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
160 | /// | ||
161 | /// Should accept the json request, create | ||
162 | /// the transaction and add it to pending transactions in the db | ||
163 | #[tokio::test] | ||
164 | async fn post_auth_json_201() { | ||
165 | let db = mocked_db(); | ||
166 | let filter = consensus_routes(db.clone()); | ||
167 | |||
168 | let res = warp::test::request() | ||
169 | .method("POST") | ||
170 | .json(&Transaction { | ||
171 | source: "fingerprint_of_some_guy".to_owned(), | ||
172 | target: "31415926535897932384626433832795028841971693993751058209749445923".to_owned(), | ||
173 | amount: 2, | ||
174 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), | ||
175 | }) | ||
176 | .header("Authorization", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiJiODI4ZmYwNzM5NjFmMDA2YjU3ZmNkZWMwNmEwZTY1YSIsImV4cCI6MjAwMDAwMDAwMCwiaWF0IjoyNTE2MjM5MDIyfQ.Zwr2BPYzxvdAy8ZjCWSA3dp96KKVHjRDu9imHKCJ0NUeD5fM4D678B6pRZk9ev8PvbEI88MgYVW9akj_IsFwrsho7Tpsh7ym593ZOMwtSWSxxzxuKuGhAuKHDiQlXMFfv6kl8-eXIxa7xbV_0m81vAz6_vYQnVnlhjRQ26LogJRixWpUKV7-mPdRHhrK6dUxi9CwVuc9fdYhd6n2FMKT2AlAnk472fDa3G1oPsFLkp56eJ6_rKWrALHFWItfNvY4zFvwXXyNjMu-0EYJiaQIXFVNnipsy5Sy2HckdY3UiYS2lFUwHIczNrdrLM7NQhJQmbJLD6XRAMifH6bA1ZxH8A") | ||
177 | .path("/transaction") | ||
178 | .reply(&filter) | ||
179 | .await; | ||
180 | |||
181 | println!("{:?}", res.body()); | ||
182 | assert_eq!(res.status(), StatusCode::CREATED); | ||
183 | for i in db.pending_transactions.read().iter() { | ||
184 | println!("{:?}", i); | ||
185 | } | ||
186 | assert_eq!(db.pending_transactions.read().len(), 2); | ||
187 | } | ||
188 | |||
189 | /// Test a POST request to /transaction, an endpoint that exists with an incorrect JWT in the | ||
190 | /// Authorization header | ||
191 | /// | ||
192 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
193 | /// | ||
194 | /// Should reject the request | ||
195 | #[tokio::test] | ||
196 | async fn post_auth_json_400() { | ||
197 | let db = mocked_db(); | ||
198 | let filter = consensus_routes(db.clone()); | ||
199 | |||
200 | let res = warp::test::request() | ||
201 | .method("POST") | ||
202 | .json(&Transaction { | ||
203 | source: "some_fingerprint".to_owned(), | ||
204 | target: "some_other_fingerprint".to_owned(), | ||
205 | amount: 2, | ||
206 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00), | ||
207 | }) | ||
208 | .header( | ||
209 | "Authorization", | ||
210 | "Bearer aaaaaaaasdlkjaldkasljdaskjlaaaaaaaaaaaaaa", | ||
211 | ) | ||
212 | .path("/transaction") | ||
213 | .reply(&filter) | ||
214 | .await; | ||
215 | |||
216 | assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
217 | assert_eq!(db.pending_transactions.read().len(), 1); | ||
218 | } | ||
219 | |||
220 | /// Test a POST request to /block, an endpoint that exists | ||
221 | /// | ||
222 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
223 | /// | ||
224 | /// Should accept the json request, create | ||
225 | /// the block | ||
226 | #[tokio::test] | ||
227 | async fn post_block_auth_201() { | ||
228 | let db = mocked_db(); | ||
229 | let filter = consensus_routes(db.clone()); | ||
230 | |||
231 | db.pending_transactions.write().insert( | ||
232 | "fingerprint_of_some_guy".to_owned(), | ||
233 | Transaction { | ||
234 | source: "fingerprint_of_some_guy".to_owned(), | ||
235 | target: "31415926535897932384626433832795028841971693993751058209749445923" | ||
236 | .to_owned(), | ||
237 | amount: 2, | ||
238 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), | ||
239 | }, | ||
240 | ); | ||
241 | |||
242 | let res = warp::test::request() | ||
243 | .method("POST") | ||
244 | .json(&Block { | ||
245 | transaction_list: vec!["fingerprint_of_some_guy".to_owned()], | ||
246 | nonce: 3222170950, | ||
247 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(23, 38, 00), | ||
248 | hash: "0000002149b72e0b348c32ac442a50ced4efbd1df7d48b377733d55dfe4f3577".to_owned(), | ||
249 | } ) | ||
250 | .header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiIwMDAwMDAyMTQ5YjcyZTBiMzQ4YzMyYWM0NDJhNTBjZWQ0ZWZiZDFkZjdkNDhiMzc3NzMzZDU1ZGZlNGYzNTc3IiwiZXhwIjoxMDAwMDAwMDAwMCwiaWF0IjoxNTE2MjM5MDAyMn0.2hZkIZiOJ9DpHwzL_rTCHGkTxs0S_-KD58a2bXuICogjrW6Z3o9LaJ95d8kpXSrAUCaFWN_-TNbk26LczDFSAhtTxpPh6ELXyLN82wAOCjsp8qLgXJQCnqNY7VFZdRUW0HDwHBLY2PVH40wprPkF7mLLonUPKcJUg9TLnmqHGriSECgv2-XZt2mD9XdTkofqIR-JRR3qoErb4G4xemMNYlWMuJK8I66Vj8kNytSt4wSCzkrWfmk5yyi7q1N3beo4nkP0DKzVstXZzWjn_qMZNZulfOdrNiKwHpwqX_bL66LB0rVpKcI5f6N6w5GZBKsdeUly7dCtKbxwYX3mV-7I_g") | ||
251 | .path("/block") | ||
252 | .reply(&filter) | ||
253 | .await; | ||
254 | |||
255 | println!("RESPONSE: {:?}", res.body()); | ||
256 | |||
257 | // should be reflectled on the db as well | ||
258 | assert_eq!( | ||
259 | db.blockchain.read().hash, | ||
260 | "0000002149b72e0b348c32ac442a50ced4efbd1df7d48b377733d55dfe4f3577".to_owned() | ||
261 | ); | ||
262 | assert_eq!(res.status(), StatusCode::CREATED); | ||
263 | } | ||
264 | |||
265 | /// Test a POST request to /block, an endpoint that exists | ||
266 | /// | ||
267 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
268 | /// | ||
269 | /// Should reject the block because there aren't enough zeroes in the hash | ||
270 | #[tokio::test] | ||
271 | async fn post_block_wrong_hash() { | ||
272 | let db = mocked_db(); | ||
273 | let filter = consensus_routes(db.clone()); | ||
274 | |||
275 | let res = warp::test::request() | ||
276 | .method("POST") | ||
277 | .header("Authorization", "Bearer foo.bar.baz") | ||
278 | .json(&Block { | ||
279 | transaction_list: vec!["foobarbaz".to_owned(), "dazsaz".to_owned()], | ||
280 | nonce: 1000, // not valid | ||
281 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 12).and_hms(05, 29, 30), | ||
282 | hash: "tnarstnarsuthnarsthlarjstk".to_owned(), | ||
283 | }) | ||
284 | .path("/block") | ||
285 | .reply(&filter) | ||
286 | .await; | ||
287 | |||
288 | assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
289 | } | ||
290 | |||
291 | /// Test a POST request to /block, an endpoint that exists | ||
292 | /// | ||
293 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
294 | /// | ||
295 | /// Should reject the block because transaction list is empty | ||
296 | #[tokio::test] | ||
297 | async fn post_block_with_empty_transaction_list() { | ||
298 | let db = mocked_db(); | ||
299 | let filter = consensus_routes(db.clone()); | ||
300 | |||
301 | let res = warp::test::request() | ||
302 | .method("POST") | ||
303 | .header("Authorization", "Bearer foo.bar.baz") | ||
304 | .json(&Block { | ||
305 | transaction_list: vec![], | ||
306 | nonce: 1000, // not valid | ||
307 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 12).and_hms(05, 29, 30), | ||
308 | hash: "thisisnotavalidhash".to_owned(), | ||
309 | }) | ||
310 | .path("/block") | ||
311 | .reply(&filter) | ||
312 | .await; | ||
313 | |||
314 | assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
315 | } | ||
316 | |||
317 | /// Test a POST request to /block, an endpoint that exists | ||
318 | /// | ||
319 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
320 | /// | ||
321 | /// Should reject the block because hash has enough zeroes but is not the actual hash of the | ||
322 | /// block | ||
323 | #[tokio::test] | ||
324 | async fn post_block_incorrect_hash() { | ||
325 | let db = mocked_db(); | ||
326 | let filter = consensus_routes(db.clone()); | ||
327 | |||
328 | let res = warp::test::request() | ||
329 | .method("POST") | ||
330 | .json(&Block { | ||
331 | transaction_list: vec![], | ||
332 | nonce: 12314, | ||
333 | timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 00), | ||
334 | hash: "0000001111111111111111111111111111111111111111111111111111111111".to_owned(), | ||
335 | }) | ||
336 | .path("/block") | ||
337 | .reply(&filter) | ||
338 | .await; | ||
339 | |||
340 | println!("{:?}", res.body()); | ||
341 | assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
342 | assert_eq!( | ||
343 | db.blockchain.read().hash, | ||
344 | "0000009745f2f09c968c095af75e8ab87eba9be90a93e5df464f83ea7ec08537" | ||
345 | ); | ||
346 | } | ||
347 | |||
348 | /// Test a POST request to /register, an endpoint that exists | ||
349 | /// | ||
350 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
351 | /// | ||
352 | /// Should accept the json request, create a new user and | ||
353 | /// add it to the user hashmap in the db | ||
354 | // #[tokio::test] | ||
355 | // async fn post_register_priviliged_user() { | ||
356 | // let db = mocked_db(); | ||
357 | // let filter = consensus_routes(db.clone()); | ||
358 | |||
359 | // let res = warp::test::request() | ||
360 | // .method("POST") | ||
361 | // .json(&priviliged_mocked_user()) | ||
362 | // .path("/register") | ||
363 | // .reply(&filter) | ||
364 | // .await; | ||
365 | |||
366 | // println!("{:?}", res.body()); | ||
367 | // assert_eq!(res.status(), StatusCode::CREATED); | ||
368 | // assert_eq!(db.users.read().len(), 2); | ||
369 | // } | ||
370 | |||
371 | /// Test a POST request to /transaction, an endpoint that exists | ||
372 | /// https://tools.ietf.org/html/rfc7231#section-6.3.2 | ||
373 | /// Should NOT accept the json request as the user is unpriviliged | ||
374 | // #[tokio::test] | ||
375 | // async fn post_register_unpriviliged_user() { | ||
376 | // let db = mocked_db(); | ||
377 | // let filter = consensus_routes(db.clone()); | ||
378 | |||
379 | // let res = warp::test::request() | ||
380 | // .method("POST") | ||
381 | // .json(&unpriviliged_mocked_user()) | ||
382 | // .path("/register") | ||
383 | // .reply(&filter) | ||
384 | // .await; | ||
385 | |||
386 | // println!("{:?}", res.body()); | ||
387 | // assert_eq!(res.status(), StatusCode::BAD_REQUEST); | ||
388 | // assert_eq!(db.users.read().len(), 1); | ||
389 | // } | ||
390 | |||
391 | /// Test a POST request to /transaction, an endpoint that exists with a longer than expected | ||
392 | /// payload | ||
393 | /// | ||
394 | /// https://tools.ietf.org/html/rfc7231#section-6.5.11 | ||
395 | /// | ||
396 | /// Should return 413 to user | ||
397 | #[tokio::test] | ||
398 | async fn post_too_long_content_413() { | ||
399 | let db = mocked_db(); | ||
400 | let filter = consensus_routes(db); | ||
401 | |||
402 | let res = warp::test::request() | ||
403 | .method("POST") | ||
404 | .header("content-length", 1024 * 36) | ||
405 | .path("/transaction") | ||
406 | .reply(&filter) | ||
407 | .await; | ||
408 | |||
409 | assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE); | ||
410 | } | ||
411 | |||
412 | /// Test the User Authentication Process | ||
413 | #[tokio::test] | ||
414 | async fn user_authentication() { | ||
415 | let db = mocked_db(); | ||
416 | let filter = consensus_routes(db); | ||
417 | |||
418 | let res = warp::test::request() | ||
419 | .method("POST") | ||
420 | .json(&InitialAuthRequest { | ||
421 | c: "D9OKSp4XD+niltqhoiTEyz3pTxGm5ZKYVNFPofW40M6Km7wE7FgIpfTkurBZ6tQsG/rYPRsd6C/Qo+o3HrgOYC8BDprwpnYb7UnJdL2pe44ZMEsPAmDAdwTP9WozY0lr+bjEjtTM1mVQnIdfknychFek/FNi3l8MrapeFTxFaTMGxWuS1+wEuAkcz4AR4+jooaXVAEpKrPiSXqbywF9OQ41tk0kRiXn234dj40ndND+GlfMgghITuBJrJx6tzLppAZNIIGwUjQDt5Oib5dEGrPOe+rran1D26YNhZOtrfYEGyUSN+/58HbItQlLrgFhL6zRT7ojw/Eg4jYXndK0xNgYGyhAn5UI/qnI2NPpZU7Wd3sJKlWc7HfrjNnKVKlcrhHtYy3FXfN/hLg7SFmuSfXqqvVbNVT6pEDU6Y5NahOYaE/vkL0no7F7lz0UjAlgQCmn5yN7mKs3yLSnlx6hmsK/fVoqGBcOIbYY5gzYMlAQ3E+lq0p2MPEoWC8NYxStSeo9M8uLYT6Jl3hYVf8aLgd1l0HEiCyT+kWxvcR5hw42I7gqaoUcnr53Zm1mYK30/fvZ6lxsrb4FphldgQC5fx6nwEgjaLUeB4n0oZTSRLbrd9ZXCjUG4FNmM+sOklhIXyTYUj4VcBSwZuAvJZEFf2em68e7ySJs/ysz+TGu3eVeRc+voAvI9mGLxWnSEjWx64po7PO61uG6ikadHZH+wIw==".to_owned(), | ||
422 | iv: "bmV2ZXJtaW5kdGhlbmZ1aw==".to_owned(), | ||
423 | key: "Xd6/VSuFKqayNHspcFJSm+PAHNoTmcR4SsMijSyuyEh6PS5rdvO4W98AhxW4VBrRO1ljfEMeFq835NEDame511D2pim00Xv0HPIYSDW6pIJA1hy+Np/WyC7PCxvKy0hPzTmHMpFmM+aF43BknJdYlPUhY4cww/xScU6WxuKIsEQNORRhQds8CHOO0EGcOjHVvR2xqnOda1g/rI7mfNMATHj9ZRsB9GH6QG5WTUbo9/71cDAILF+28TG40jSKvY2KzO9vr668tgqoMV2vLnXQa1AD9ZWmdHHdjiXuiH3X0uXxHrfjH7HeXi/HOj/pgCX12jKsEsRwkBTGL4koObH6pQ==".to_owned(), | ||
424 | }) | ||
425 | .path("/register") | ||
426 | .reply(&filter) | ||
427 | .await; | ||
428 | |||
429 | println!("{:?}", res); | ||
430 | assert_eq!(res.status(), StatusCode::CREATED); | ||
431 | } | ||
432 | } | ||
433 | |||
434 | // TODO: POST block without correct transactions test <09-04-21, yigit> // | ||
435 | // TODO: POST transaction while that source has pending transaction test <09-04-21, yigit> // | ||