Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testUserResourceOptionsDeleteAuthorized()
        public virtual void testUserResourceOptionsDeleteAuthorized()
        {
            string fullUserUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/user/" + MockProvider.EXAMPLE_USER_ID;

            User      sampleUser      = MockProvider.createMockUser();
            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(sampleUser);

            Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null);

            when(identityServiceMock.CurrentAuthentication).thenReturn(authentication);
            when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, USER, MockProvider.EXAMPLE_USER_ID)).thenReturn(true);
            when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, USER, MockProvider.EXAMPLE_USER_ID)).thenReturn(false);

            when(processEngineConfigurationMock.AuthorizationEnabled).thenReturn(true);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).then().statusCode(Status.OK.StatusCode).body("links[0].href", equalTo(fullUserUrl + "/profile")).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1].href", equalTo(fullUserUrl)).body("links[1].method", equalTo(HttpMethod.DELETE)).body("links[1].rel", equalTo("delete")).body("links[2]", nullValue()).when().options(USER_URL);

            verify(identityServiceMock, times(2)).CurrentAuthentication;
            verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, USER, MockProvider.EXAMPLE_USER_ID);
            verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, USER, MockProvider.EXAMPLE_USER_ID);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testChangeCredentials()
        public virtual void testChangeCredentials()
        {
            User      initialUser     = MockProvider.createMockUser();
            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            Authentication authentication = MockProvider.createMockAuthentication();

            when(identityServiceMock.CurrentAuthentication).thenReturn(authentication);

            when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(true);

            UserCredentialsDto dto = new UserCredentialsDto();

            dto.Password = "******";
            dto.AuthenticatedUserPassword = MockProvider.EXAMPLE_USER_PASSWORD;

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.NO_CONTENT.StatusCode).when().put(USER_CREDENTIALS_URL);

            verify(identityServiceMock).CurrentAuthentication;
            verify(identityServiceMock).checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD);

            // password was updated
            verify(initialUser).Password = dto.Password;

            // and then saved
            verify(identityServiceMock).saveUser(initialUser);
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testReadOnlyPutUserCredentialsFails()
        public virtual void testReadOnlyPutUserCredentialsFails()
        {
            User userUdpdate = MockProvider.createMockUser();

            when(identityServiceMock.ReadOnly).thenReturn(true);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(UserCredentialsDto.fromUser(userUdpdate)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", equalTo("Identity service implementation is read-only.")).when().put(USER_CREDENTIALS_URL);

            verify(identityServiceMock, never()).saveUser(userUdpdate);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testReadOnlyUserCreateFails()
        public virtual void testReadOnlyUserCreateFails()
        {
            User newUser = MockProvider.createMockUser();

            when(identityServiceMock.ReadOnly).thenReturn(true);

            given().body(UserDto.fromUser(newUser, true)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", equalTo("Identity service implementation is read-only.")).when().post(USER_CREATE_URL);

            verify(identityServiceMock, never()).newUser(MockProvider.EXAMPLE_USER_ID);
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testUserCreateThrowsAuthorizationException()
        public virtual void testUserCreateThrowsAuthorizationException()
        {
            User   newUser = MockProvider.createMockUser();
            string message = "exception expected";

            when(identityServiceMock.newUser(MockProvider.EXAMPLE_USER_ID)).thenThrow(new AuthorizationException(message));

            UserDto userDto = UserDto.fromUser(newUser, true);

            given().body(userDto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(AuthorizationException).Name)).body("message", equalTo(message)).when().post(USER_CREATE_URL);
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testGetSingleUserProfile()
        public virtual void testGetSingleUserProfile()
        {
            User      sampleUser      = MockProvider.createMockUser();
            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(sampleUser);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).then().statusCode(Status.OK.StatusCode).body("id", equalTo(MockProvider.EXAMPLE_USER_ID)).body("firstName", equalTo(MockProvider.EXAMPLE_USER_FIRST_NAME)).body("lastName", equalTo(MockProvider.EXAMPLE_USER_LAST_NAME)).body("email", equalTo(MockProvider.EXAMPLE_USER_EMAIL)).when().get(USER_PROFILE_URL);
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testUserCreateExistingFails()
        public virtual void testUserCreateExistingFails()
        {
            User newUser = MockProvider.createMockUser();

            when(identityServiceMock.newUser(MockProvider.EXAMPLE_USER_ID)).thenReturn(newUser);
            doThrow(new ProcessEngineException("")).when(identityServiceMock).saveUser(newUser);

            UserDto userDto = UserDto.fromUser(newUser, true);

            given().body(userDto).contentType(ContentType.JSON).then().statusCode(Status.INTERNAL_SERVER_ERROR.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(ProcessEngineException).Name)).when().post(USER_CREATE_URL);

            verify(identityServiceMock).newUser(MockProvider.EXAMPLE_USER_ID);
            verify(identityServiceMock).saveUser(newUser);
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testCreateNewUserWithCredentials()
        public virtual void testCreateNewUserWithCredentials()
        {
            User newUser = MockProvider.createMockUser();

            when(identityServiceMock.newUser(MockProvider.EXAMPLE_USER_ID)).thenReturn(newUser);

            UserDto userDto = UserDto.fromUser(newUser, true);

            given().body(userDto).contentType(ContentType.JSON).expect().statusCode(Status.NO_CONTENT.StatusCode).when().post(USER_CREATE_URL);

            verify(identityServiceMock).newUser(MockProvider.EXAMPLE_USER_ID);
            verify(newUser).FirstName = MockProvider.EXAMPLE_USER_FIRST_NAME;
            verify(newUser).LastName  = MockProvider.EXAMPLE_USER_LAST_NAME;
            verify(newUser).Email     = MockProvider.EXAMPLE_USER_EMAIL;
            verify(newUser).Password  = MockProvider.EXAMPLE_USER_PASSWORD;
            verify(identityServiceMock).saveUser(newUser);
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfileThrowsAuthorizationException()
        public virtual void testPutProfileThrowsAuthorizationException()
        {
            User initialUser = MockProvider.createMockUser();
            User userUpdate  = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            string message = "exception expected";

            doThrow(new AuthorizationException(message)).when(identityServiceMock).saveUser(any(typeof(User)));

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(AuthorizationException).Name)).body("message", equalTo(message)).when().put(USER_PROFILE_URL);
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutCredentialsThrowsAuthorizationException()
        public virtual void testPutCredentialsThrowsAuthorizationException()
        {
            User      initialUser     = MockProvider.createMockUser();
            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            string message = "exception expected";

            doThrow(new AuthorizationException(message)).when(identityServiceMock).saveUser(any(typeof(User)));

            UserCredentialsDto dto = new UserCredentialsDto();

            dto.Password = "******";

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(dto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(AuthorizationException).Name)).body("message", equalTo(message)).when().put(USER_CREDENTIALS_URL);
        }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testChangeCredentialsWithWrongAuthenticatedUserPassword()
        public virtual void testChangeCredentialsWithWrongAuthenticatedUserPassword()
        {
            User      initialUser     = MockProvider.createMockUser();
            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            Authentication authentication = MockProvider.createMockAuthentication();

            when(identityServiceMock.CurrentAuthentication).thenReturn(authentication);

            when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(false);

            UserCredentialsDto dto = new UserCredentialsDto();

            dto.Password = "******";
            dto.AuthenticatedUserPassword = MockProvider.EXAMPLE_USER_PASSWORD;

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.BAD_REQUEST.StatusCode).contentType(ContentType.JSON).body("type", equalTo("InvalidRequestException")).body("message", equalTo("The given authenticated user password is not valid.")).when().put(USER_CREDENTIALS_URL);
        }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfile()
        public virtual void testPutProfile()
        {
            User initialUser = MockProvider.createMockUser();
            User userUpdate  = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.NO_CONTENT.StatusCode).when().put(USER_PROFILE_URL);

            // password was updated
            verify(initialUser).Email     = updateDto.Email;
            verify(initialUser).FirstName = updateDto.FirstName;
            verify(initialUser).LastName  = updateDto.LastName;

            // and then saved
            verify(identityServiceMock).saveUser(initialUser);
        }