Search in sources :

Example 31 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class UserResourceTest method shouldGetCurrentUserWithManagementConfigWithUrl.

@Test
public void shouldGetCurrentUserWithManagementConfigWithUrl() {
    when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
    when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
    ConsoleSettingsEntity consoleConfigEntity = new ConsoleSettingsEntity();
    Management managementConfig = new Management();
    managementConfig.setUrl("URL");
    consoleConfigEntity.setManagement(managementConfig);
    when(configService.getConsoleSettings()).thenReturn(consoleConfigEntity);
    final Response response = target().request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
    Mockito.verify(userService).findByIdWithRoles(userId.capture());
    assertEquals(USER_NAME, userId.getValue());
    User user = response.readEntity(User.class);
    assertNotNull(user);
    UserConfig config = user.getConfig();
    assertNotNull(config);
    assertEquals("URL", config.getManagementUrl());
    assertNotNull(user.getLinks());
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) User(io.gravitee.rest.api.portal.rest.model.User) Management(io.gravitee.rest.api.model.settings.Management) UserConfig(io.gravitee.rest.api.portal.rest.model.UserConfig) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 32 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class UserResourceTest method shouldGetUserAvatarRedirectUrl.

@Test
public void shouldGetUserAvatarRedirectUrl() throws IOException {
    doReturn(new UserEntity()).when(userService).findById(any());
    doReturn(new UserEntity()).when(userService).findByIdWithRoles(any());
    doReturn(new UrlPictureEntity(target().getUri().toURL().toString())).when(userService).getPicture(any());
    final Response response = target().path("avatar").request().get();
    assertEquals(OK_200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) UrlPictureEntity(io.gravitee.rest.api.model.UrlPictureEntity) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 33 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class OAuth2AuthenticationResourceTest method shouldConnectUser.

@Test
public void shouldConnectUser() throws Exception {
    // -- MOCK
    // mock environment
    mockDefaultEnvironment();
    // mock oauth2 exchange authorisation code for access token
    mockExchangeAuthorizationCodeForAccessToken();
    // mock oauth2 user info call
    mockUserInfo(okJson(IOUtils.toString(read("/oauth2/json/user_info_response_body.json"), Charset.defaultCharset())));
    // mock DB find user by name
    UserEntity userEntity = mockUserEntity();
    userEntity.setId("janedoe@example.com");
    userEntity.setSource(USER_SOURCE_OAUTH2);
    userEntity.setSourceId("janedoe@example.com");
    userEntity.setPicture("http://example.com/janedoe/me.jpg");
    when(userService.createOrUpdateUserFromSocialIdentityProvider(eq(identityProvider), anyString())).thenReturn(userEntity);
    // mock DB user connect
    when(userService.connect(userEntity.getId())).thenReturn(userEntity);
    // -- CALL
    final MultivaluedMap<String, String> payload = createPayload("the_client_id", "http://localhost/callback", "CoDe");
    Response response = target().request().post(form(payload));
    // -- VERIFY
    verify(userService, times(1)).createOrUpdateUserFromSocialIdentityProvider(eq(identityProvider), anyString());
    verify(userService, times(1)).connect(userEntity.getSourceId());
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    // verify response body
    // verifyUserInResponseBody(response);
    // verify jwt token
    verifyJwtToken(response);
}
Also used : UserEntity(io.gravitee.rest.api.model.UserEntity) AbstractResourceTest(io.gravitee.rest.api.portal.rest.resource.AbstractResourceTest) Test(org.junit.Test)

Example 34 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class OAuth2AuthenticationResourceTest method mockUserEntity.

private UserEntity mockUserEntity() {
    UserEntity createdUser = new UserEntity();
    createdUser.setId("janedoe@example.com");
    createdUser.setSource(USER_SOURCE_OAUTH2);
    createdUser.setSourceId("janedoe@example.com");
    createdUser.setLastname("Doe");
    createdUser.setFirstname("Jane");
    createdUser.setEmail("janedoe@example.com");
    createdUser.setPicture("http://example.com/janedoe/me.jpg");
    return createdUser;
}
Also used : UserEntity(io.gravitee.rest.api.model.UserEntity)

Example 35 with UserEntity

use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.

the class UsersResourceTest method shouldCreateRegistration.

@Test
public void shouldCreateRegistration() {
    // init
    RegisterUserInput input = new RegisterUserInput().email("test@example.com").firstname("Firstname").lastname("LASTNAME").confirmationPageUrl("HTTP://MY-CONFIRM-PAGE");
    NewExternalUserEntity newExternalUserEntity = new NewExternalUserEntity();
    doReturn(newExternalUserEntity).when(userMapper).convert(input);
    doReturn(new UserEntity()).when(userService).register(newExternalUserEntity, "HTTP://MY-CONFIRM-PAGE");
    // test
    final Response response = target("registration").request().post(Entity.json(input));
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    Mockito.verify(userMapper).convert(input);
    Mockito.verify(userService).register(newExternalUserEntity, "HTTP://MY-CONFIRM-PAGE");
}
Also used : Response(javax.ws.rs.core.Response) NewExternalUserEntity(io.gravitee.rest.api.model.NewExternalUserEntity) RegisterUserEntity(io.gravitee.rest.api.model.RegisterUserEntity) NewExternalUserEntity(io.gravitee.rest.api.model.NewExternalUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Aggregations

UserEntity (io.gravitee.rest.api.model.UserEntity)57 Test (org.junit.Test)36 User (io.gravitee.rest.api.portal.rest.model.User)14 Response (javax.ws.rs.core.Response)14 RoleEntity (io.gravitee.rest.api.model.RoleEntity)13 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)12 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)12 Date (java.util.Date)10 PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)9 UserService (io.gravitee.rest.api.service.UserService)9 NewExternalUserEntity (io.gravitee.rest.api.model.NewExternalUserEntity)8 List (java.util.List)8 Instant (java.time.Instant)7 UserDetails (io.gravitee.rest.api.idp.api.authentication.UserDetails)6 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)6 MembershipService (io.gravitee.rest.api.service.MembershipService)6 HashMap (java.util.HashMap)6 Collectors (java.util.stream.Collectors)6 MembershipPayload (io.gravitee.cockpit.api.command.membership.MembershipPayload)5 MembershipReply (io.gravitee.cockpit.api.command.membership.MembershipReply)5