aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoralpaylan2021-04-14 16:36:42 +0300
committeralpaylan2021-04-14 16:36:42 +0300
commit6a6cfcd2df56938aa356e20e4728552a8c2ee8aa (patch)
tree0d9b6d616c31fcd35883fe8619633cdbaec09a49 /tests
parent2bce40bfeaefc64083d285233777983af5345ce5 (diff)
downloadgradecoin-6a6cfcd2df56938aa356e20e4728552a8c2ee8aa.tar.gz
gradecoin-6a6cfcd2df56938aa356e20e4728552a8c2ee8aa.tar.bz2
gradecoin-6a6cfcd2df56938aa356e20e4728552a8c2ee8aa.zip
embed user passwds to the code structs.
Diffstat (limited to 'tests')
-rw-r--r--tests/route_tests.rs4
-rw-r--r--tests/schema_tests.rs28
2 files changed, 21 insertions, 11 deletions
diff --git a/tests/route_tests.rs b/tests/route_tests.rs
index 7c0651f..5c2d891 100644
--- a/tests/route_tests.rs
+++ b/tests/route_tests.rs
@@ -12,7 +12,7 @@ mod tests {
12 db.users.write().insert( 12 db.users.write().insert(
13 "mock_transaction_source".to_owned(), 13 "mock_transaction_source".to_owned(),
14 User { 14 User {
15 user_id: MetuId::new("e254275".to_owned()).unwrap(), 15 user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
16 public_key: "-----BEGIN PUBLIC KEY----- 16 public_key: "-----BEGIN PUBLIC KEY-----
17MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4nU0G4WjkmcQUx0hq6LQ 17MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4nU0G4WjkmcQUx0hq6LQ
18uV5Q+ACmUFL/OjoYMDwC/O/6pCd1UZgCfgHN2xEffDPznzcTn8OiFRxr4oWyBiny 18uV5Q+ACmUFL/OjoYMDwC/O/6pCd1UZgCfgHN2xEffDPznzcTn8OiFRxr4oWyBiny
@@ -56,6 +56,7 @@ sQIDAQAB
56 fn priviliged_mocked_user() -> AuthRequest { 56 fn priviliged_mocked_user() -> AuthRequest {
57 AuthRequest { 57 AuthRequest {
58 student_id: String::from("e254275"), 58 student_id: String::from("e254275"),
59 passwd: String::from("DtNX1qk4YF4saRH"),
59 public_key: "NOT IMPLEMENTED".to_owned(), 60 public_key: "NOT IMPLEMENTED".to_owned(),
60 } 61 }
61 } 62 }
@@ -64,6 +65,7 @@ sQIDAQAB
64 fn unpriviliged_mocked_user() -> AuthRequest { 65 fn unpriviliged_mocked_user() -> AuthRequest {
65 AuthRequest { 66 AuthRequest {
66 student_id: String::from("foobarbaz"), 67 student_id: String::from("foobarbaz"),
68 passwd: String::from("DtNX1qk4YF4saRH"),
67 public_key: "NOT IMPLEMENTED".to_owned(), 69 public_key: "NOT IMPLEMENTED".to_owned(),
68 } 70 }
69 } 71 }
diff --git a/tests/schema_tests.rs b/tests/schema_tests.rs
index c1880b9..4240a5f 100644
--- a/tests/schema_tests.rs
+++ b/tests/schema_tests.rs
@@ -192,7 +192,7 @@ mod tests {
192 #[test] 192 #[test]
193 fn user_serialize_correctly() { 193 fn user_serialize_correctly() {
194 let user = User { 194 let user = User {
195 user_id: MetuId::new("e254275".to_owned()).unwrap(), 195 user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
196 public_key: "public_key".to_owned(), 196 public_key: "public_key".to_owned(),
197 balance: 0 197 balance: 0
198 }; 198 };
@@ -202,9 +202,11 @@ mod tests {
202 &[ 202 &[
203 Token::Struct{name: "User", len: 3}, 203 Token::Struct{name: "User", len: 3},
204 Token::String("user_id"), 204 Token::String("user_id"),
205 Token::Struct {name: "MetuId", len: 1}, 205 Token::Struct {name: "MetuId", len: 2},
206 Token::String("id"), 206 Token::String("id"),
207 Token::String("e254275"), 207 Token::String("e254275"),
208 Token::String("passwd"),
209 Token::String("DtNX1qk4YF4saRH"),
208 Token::StructEnd, 210 Token::StructEnd,
209 Token::String("public_key"), 211 Token::String("public_key"),
210 Token::String("public_key"), 212 Token::String("public_key"),
@@ -218,11 +220,11 @@ mod tests {
218 #[test] 220 #[test]
219 fn user_deserialize_correctly() { 221 fn user_deserialize_correctly() {
220 let expected_user = User { 222 let expected_user = User {
221 user_id: MetuId::new("e254275".to_owned()).unwrap(), 223 user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
222 public_key: "public_key".to_owned(), 224 public_key: "public_key".to_owned(),
223 balance: 0 225 balance: 0
224 }; 226 };
225 let data = r#"{"user_id":{"id":"e254275"},"public_key":"public_key","balance":0}"#; 227 let data = r#"{"user_id":{"id":"e254275","passwd":"DtNX1qk4YF4saRH"},"public_key":"public_key","balance":0}"#;
226 let user: User = serde_json::from_str(data).unwrap(); 228 let user: User = serde_json::from_str(data).unwrap();
227 229
228 assert_eq!(user, expected_user); 230 assert_eq!(user, expected_user);
@@ -231,14 +233,16 @@ mod tests {
231 233
232 #[test] 234 #[test]
233 fn metu_id_serialize_correctly() { 235 fn metu_id_serialize_correctly() {
234 let metu_id = MetuId::new ("e254275".to_owned()).unwrap(); 236 let metu_id = MetuId::new ("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap();
235 237
236 assert_tokens( 238 assert_tokens(
237 &metu_id, 239 &metu_id,
238 &[ 240 &[
239 Token::Struct{name: "MetuId", len: 1}, 241 Token::Struct{name: "MetuId", len: 2},
240 Token::String("id"), 242 Token::String("id"),
241 Token::String("e254275"), 243 Token::String("e254275"),
244 Token::String("passwd"),
245 Token::String("DtNX1qk4YF4saRH"),
242 Token::StructEnd, 246 Token::StructEnd,
243 ] 247 ]
244 ) 248 )
@@ -246,8 +250,8 @@ mod tests {
246 250
247 #[test] 251 #[test]
248 fn metu_id_deserialize_correctly() { 252 fn metu_id_deserialize_correctly() {
249 let expected_metu_id = MetuId::new ("e254275".to_owned()).unwrap(); 253 let expected_metu_id = MetuId::new ("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap();
250 let data = r#"{"id":"e254275"}"#; 254 let data = r#"{"id":"e254275","passwd":"DtNX1qk4YF4saRH"}"#;
251 let metu_id: MetuId = serde_json::from_str(data).unwrap(); 255 let metu_id: MetuId = serde_json::from_str(data).unwrap();
252 256
253 assert_eq!(metu_id, expected_metu_id); 257 assert_eq!(metu_id, expected_metu_id);
@@ -257,15 +261,18 @@ mod tests {
257 fn auth_request_serialize_correctly() { 261 fn auth_request_serialize_correctly() {
258 let auth_request = AuthRequest { 262 let auth_request = AuthRequest {
259 student_id: "e254275".to_owned(), 263 student_id: "e254275".to_owned(),
264 passwd: "DtNX1qk4YF4saRH".to_owned(),
260 public_key: "public_key".to_owned() 265 public_key: "public_key".to_owned()
261 }; 266 };
262 267
263 assert_tokens( 268 assert_tokens(
264 &auth_request, 269 &auth_request,
265 &[ 270 &[
266 Token::Struct{name: "AuthRequest", len: 2}, 271 Token::Struct{name: "AuthRequest", len: 3},
267 Token::String("student_id"), 272 Token::String("student_id"),
268 Token::String("e254275"), 273 Token::String("e254275"),
274 Token::String("passwd"),
275 Token::String("DtNX1qk4YF4saRH"),
269 Token::String("public_key"), 276 Token::String("public_key"),
270 Token::String("public_key"), 277 Token::String("public_key"),
271 Token::StructEnd, 278 Token::StructEnd,
@@ -277,9 +284,10 @@ mod tests {
277 fn auth_request_deserialize_correctly() { 284 fn auth_request_deserialize_correctly() {
278 let expected_auth_request = AuthRequest { 285 let expected_auth_request = AuthRequest {
279 student_id: "e254275".to_owned(), 286 student_id: "e254275".to_owned(),
287 passwd: "DtNX1qk4YF4saRH".to_owned(),
280 public_key: "public_key".to_owned() 288 public_key: "public_key".to_owned()
281 }; 289 };
282 let data = r#"{"student_id":"e254275","public_key":"public_key"}"#; 290 let data = r#"{"student_id":"e254275","passwd":"DtNX1qk4YF4saRH","public_key":"public_key"}"#;
283 let auth_request: AuthRequest = serde_json::from_str(data).unwrap(); 291 let auth_request: AuthRequest = serde_json::from_str(data).unwrap();
284 292
285 assert_eq!(auth_request, expected_auth_request); 293 assert_eq!(auth_request, expected_auth_request);