GithubHelp home page GithubHelp logo

Comments (4)

magahl avatar magahl commented on August 16, 2024
    [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.

bruyer-k avatar bruyer-k commented on August 16, 2024

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.

FoC- avatar FoC- commented on August 16, 2024

Ohhhh ')' in wrong place. Great thanks.

from mongomembership.

FoC- avatar FoC- commented on August 16, 2024

New nuget package is released 0.0.14.

from mongomembership.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.