aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/handlers.rs2
-rw-r--r--src/schema.rs41
-rw-r--r--tests/route_tests.rs4
-rw-r--r--tests/schema_tests.rs28
4 files changed, 55 insertions, 20 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index e34abbe..b9df931 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -39,7 +39,7 @@ pub async fn authenticate_user(
39 debug!("POST request to /register, authenticate_user"); 39 debug!("POST request to /register, authenticate_user");
40 let provided_id = request.student_id.clone(); 40 let provided_id = request.student_id.clone();
41 41
42 let priv_student_id = match MetuId::new(request.student_id) { 42 let priv_student_id = match MetuId::new(request.student_id, request.passwd) {
43 Some(id) => id, 43 Some(id) => id,
44 None => { 44 None => {
45 let res_json = warp::reply::json(&GradeCoinResponse { 45 let res_json = warp::reply::json(&GradeCoinResponse {
diff --git a/src/schema.rs b/src/schema.rs
index 55e46c0..65150c1 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -132,22 +132,47 @@ pub struct User {
132#[derive(Serialize, Deserialize, Debug, PartialEq)] 132#[derive(Serialize, Deserialize, Debug, PartialEq)]
133pub struct MetuId { 133pub struct MetuId {
134 id: String, 134 id: String,
135 passwd: String,
135} 136}
136 137
137// TODO: this will arrive encrypted <13-04-21, yigit> // 138// TODO: this will arrive encrypted <13-04-21, yigit> //
138#[derive(Serialize, Deserialize, Debug, PartialEq)] 139#[derive(Serialize, Deserialize, Debug, PartialEq)]
139pub struct AuthRequest { 140pub struct AuthRequest {
140 pub student_id: String, 141 pub student_id: String,
142 pub passwd: String,
141 pub public_key: String, 143 pub public_key: String,
142} 144}
143 145
144lazy_static! { 146lazy_static! {
145 static ref OUR_STUDENTS: HashSet<&'static str> = { 147 static ref OUR_STUDENTS: HashSet<(&'static str, &'static str)> = {
146 [ 148 [
147 "e254275", "e223687", "e211024", "e209888", "e223725", "e209362", "e209898", "e230995", 149 ("e254275", "DtNX1qk4YF4saRH"),
148 "e223743", "e223747", "e223749", "e223751", "e188126", "e209913", "e203608", "e233013", 150 ("e223687", "cvFEs4XLjuGBD1v"),
149 "e216982", "e217185", "e223780", "e194931", "e223783", "e254550", "e217203", "e217477", 151 ("e211024", "voQAcxiKJmEXYRT"),
150 "e223786", "e231060", "e223795", 152 ("e209888", "O75dli6AQtz2tUi"),
153 ("e223725", "xXuTD3Y4tyrv2Jz"),
154 ("e209362", "N7wGm5XU5zVWOWu"),
155 ("e209898", "aKBFfB8fZMq8pVn"),
156 ("e230995", "TgcHGlqeFhQGx42"),
157 ("e223743", "YVWVSWuIHplJk9C"),
158 ("e223747", "8LAeHrsjnwXh59Q"),
159 ("e223749", "HMFeJqVOzwCPHbc"),
160 ("e223751", "NjMsxmtmy2VOwMW"),
161 ("e188126", "QibuPdV2gXfsVJW"),
162 ("e209913", "kMxJvl2vHSWCy4A"),
163 ("e203608", "mfkkR0MWurk6Rp1"),
164 ("e233013", "GCqHxdOaDj2pWXx"),
165 ("e216982", "2Z0xmgCStnj5qg5"),
166 ("e217185", "BcaZNlzlhPph7A3"),
167 ("e223780", "2KvVxKUQaA9H4sn"),
168 ("e194931", "hsC0Wb8PQ5vzwdQ"),
169 ("e223783", "ETUJA3kt1QYvJai"),
170 ("e254550", "rPRjX0A4NefvKWi"),
171 ("e217203", "lN3IWhGyCrGfkk5"),
172 ("e217477", "O9xlMaa7LanC82w"),
173 ("e223786", "UxI6czykJfp9T9N"),
174 ("e231060", "VJgziofQQPCoisH"),
175 ("e223795", "pmcTCKox99NFsqp"),
151 ] 176 ]
152 .iter() 177 .iter()
153 .cloned() 178 .cloned()
@@ -162,9 +187,9 @@ impl fmt::Display for MetuId {
162} 187}
163 188
164impl MetuId { 189impl MetuId {
165 pub fn new(id: String) -> Option<Self> { 190 pub fn new(id: String, pwd: String) -> Option<Self> {
166 if OUR_STUDENTS.contains(&*id) { 191 if OUR_STUDENTS.contains(&(&*id, &*pwd)) {
167 Some(MetuId { id: id }) 192 Some(MetuId { id: id, passwd: pwd })
168 } else { 193 } else {
169 None 194 None
170 } 195 }
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);