Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/07/10 03:26:15 (14 years ago)
Author:
bfarka
Message:

fixed bugs in membership provider 32 out of 43 tests are now passing.. (#1046)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Services.Authentication Prototype/UnitTests/HeuristicLabMembershipProviderTest.cs

    r4008 r4009  
    8181      bool actual;
    8282      actual = target.RequiresQuestionAndAnswer;
    83       Assert.Inconclusive("Verify the correctness of this test method.");
     83      Assert.IsFalse(actual);
    8484    }
    8585
     
    141141      int actual;
    142142      actual = target.MinRequiredNonAlphanumericCharacters;
    143       Assert.Inconclusive("Verify the correctness of this test method.");
     143      Assert.AreEqual(actual, 0);
    144144    }
    145145
     
    150150    public void MaxInvalidPasswordAttemptsTest() {
    151151      MembershipProvider target = Membership.Provider;
    152       int actual;
    153       actual = target.MaxInvalidPasswordAttempts;
    154       Assert.Inconclusive("Verify the correctness of this test method.");
     152      MembershipCreateStatus status;
     153      target.CreateUser("testUser", "MySuperPassword", "mail", "question", "answer", true, null, out status);
     154      Assert.AreEqual(MembershipCreateStatus.Success, status);
     155
     156      target.ValidateUser("testUser", "MySuperPassword");
     157      Assert.IsFalse(target.GetUser("testUser", true).IsLockedOut);
     158
     159      for (int i = 0; i < target.MaxInvalidPasswordAttempts - 1; i++) {
     160        target.ValidateUser("testUser", "foo");
     161        Assert.IsFalse(target.GetUser("testUser", true).IsLockedOut);
     162      }
     163
     164      target.ValidateUser("testUser", "MySuperPassword");
     165      Assert.IsFalse(target.GetUser("testUser", true).IsLockedOut);
     166
     167
     168      for (int i = 0; i < target.MaxInvalidPasswordAttempts; i++) {
     169        target.ValidateUser("testUser", "foo");
     170        Assert.IsFalse(target.GetUser("testUser", true).IsLockedOut);
     171      }
     172     
     173      target.ValidateUser("testUser", "foo");
     174      Assert.IsTrue(target.GetUser("testUser", true).IsLockedOut);
     175
     176      target.ValidateUser("testUser", "MySuperPassword");
     177      Assert.IsTrue(target.GetUser("testUser", true).IsLockedOut);
     178
    155179    }
    156180
     
    248272      HeuristicLabUser dbUser = db.HeuristicLabUsers.Single(u => u.UserName == "testname");
    249273      Assert.IsFalse(dbUser.Locked);
    250       Assert.IsTrue(dbUser.Locked);
    251274
    252275    }
     
    283306    }
    284307
    285     /// <summary>
    286     ///A test for GetUser
    287     ///</summary>
    288     [TestMethod()]
    289     public void GetUserTest1() {
    290       MembershipProvider target = Membership.Provider; // TODO: Initialize to an appropriate value
    291       object providerUserKey = null; // TODO: Initialize to an appropriate value
    292       bool userIsOnline = false; // TODO: Initialize to an appropriate value
    293       MembershipUser expected = null; // TODO: Initialize to an appropriate value
    294       MembershipUser actual;
    295       actual = target.GetUser(providerUserKey, userIsOnline);
    296       Assert.AreEqual(expected, actual);
    297       Assert.Inconclusive("Verify the correctness of this test method.");
    298     }
    299308
    300309    /// <summary>
     
    304313    public void GetUserTest() {
    305314      MembershipProvider target = Membership.Provider; // TODO: Initialize to an appropriate value
    306       string username = string.Empty; // TODO: Initialize to an appropriate value
    307       bool userIsOnline = false; // TODO: Initialize to an appropriate value
    308       MembershipUser expected = null; // TODO: Initialize to an appropriate value
    309       MembershipUser actual;
    310       actual = target.GetUser(username, userIsOnline);
    311       Assert.AreEqual(expected, actual);
    312       Assert.Inconclusive("Verify the correctness of this test method.");
     315      MembershipCreateStatus status;
     316      target.CreateUser("testUser","myPersonalSecret", "root@nowhere.com","myQuestion", "myAnswer", true, null, out status);
     317      Assert.AreEqual(MembershipCreateStatus.Success, status);
     318      MembershipUser user = target.GetUser("testUser", true);
     319      Assert.AreEqual(user.UserName, "testUser");
     320      Assert.AreEqual(user.Email, "root@nowhere.com");
     321      Assert.AreEqual(user.PasswordQuestion, "myQuestion");
     322      Assert.IsTrue(target.ValidateUser("testUser", "myPersonalSecret"));
     323     
    313324    }
    314325
     
    511522      // gibt zwar true zurück, was schon mal gut ist
    512523      Assert.IsTrue(target.ChangePasswordQuestionAndAnswer("testname", "INIT", "newquestion", "newanswer"));
    513       // aber hier ist die änderung noch nicht da!! es ist immer noch die alte frage + alte antwort
     524      db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, u);
    514525      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
    515526      Assert.AreEqual<String>("newquestion", u.PasswordQuestion);
     
    522533    [TestMethod()]
    523534    public void ChangePasswordTest() {
     535      MembershipProvider target = Membership.Provider;
     536     
    524537      // create user
    525538      HeuristicLabUser u = new HeuristicLabUser("testname", "testemail", "testquestion", "testcomment");
     539      u.Password = ((HeuristicLabMembershipProvider)target).EncodePassword("INIT");
    526540      db.HeuristicLabUsers.InsertOnSubmit(u);
    527541      db.SubmitChanges();
     
    529543      // check if user is stored
    530544      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
    531       Assert.AreEqual<String>("INIT", u.Password);
     545      Assert.AreEqual<String>(((HeuristicLabMembershipProvider)target).EncodePassword("INIT"), u.Password);
    532546
    533547      // change data and check again
    534       MembershipProvider target = Membership.Provider;
    535548      Assert.IsTrue(target.ChangePassword("testname", "INIT", "newPassword"));
    536       // hat nix gemacht!! :(
     549      db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, u);
    537550      u = db.HeuristicLabUsers.Single<HeuristicLabUser>(x => x.UserName == "testname");
    538       Assert.AreEqual<String>("newPassword", u.Password);
     551      Assert.AreEqual<String>(((HeuristicLabMembershipProvider)target).EncodePassword("newPassword"), u.Password);
    539552    }
    540553
Note: See TracChangeset for help on using the changeset viewer.