From 6078fec593afcef1f2bb920b931daada09480f51 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 25 Apr 2021 22:59:52 +0300 Subject: Fix tests --- Cargo.lock | 47 ++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + scripts/encryptor.py | 8 ++++++ src/handlers.rs | 2 +- tests/route_tests.rs | 72 ++++++++++++++++++++++++++-------------------------- 5 files changed, 93 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82a3df2..22990ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,6 +40,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "anyhow" version = "1.0.40" @@ -282,6 +291,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "ctor" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "derivative" version = "2.2.0" @@ -293,6 +312,12 @@ dependencies = [ "syn", ] +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + [[package]] name = "digest" version = "0.9.0" @@ -457,6 +482,7 @@ dependencies = [ "log4rs", "md-5", "parking_lot 0.10.2", + "pretty_assertions", "rsa", "serde", "serde_json", @@ -984,6 +1010,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "output_vt100" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "parking_lot" version = "0.10.2" @@ -1114,6 +1149,18 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "pretty_assertions" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b" +dependencies = [ + "ansi_term", + "ctor", + "diff", + "output_vt100", +] + [[package]] name = "proc-macro2" version = "1.0.26" diff --git a/Cargo.toml b/Cargo.toml index 45fda30..77efd25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,4 @@ askama = "0.10.5" [dev-dependencies] serde_test = "1.0.117" +pretty_assertions = "0.7.2" diff --git a/scripts/encryptor.py b/scripts/encryptor.py index 2dac487..ed0c1d8 100644 --- a/scripts/encryptor.py +++ b/scripts/encryptor.py @@ -12,6 +12,9 @@ def hex2bin(hexStr): return binascii.unhexlify(hexStr) iv = hex2bin("6e657665726d696e647468656e66756b") + +iv_ready = base64.b64encode(iv) + key = hex2bin("6e6565726d666e646e6565726d666e64") mode = CBC(iv) @@ -67,3 +70,8 @@ asy_cipher = PKCS1_OAEP.new(publickey, hashAlgo=Crypto.Hash.SHA256) ciphertext = asy_cipher.encrypt(key) key = base64.b64encode(ciphertext) + +print(f'key: {key}') +print(f'c: {c}') +print(f'iv: {iv_ready}') + diff --git a/src/handlers.rs b/src/handlers.rs index 7204aa7..e831806 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -224,7 +224,7 @@ pub async fn authenticate_user( Err(err) => { println!( "auth request (c) did not decrypt correctly {:?} {}", - &auth_packet, err + &buf, err ); let res_json = warp::reply::json(&GradeCoinResponse { diff --git a/tests/route_tests.rs b/tests/route_tests.rs index cfa1af6..a449b0b 100644 --- a/tests/route_tests.rs +++ b/tests/route_tests.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests { use gradecoin::schema::{Block, Db, InitialAuthRequest, MetuId, Transaction, User}; + use pretty_assertions::assert_eq; use gradecoin::routes::consensus_routes; use warp::http::StatusCode; @@ -24,7 +25,7 @@ FQIDAQAB -----END PUBLIC KEY-----" .to_owned(), balance: 30, - is_bot: false + is_bot: false, }, ); @@ -34,45 +35,44 @@ FQIDAQAB user_id: MetuId::new("e223715".to_owned(), "1H5QuOYI1b2r9ET".to_owned()).unwrap(), public_key: "NOT_USED_FOR_THIS_USER".to_owned(), balance: 0, - is_bot: false + is_bot: false, }, ); /* ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA5yWTMeFqr2nvOC9oR5Wq/nzcNlwCIaziojt7rJ4BBvuwkT0t -ERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXGekrGzvC8jHQMKHyNoWzUlpQJ9UMt -dQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2/ef6abkdj+XWg/slYtrFeOf3ktc1 -l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH8LFPX4bO9lJ9mAoMZFec6XVwumn/ -uqu9jyWQL6qh6gtwQHgN+A9wGvzVvltJ9h8sshSHWWtBD0M19ilbXhKyBsHSSZkp -x+TAvFhfQ8JURw7KqahUPVlCwJ5OIKccJ/6FFQIDAQABAoIBADTZGnZlG4dPqSon -bKgxSA83bQHgt3wLkyWUhApLdeCq2wvZ+NvWDG/s7yT11IZ991ZJIJGfjTtoIALz -J3rAX8jGH/5gfDuArOb000z9HP3wivZQjawa9gqlNC7s5INkQ9iHdsaIqeoYtpMX -qg8uLPiQeWiCsoeb/Rff7ARWEKA7udoZ2uZcZFMHTKx+mBpk8IiepQAJPBRVwmXk -x/3LTaezi6Tkvp/k/gf4IeSICiRGFRmm2Vxciduj11/CrdTHPQLz/Rh5/IN8Bkry -xdQdQxxhwxF/ap6OJIJyguq7gximn2uK0jbHY3nRmrF8SsEtIT+Gd7I46L/goR8c -jQOQRmECgYEA9RJSOBUkZMLoUcC2LGJBZOAnJZ7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CvIM/YLSQ/jS + gu7yRkwttzA2NapCQ1h6mQKBgQClwBwn8Qyd01y2mCKkNzsP+2/cqTAbeSNAXFe8 + pMfDowx1+hBu7/7CF+/kPwmQuTa5kSB9PgWsWzYjwNm4OX1j+mbL9lEDLf7tRVWQ + lydJyz7tmRYzWj6j4V/l/u90M3QgyiqTbCf73GG0AkjaRwHn3dG1gl9A0lZqDvK3 + iQXouwKBgQCrx6SCnEkhLISSZpzdDehtWmyCQJIwcdlRQlAmFLVn+TJHTXR7xUm2 + VpTrPTfaYWx83OQUn/OZqY5gIQ+jlfwqnVg+PDQQ/P09/4xygRCLvjL6NCSvtkj1 + MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg== + -----END RSA PRIVATE KEY----- + */ db.pending_transactions.write().insert( "fingerprint_of_foo".to_owned(), Transaction { - source: "fingerprint_of_foo" - .to_owned(), + source: "fingerprint_of_foo".to_owned(), target: "fingerprint_of_foo".to_owned(), amount: 2, timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), @@ -110,7 +110,7 @@ MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg== assert_eq!(res.status(), StatusCode::OK); - let expected_json_body = r#"{"fingerprint_of_foo":{"by":"fingerprint_of_foo","source":"31415926535897932384626433832795028841971693993751058209749445923","target":"fingerprint_of_foo","amount":2,"timestamp":"2021-04-13T20:55:30"}}"#; + let expected_json_body = r#"{"fingerprint_of_foo":{"source":"fingerprint_of_foo","target":"fingerprint_of_foo","amount":2,"timestamp":"2021-04-13T20:55:30"}}"#; assert_eq!(res.body(), expected_json_body); } @@ -231,9 +231,9 @@ MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg== db.pending_transactions.write().insert( "fingerprint_of_some_guy".to_owned(), Transaction { - source: "fingerprint_of_some_guy" + source: "fingerprint_of_some_guy".to_owned(), + target: "31415926535897932384626433832795028841971693993751058209749445923" .to_owned(), - target: "31415926535897932384626433832795028841971693993751058209749445923".to_owned(), amount: 2, timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), }, @@ -420,7 +420,7 @@ MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg== .json(&InitialAuthRequest { 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(), iv: "bmV2ZXJtaW5kdGhlbmZ1aw==".to_owned(), - key: "s4cn9BSmuForX6PxJAa55Es4t2puXuDtdII1lxEArqVlP+uYd5jDKofFtn9PCAoY7jyTgBIhQW7Ah5MGCcufWTaKHAjFVfSZ+qGwbGbBcklbNGH/F7cJ0Pe7kOCddUpIvLG6WH6+mnvyPs8PwDyagsx1Jc2PSSOYLAwkECvPbjiUjQiBixguTRNsU2eKaqzLimPE0w2ztvdA+IgCv94UPhjQfQrnMGK+Ppn3oK7IfKQJ7v2DLVNuz4d/BpwuqD+lYYAu4B4qn3daNR32a/mqAAlPg/RbPlH69N44Qh/NYux90FOY0XKxUskEwsAUw8dHFzzdKPcGx4C0s5e4KSLGkw==".to_owned(), + key: "Xd6/VSuFKqayNHspcFJSm+PAHNoTmcR4SsMijSyuyEh6PS5rdvO4W98AhxW4VBrRO1ljfEMeFq835NEDame511D2pim00Xv0HPIYSDW6pIJA1hy+Np/WyC7PCxvKy0hPzTmHMpFmM+aF43BknJdYlPUhY4cww/xScU6WxuKIsEQNORRhQds8CHOO0EGcOjHVvR2xqnOda1g/rI7mfNMATHj9ZRsB9GH6QG5WTUbo9/71cDAILF+28TG40jSKvY2KzO9vr668tgqoMV2vLnXQa1AD9ZWmdHHdjiXuiH3X0uXxHrfjH7HeXi/HOj/pgCX12jKsEsRwkBTGL4koObH6pQ==".to_owned(), }) .path("/register") .reply(&filter) -- cgit v1.2.3-70-g09d2