Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Failing unit test added for 2nd level cache issue #8

Open
wants to merge 1 commit into from

1 participant

@davidarcher

I've added a failing unit test that shows the issue I (along with others) have experienced when using Rhino.Security along with a 2nd level cache. Specifically, when associating/detaching users from usersgroups, the cache is not being invalidated properly and the next call to get the users groups ends up returning the cached query.

http://groups.google.com/group/rhino-tools-dev/browse_thread/thread/942db39264ff76e3
http://groups.google.com/group/rhino-tools-dev/browse_thread/thread/c7c8e448c82539a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 23, 2011
  1. @davidarcher

    Added unit test for removing user from usersgroup and validating seco…

    davidarcher authored
    …nd level cache is invalidated correctly
This page is out of date. Refresh to see the latest.
View
45 Rhino.Security.Tests/AuthorizationServiceWithSecondLevelCacheFixture.cs
@@ -1,6 +1,8 @@
+using System;
using System.IO;
using Microsoft.Practices.ServiceLocation;
using Rhino.Security.Interfaces;
+using Rhino.Security.Model;
using Xunit;
namespace Rhino.Security.Tests
@@ -73,5 +75,48 @@ public void UseSecondLevelCacheForSecurityQuestions()
s3.Transaction.Commit();
}
}
+
+ [Fact]
+ public void RemovingUserFromGroupInvalidatesSecondLevelCache()
+ {
+ var users = authorizationRepository.CreateUsersGroup("Users");
+ authorizationRepository.AssociateUserWith(user, users);
+
+ session.Flush();
+ session.Transaction.Commit();
+ session.Dispose();
+
+ using (var s1 = factory.OpenSession())
+ using (var tx = s1.BeginTransaction())
+ {
+ SillyContainer.SessionProvider = () => s1;
+ var anotherAuthorizationRepository = ServiceLocator.Current.GetInstance<IAuthorizationRepository>();
+ UsersGroup[] initialGroups = anotherAuthorizationRepository.GetAssociatedUsersGroupFor(user);
+ Assert.Equal(2, initialGroups.Length);
+ Assert.Equal("Administrators", initialGroups[0].Name);
+ Assert.Equal("Users", initialGroups[1].Name);
+ tx.Commit();
+ }
+
+ using (var s2 = factory.OpenSession())
+ using (var tx = s2.BeginTransaction())
+ {
+ SillyContainer.SessionProvider = () => s2;
+ var anotherAuthorizationRepository = ServiceLocator.Current.GetInstance<IAuthorizationRepository>();
+ anotherAuthorizationRepository.DetachUserFromGroup(user, "Users");
+ tx.Commit();
+ }
+
+ using (var s3 = factory.OpenSession())
+ using (var tx = s3.BeginTransaction())
+ {
+ SillyContainer.SessionProvider = () => s3;
+ var anotherAuthorizationRepository = ServiceLocator.Current.GetInstance<IAuthorizationRepository>();
+ UsersGroup[] newGroups = anotherAuthorizationRepository.GetAssociatedUsersGroupFor(user);
+ Assert.Equal(1, newGroups.Length);
+ Assert.Equal("Administrators", newGroups[0].Name);
+ tx.Commit();
+ }
+ }
}
}
Something went wrong with that request. Please try again.