Changeset 3956
- Timestamp:
- 06/26/10 10:18:57 (15 years ago)
- Location:
- branches/HeuristicLab.Services.Authentication Prototype
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Services.Authentication Prototype/HeuristicLab.Services.Authentication Prototyp.sln
r3953 r3956 11 11 ProjectSection(SolutionItems) = preProject 12 12 HeuristicLab.Services.Authentication Prototyp.vsmdi = HeuristicLab.Services.Authentication Prototyp.vsmdi 13 HeuristicLab.Services.Authentication Prototyp 1.vsmdi = HeuristicLab.Services.Authentication Prototyp1.vsmdi13 HeuristicLab.Services.Authentication Prototyp2.vsmdi = HeuristicLab.Services.Authentication Prototyp2.vsmdi 14 14 LocalTestRun.testrunconfig = LocalTestRun.testrunconfig 15 15 EndProjectSection … … 17 17 Global 18 18 GlobalSection(TestCaseManagementSettings) = postSolution 19 CategoryFile = HeuristicLab.Services.Authentication Prototyp 1.vsmdi19 CategoryFile = HeuristicLab.Services.Authentication Prototyp2.vsmdi 20 20 EndGlobalSection 21 21 GlobalSection(SolutionConfigurationPlatforms) = preSolution -
branches/HeuristicLab.Services.Authentication Prototype/Service/Provider/HeuristicLabMembershipProvider.cs
r3948 r3956 16 16 17 17 public override bool ChangePassword(string username, string oldPassword, string newPassword) { 18 DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 19 if (db == null) { 20 return false; 21 } 22 try { 23 HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username); 24 if (u.ChangePassword(oldPassword, newPassword)) { 18 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 19 // check database connection 20 if (db == null) { 21 return false; 22 } 23 try { 24 // try to get user 25 HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username); 26 if (u.ChangePassword(oldPassword, newPassword)) { 27 // save user to database only if needed 28 db.SubmitChanges(); 29 return true; 30 } else { 31 return false; 32 } 33 } 34 catch (Exception) { 35 return false; 36 } 37 } 38 } 39 40 public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { 41 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 42 // check database connection 43 if (db == null) { 44 return false; 45 } 46 try { 47 // try to get user 48 HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username); 49 if (u.ChangePasswordQuestionAndAnswer(password, newPasswordQuestion, newPasswordAnswer)) { 50 // save user to database only if needed 51 db.SubmitChanges(); 52 return true; 53 } else { 54 return false; 55 } 56 } 57 catch (Exception) { 58 return false; 59 } 60 } 61 } 62 63 public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { 64 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 65 // check database connection 66 if (db == null) { 67 status = MembershipCreateStatus.ProviderError; 68 return null; 69 } 70 try { 71 // check for duplicate entries 72 if (db.HeuristicLabUsers.Count(x => x.UserName == username) > 0) { 73 status = MembershipCreateStatus.DuplicateUserName; 74 return null; 75 } 76 if (db.HeuristicLabUsers.Count(x => x.Email == email) > 0) { 77 status = MembershipCreateStatus.DuplicateEmail; 78 return null; 79 } 80 81 // create new user 82 HeuristicLabUser u = new HeuristicLabUser(username, email, passwordQuestion, ""); 83 u.ChangePassword("INIT", password); 84 u.ChangePasswordQuestionAndAnswer(password, passwordQuestion, passwordAnswer); 85 // save user into database 86 db.HeuristicLabUsers.InsertOnSubmit(u); 87 db.SubmitChanges(); 88 89 // success 90 status = MembershipCreateStatus.Success; 91 return u; 92 } 93 catch (Exception) { 94 // error 95 status = MembershipCreateStatus.ProviderError; 96 return null; 97 } 98 } 99 } 100 101 public override bool DeleteUser(string username, bool deleteAllRelatedData) { 102 using (DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext()) { 103 // check database connection 104 if (db == null) { 105 return false; 106 } 107 try { 108 // try to get user 109 HeuristicLabUser u = 110 db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == username); 111 112 // optionally delete related data 113 if (deleteAllRelatedData) { 114 db.HeuristicLabUserRole.DeleteAllOnSubmit<HeuristicLabUserRole>(u.HeuristicLabUserRole); 115 } 116 117 // delete user 118 db.HeuristicLabUsers.DeleteOnSubmit(u); 25 119 db.SubmitChanges(); 26 120 return true; 27 } else { 28 return false; 29 } 30 } 31 catch (Exception) { 32 return false; 33 } 34 } 35 36 public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) { 37 DataClassesDataContext db = DatabaseUtil.createDataClassesDataContext(); 38 if (db == null) { 39 return false; 40 } 41 try { 42 HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == username); 43 if (u.ChangePasswordQuestionAndAnswer(password, newPasswordQuestion, newPasswordAnswer)) { 44 db.SubmitChanges(); 45 return true; 46 } else { 47 return false; 48 } 49 } 50 catch (Exception) { 51 return false; 52 } 53 } 54 55 public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { 56 throw new NotImplementedException(); 57 } 58 59 public override bool DeleteUser(string username, bool deleteAllRelatedData) { 60 throw new NotImplementedException(); 121 } 122 catch (Exception) { 123 return false; 124 } 125 } 61 126 } 62 127 … … 86 151 87 152 public override string GetPassword(string username, string answer) { 153 88 154 throw new NotImplementedException(); 89 155 } -
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs
r3948 r3956 1 using Service.Provider; 1 using System; 2 using Service.Provider; 2 3 using Microsoft.VisualStudio.TestTools.UnitTesting; 3 4 using System.Web.Security; 5 using Persistence; 6 using System.Linq; 7 using System.Collections.Generic; 4 8 5 9 namespace UnitTests { … … 368 372 [TestMethod()] 369 373 public void DeleteUserTest() { 370 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value 371 string username = string.Empty; // TODO: Initialize to an appropriate value 372 bool deleteAllRelatedData = false; // TODO: Initialize to an appropriate value 373 bool expected = false; // TODO: Initialize to an appropriate value 374 bool actual; 375 actual = target.DeleteUser(username, deleteAllRelatedData); 376 Assert.AreEqual(expected, actual); 377 Assert.Inconclusive("Verify the correctness of this test method."); 374 // insert new user 375 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); 376 MembershipCreateStatus status; 377 target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status); 378 Assert.AreEqual(MembershipCreateStatus.Success, status); 379 380 // delete user 381 Assert.IsTrue(target.DeleteUser("testname", true)); 382 Assert.AreEqual(0, db.HeuristicLabUsers.Count(x => x.UserName == "testname")); 378 383 } 379 384 … … 383 388 [TestMethod()] 384 389 public void CreateUserTest() { 385 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value 386 string username = string.Empty; // TODO: Initialize to an appropriate value 387 string password = string.Empty; // TODO: Initialize to an appropriate value 388 string email = string.Empty; // TODO: Initialize to an appropriate value 389 string passwordQuestion = string.Empty; // TODO: Initialize to an appropriate value 390 string passwordAnswer = string.Empty; // TODO: Initialize to an appropriate value 391 bool isApproved = false; // TODO: Initialize to an appropriate value 392 object providerUserKey = null; // TODO: Initialize to an appropriate value 393 MembershipCreateStatus status = new MembershipCreateStatus(); // TODO: Initialize to an appropriate value 394 MembershipCreateStatus statusExpected = new MembershipCreateStatus(); // TODO: Initialize to an appropriate value 395 MembershipUser expected = null; // TODO: Initialize to an appropriate value 396 MembershipUser actual; 397 actual = target.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status); 398 Assert.AreEqual(statusExpected, status); 399 Assert.AreEqual(expected, actual); 400 Assert.Inconclusive("Verify the correctness of this test method."); 390 // create user 391 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); 392 MembershipCreateStatus status; 393 target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status); 394 Assert.AreEqual(MembershipCreateStatus.Success, status); 395 396 // check if user is OK 397 HeuristicLabUser u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname"); 398 Assert.AreEqual<string>("testname", u.UserName); 399 Assert.AreEqual<string>("testemail", u.Email); 400 Assert.AreEqual<string>("newPassword", u.Password); 401 Assert.AreEqual<string>("testquestion", u.PasswordQuestion); 402 Assert.AreEqual<string>("testanswer", u.PasswordAnswer); 403 Assert.AreEqual<string>("", u.Comment); 404 405 // check for duplicate errors 406 target.CreateUser("testname", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status); 407 Assert.AreEqual(MembershipCreateStatus.DuplicateUserName, status); 408 target.CreateUser("testname2", "newPassword", "testemail", "testquestion", "testanswer", true, null, out status); 409 Assert.AreEqual(MembershipCreateStatus.DuplicateEmail, status); 401 410 } 402 411 … … 406 415 [TestMethod()] 407 416 public void ChangePasswordQuestionAndAnswerTest() { 408 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value 409 string username = string.Empty; // TODO: Initialize to an appropriate value 410 string password = string.Empty; // TODO: Initialize to an appropriate value 411 string newPasswordQuestion = string.Empty; // TODO: Initialize to an appropriate value 412 string newPasswordAnswer = string.Empty; // TODO: Initialize to an appropriate value 413 bool expected = false; // TODO: Initialize to an appropriate value 414 bool actual; 415 actual = target.ChangePasswordQuestionAndAnswer(username, password, newPasswordQuestion, newPasswordAnswer); 416 Assert.AreEqual(expected, actual); 417 Assert.Inconclusive("Verify the correctness of this test method."); 417 // create user 418 HeuristicLabUser u = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 419 db.HeuristicLabUsers.InsertOnSubmit(u); 420 db.SubmitChanges(); 421 422 // check if user is stored 423 u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname"); 424 Assert.AreEqual<String>("testquestion", u.PasswordQuestion); 425 Assert.AreEqual<String>("", u.PasswordAnswer); 426 427 // change data and check again 428 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); 429 // gibt zwar true zurück, was schon mal gut ist 430 Assert.IsTrue(target.ChangePasswordQuestionAndAnswer("testname", "INIT", "newquestion", "newanswer")); 431 // aber hier ist die änderung noch nicht da!! es ist immer noch die alte frage + alte antwort 432 u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname"); 433 Assert.AreEqual<String>("newquestion", u.PasswordQuestion); 434 Assert.AreEqual<String>("newanswer", u.PasswordAnswer); 418 435 } 419 436 … … 423 440 [TestMethod()] 424 441 public void ChangePasswordTest() { 425 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); // TODO: Initialize to an appropriate value 426 string username = string.Empty; // TODO: Initialize to an appropriate value 427 string oldPassword = string.Empty; // TODO: Initialize to an appropriate value 428 string newPassword = string.Empty; // TODO: Initialize to an appropriate value 429 bool expected = false; // TODO: Initialize to an appropriate value 430 bool actual; 431 actual = target.ChangePassword(username, oldPassword, newPassword); 432 Assert.AreEqual(expected, actual); 433 Assert.Inconclusive("Verify the correctness of this test method."); 442 // create user 443 HeuristicLabUser u = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 444 db.HeuristicLabUsers.InsertOnSubmit(u); 445 db.SubmitChanges(); 446 447 // check if user is stored 448 u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname"); 449 Assert.AreEqual<String>("INIT", u.Password); 450 451 // change data and check again 452 HeuristicLabMembershipProvider target = new HeuristicLabMembershipProvider(); 453 Assert.IsTrue(target.ChangePassword("testname", "INIT", "newPassword")); 454 // hat nix gemacht!! :( 455 u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname"); 456 Assert.AreEqual<String>("newPassword", u.Password); 434 457 } 435 458 -
branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabUserTest.cs
r3949 r3956 20 20 public void modifyUserTest() { 21 21 // insert new user 22 Persistence.HeuristicLabUser user = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");22 HeuristicLabUser user = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment"); 23 23 db.HeuristicLabUsers.InsertOnSubmit(user); 24 24 db.SubmitChanges(); 25 Persistence.HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == "testname");25 HeuristicLabUser u = db.HeuristicLabUsers.Single(x => x.UserName == "testname"); 26 26 Assert.IsNotNull(u); 27 27 Assert.AreEqual<string>("testname", u.UserName);
Note: See TracChangeset
for help on using the changeset viewer.