Uploaded image for project: 'Click'
  1. Click
  2. CLK-585

Implement mock support for Principal and Roles

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.2.0
    • Component/s: mock
    • Labels:
      None

      Description

      Currently there is no way to provide a Principal (user) and Roles for mock tests.

      Sven Pfeiffer provided the following impl on the mainlig list which can be added to the Mock API:

      ====================

      public class AuthenticatedMockRequest extends MockRequest {

      MockPrincipal userPrincipal;

      public AuthenticatedMockRequest(MockPrincipal userPrincipal)

      { this.userPrincipal = userPrincipal; }

      @Override
      public boolean isUserInRole(String name)

      { return userPrincipal.getRoles().contains(name); }

      @Override
      public Principal getUserPrincipal()

      { return userPrincipal; }

      }
      and

      MockPrincipal:
      public class MockPrincipal implements Principal {

      private String name;
      private List<String> roles = new ArrayList<String>();

      public MockPrincipal(String userName)

      { this.name = userName; }

      public MockPrincipal(String userName, List<String> roles)

      { this.name = userName; this.roles = roles; }

      @Override
      public String getName()

      { return name; }

      public List<String> getRoles()

      { return roles; }

      public void setRoles(String... newRoles) {
      roles.clear();
      for (String role : newRoles)

      { roles.add(role); }

      }
      }

      And I added the following lines to my testcase:

      MockPrincipal principal = new MockPrincipal("admin");
      principal.setRoles("admin", "user");
      container.setRequest(new AuthenticatedMockRequest(principal));

        Activity

        Hide
        sabob Bob Schellink added a comment -

        fixed in trunk

        Show
        sabob Bob Schellink added a comment - fixed in trunk

          People

          • Assignee:
            sabob Bob Schellink
            Reporter:
            sabob Bob Schellink
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development