//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); }
public virtual void updateCredentials(UserCredentialsDto account) { ensureNotReadOnly(); Authentication currentAuthentication = identityService.CurrentAuthentication; if (currentAuthentication != null && !string.ReferenceEquals(currentAuthentication.UserId, null)) { if (!identityService.checkPassword(currentAuthentication.UserId, account.AuthenticatedUserPassword)) { throw new InvalidRequestException(Status.BAD_REQUEST, "The given authenticated user password is not valid."); } } User dbUser = findUserObject(); if (dbUser == null) { throw new InvalidRequestException(Status.NOT_FOUND, "User with id " + resourceId + " does not exist"); } dbUser.Password = account.Password; identityService.saveUser(dbUser); }
public virtual void createInitialUser(string id, string password, string firstName, string lastName) { UserDto user = new UserDto(); UserCredentialsDto credentials = new UserCredentialsDto(); credentials.Password = password; user.Credentials = credentials; UserProfileDto profile = new UserProfileDto(); profile.Id = id; profile.FirstName = firstName; profile.LastName = lastName; user.Profile = profile; WebResource webResource = client.resource(testProperties.getApplicationPath("/camunda/api/admin/setup/default/user/create")); ClientResponse clientResponse = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(typeof(ClientResponse), user); try { if (clientResponse.ResponseStatus != Response.Status.NO_CONTENT) { throw new WebApplicationException(clientResponse.ResponseStatus); } } finally { clientResponse.close(); } }
//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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testPutCredentialsNonExistingUserFails() public virtual void testPutCredentialsNonExistingUserFails() { UserQuery sampleUserQuery = mock(typeof(UserQuery)); when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery); when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery); when(sampleUserQuery.singleResult()).thenReturn(null); UserCredentialsDto dto = new UserCredentialsDto(); dto.Password = "******"; given().pathParam("id", "aNonExistingUser").body(dto).contentType(ContentType.JSON).then().then().expect().statusCode(Status.NOT_FOUND.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", equalTo("User with id aNonExistingUser does not exist")).when().put(USER_CREDENTIALS_URL); // user was not updated verify(identityServiceMock, never()).saveUser(any(typeof(User))); }
//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); }
//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); }