Ejemplo n.º 1
0
    public void Role_GetHierarchy()
    {
        PolicyDecision policy = new PolicyDecision(config);
        policy.ApplicationName = "Application 1";

        String[] roles = {"Test Role", "Test Role 2", "Test Role 3"};

        for (Int32 i = 0; i != roles.Length; ++i) {
          if (policy.RoleExists(roles[i]))
        continue;
          if (0 == i)
        policy.CreateRole(roles[i]);
          else
        policy.CreateRole(roles[i], roles[i-1]);
        }

        policy.AddUsersToRoles(new String[] { "User" },
               new String[] { roles[2] });

        String[] userRoles = policy.GetRolesForUser("User");
        Assert.AreEqual(3, userRoles.Length);
        foreach (String role in roles)
          Assert.IsTrue(Array.Exists(userRoles, v => v == role));

        for (Int32 i = roles.Length - 1; i >= 0; --i)
          policy.DeleteRole(roles[i], false);
    }
Ejemplo n.º 2
0
    public void UserRole_InvalidNames()
    {
        PolicyDecision policy = new PolicyDecision(config);

        Type[] expectations = new Type[] {
          typeof(ProviderException),
          typeof(ProviderException),
          typeof(ArgumentException)
        };
        String[] values = new String[] {
          String.Empty,
          null,
          "something , another ,"
        };
        Action<String>[] tests = new Action<String>[] {
          (value) => policy.CreateRole(value),
        (value) => policy.DeleteRole(value, false),
        (value) => policy.RoleExists(value),
        (value) => policy.GetUsersInRole(value),
        (value) => policy.IsUserInRole("Valid", value),
        (value) => policy.IsUserInRole(value, "Valid"),
        (value) => policy.GetRolesForUser(value),
        (value) => policy.FindUsersInRole(value, "Valid"),
        (value) => policy.FindUsersInRole("Valid", value)
        };

        for (Int32 i = 0; i != tests.Length; ++i)
          for (Int32 j = 0; j != values.Length; ++j)
        Assert.Throws(expectations[j], () => tests[i](values[j]));
    }