Comments (4)
[Subject(typeof(MongoRoleProvider))]
internal class When_AddUsersToRoles_is_called_twice : StubsBase
{
private static MongoRoleProvider provider;
private static IMongoGateway mongo;
private static string roleName;
private Establish conext = () =>
{
roleName = "admin";
provider = CreateRoleProvider();
mongo = CreateMongoGateway();
MembershipCreateStatus status;
var firstUser = CreateUser("MongoMembershipProviderTest");
firstUser.Username = "user1";
firstUser.Id = "userID-1";
mongo.CreateUser(firstUser);
var secondUser = CreateUser("MongoMembershipProviderTest");
secondUser.Username = "user2";
firstUser.Id = "userID-2";
mongo.CreateUser(secondUser);
};
private Because of_adding_two_users_to_same_role = () =>
{
provider.AddUsersToRoles(new[] { "user1" }, new[] { roleName });
provider.AddUsersToRoles(new[] { "user2" }, new[] { roleName });
};
private It should_add_role_too_both_users= () =>
{
var roles = provider.GetUsersInRole(roleName);
roles.ShouldContain("user1", "user2");
};
private Cleanup staff = () =>
{
mongo.DropRoles();
mongo.DropUsers();
};
}
Failing test to prove redbit86k bug report
from mongomembership.
There's a bug, the line is defective, it won't work the way it's intended to.
return UsersCollection
.AsQueryable()
.Any(user
=> user.ApplicationName == applicationName
&& user.UsernameLowercase == username.ToLowerInvariant()
&& (user.Roles.Contains(roleName.ToLowerInvariant())) || user.Roles.Contains(roleName));
If you read the line, you'll see that it match any user which usernameLowercase is username and which contains the role roleName in its Roles OR any user which has the role roleName in its Roles, which means ANY user, not the one we're looking for.
Since the aim of the function is to determine wether the userIsInRole
, that's a bug, we can see it without testing.
The best solution is
return UsersCollection
.AsQueryable()
.Any(user
=> user.ApplicationName == applicationName
&& user.UsernameLowercase == username.ToLowerInvariant()
&& (user.Roles.Contains(roleName.ToLowerInvariant()) || user.Roles.Contains(roleName)));
Because we want to be able to add the Role in Lower case or in its 'original case'.
from mongomembership.
Ohhhh ')' in wrong place. Great thanks.
from mongomembership.
New nuget package is released 0.0.14.
from mongomembership.
Related Issues (9)
- Searches (FindUsersByName, for example) throw an exception because the MongoDB driver doesn't support ToLowerInvariant HOT 1
- MongoCommandException always occurs in CreateIndex()
- Error in Membership.CreateUser(string username, string password) method causes null reference exception HOT 1
- Licensing HOT 1
- Case Sensitivity inconsistency HOT 2
- Updating Mongo C# driver HOT 2
- Breaks With new MongoDB Driver v2.0 HOT 11
- Tests and Sample Web projects doesn't work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongomembership.