Correction des tests pour prendre en compte :
- le hashage des mots de passe - la fonction getRolesForUser
This commit is contained in:
@@ -13,6 +13,7 @@ import org.yacos.core.conferences.Conference;
|
||||
import org.yacos.core.conferences.IConferenceManager;
|
||||
import org.yacos.core.exceptions.ConferenceDoesntExistException;
|
||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||
import org.yacos.core.exceptions.UserEMailAlreadyExistsException;
|
||||
import org.yacos.core.users.IUserManager;
|
||||
import org.yacos.core.users.User;
|
||||
import org.yacos.core.users.Role.RoleType;
|
||||
@@ -58,30 +59,35 @@ public class Filler {
|
||||
new Date(),new Date(),new Date(),new Date(),new Date());
|
||||
|
||||
//ajout de 2 users
|
||||
User author = um.addUser("max","pw","maxime","dagn","ipint", "max@e.fr");
|
||||
User author2 = um.addUser("toto","pw","toto","titu","ipint", "toto@e.fr");
|
||||
User membre1 = um.addUser("login_membre1","pw","Jean","Bon","ipint", "meme@e.fr");
|
||||
User membre2 = um.addUser("login_membre2","pw","Vincent","Tim","ipint", "meme@e.fr");
|
||||
User membre3 = um.addUser("login_membre3","pw","Camille","Hon","ipint", "meme@e.fr");
|
||||
User membre = um.addUser("login_membre","pw","nom_membre","meme","ipint", "meme@e.fr");
|
||||
User admin = um.addUser("admin","admin","maxime","dagn","ipint", "max@e.fr");
|
||||
|
||||
//ajout des roles pr les users
|
||||
cm.addRole(RoleType.AUTHOR, author.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, membre1.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, membre2.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, membre3.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.AUTHOR, admin.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.CHAIRMAN, admin.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, admin.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.REFEREE, admin.getLogin(), conf.getId());
|
||||
|
||||
|
||||
//ajout d'un article pr le user "max"
|
||||
Article article = am.addArticle("title article max","topic","url_article",
|
||||
author.getLogin(), new ArrayList<String>(), Article.State.SUMMARY, conf.getId());
|
||||
am.addArticle("title article toto","topic","url_article",
|
||||
author2.getLogin(), new ArrayList<String>(), Article.State.SUMMARY, conf.getId());
|
||||
User author;
|
||||
try {
|
||||
author = um.addUser("max",User.hashPassword("pw"),"maxime","dagn","ipint", "max@e.fr");
|
||||
User author2 = um.addUser("toto",User.hashPassword("pw"),"toto","titu","ipint", "toto@e.fr");
|
||||
User membre1 = um.addUser("login_membre1",User.hashPassword("pw"),"Jean","Bon","ipint", "meme1@e.fr");
|
||||
User membre2 = um.addUser("login_membre2",User.hashPassword("pw"),"Vincent","Tim","ipint", "meme2@e.fr");
|
||||
User membre3 = um.addUser("login_membre3",User.hashPassword("pw"),"Camille","Hon","ipint", "meme3@e.fr");
|
||||
User membre = um.addUser("login_membre",User.hashPassword("pw"),"nom_membre","meme","ipint", "meme4@e.fr");
|
||||
User admin = um.addUser("admin",User.hashPassword("admin"),"maxime","dagn","ipint", "admin@yacos.org");
|
||||
|
||||
//ajout des roles pr les users
|
||||
cm.addRole(RoleType.AUTHOR, author.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, membre1.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, membre2.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, membre3.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.AUTHOR, admin.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.CHAIRMAN, admin.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.PCMEMBER, admin.getLogin(), conf.getId());
|
||||
cm.addRole(RoleType.REFEREE, admin.getLogin(), conf.getId());
|
||||
|
||||
//ajout d'un article pr le user "max"
|
||||
Article article = am.addArticle("title article max","topic","url_article",
|
||||
author.getLogin(), new ArrayList<String>(), Article.State.SUMMARY, conf.getId());
|
||||
am.addArticle("title article toto","topic","url_article",
|
||||
author2.getLogin(), new ArrayList<String>(), Article.State.SUMMARY, conf.getId());
|
||||
} catch (UserEMailAlreadyExistsException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("--> FIN OK");
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.yacos.core.conferences.Conference;
|
||||
import org.yacos.core.conferences.IConferenceManager;
|
||||
import org.yacos.core.exceptions.ConferenceDoesntExistException;
|
||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||
import org.yacos.core.exceptions.UserEMailAlreadyExistsException;
|
||||
import org.yacos.core.users.IUserManager;
|
||||
import org.yacos.core.users.User;
|
||||
|
||||
@@ -39,12 +40,12 @@ public class ArticleManagerTest {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupArticleTest() throws PKAlreadyUsedException{
|
||||
public void setupArticleTest() throws PKAlreadyUsedException, UserEMailAlreadyExistsException{
|
||||
//ajout d'un user
|
||||
if (um.exists("max")){
|
||||
author = um.getUser("max");
|
||||
}else{
|
||||
author = um.addUser("max","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
author = um.addUser("max",User.hashPassword("pw"),"maxime","dagn","ipint", "e@e.fr");
|
||||
}
|
||||
//ajout d'une conf
|
||||
conf = cm.addConference("titi","desc conf","info en plus",new Date(),new Date(),new Date(),new Date(),new Date());
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.junit.Test;
|
||||
import org.yacos.core.conferences.Conference;
|
||||
import org.yacos.core.conferences.IConferenceManager;
|
||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||
import org.yacos.core.exceptions.UserEMailAlreadyExistsException;
|
||||
import org.yacos.core.users.IUserManager;
|
||||
import org.yacos.core.users.Role;
|
||||
import org.yacos.core.users.User;
|
||||
@@ -37,7 +38,7 @@ public class ConferenceManagerTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if(!um.exists("max")){
|
||||
um.addUser("max","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
um.addUser("max",User.hashPassword("pw"),"maxime","dagn","ipint", "e@e.fr");
|
||||
} else {
|
||||
um.getUser("max");
|
||||
}
|
||||
@@ -95,11 +96,11 @@ public class ConferenceManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConferencesForUserTest() throws PKAlreadyUsedException{
|
||||
public void getConferencesForUserTest() throws PKAlreadyUsedException, UserEMailAlreadyExistsException{
|
||||
User user = um.getUser("max");
|
||||
List<Conference> list = cm.getConferences(user);
|
||||
assertFalse(list.isEmpty());
|
||||
User user2 = um.addUser("max2","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
User user2 = um.addUser("max2",User.hashPassword("pw"),"maxime","dagn","ipint", "e@e.fr");
|
||||
list = cm.getConferences(user2);
|
||||
assertTrue(list.isEmpty());
|
||||
um.removeUser(user2.getLogin());
|
||||
|
||||
@@ -90,7 +90,8 @@ public class InvitationTokenTest {
|
||||
assertEquals(1,confManager.getInvitationTokensForConference(conf2.getId()).size());
|
||||
assertEquals(3,userManager.getInvitationTokensForEmail("InvitationToken@test.com").size());
|
||||
|
||||
User testUser = userManager.addUser("testInvitationToken", "pass", "ITokenTest", "ITokenTest", "YACOS", "InvitationToken@test.com");
|
||||
User testUser = userManager.addUser("testInvitationToken",
|
||||
User.hashPassword("pass"), "ITokenTest", "ITokenTest", "YACOS", "InvitationToken@test.com");
|
||||
assertTrue("Checking that all tokens are used when User is created",
|
||||
userManager.getInvitationTokensForEmail(testUser.getEmail()).isEmpty());
|
||||
assertTrue("Checking the roles for test user",
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.junit.Test;
|
||||
import org.yacos.core.conferences.Conference;
|
||||
import org.yacos.core.conferences.IConferenceManager;
|
||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||
import org.yacos.core.exceptions.UserEMailAlreadyExistsException;
|
||||
import org.yacos.core.users.IUserManager;
|
||||
import org.yacos.core.users.Role;
|
||||
import org.yacos.core.users.User;
|
||||
@@ -43,16 +44,16 @@ public class UserManagerTest {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup()throws PKAlreadyUsedException{
|
||||
public void setup()throws PKAlreadyUsedException, UserEMailAlreadyExistsException{
|
||||
if(!um.exists("truc")){
|
||||
um.addUser("truc","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
um.addUser("truc",User.hashPassword("pw"),"maxime","dagn","ipint", "e@e.fr");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addUserTest() throws PKAlreadyUsedException{
|
||||
User user = um.addUser("maxmax","pw","maxime","dagn","ipint", "e@e.fr");
|
||||
assertEquals("pw", user.getPassword());
|
||||
public void addUserTest() throws PKAlreadyUsedException, UserEMailAlreadyExistsException{
|
||||
User user = um.addUser("maxmax",User.hashPassword("pw"),"maxime","dagn","ipint", "e@e.fr");
|
||||
assertEquals(User.hashPassword("pw"), user.getPassword());
|
||||
um.removeUser("maxmax");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.yacos.tests.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
@@ -11,6 +13,7 @@ import org.junit.Test;
|
||||
import org.yacos.core.conferences.Conference;
|
||||
import org.yacos.core.conferences.IConferenceManager;
|
||||
import org.yacos.core.exceptions.PKAlreadyUsedException;
|
||||
import org.yacos.core.exceptions.UserEMailAlreadyExistsException;
|
||||
import org.yacos.core.users.IUserManager;
|
||||
import org.yacos.core.users.Role;
|
||||
import org.yacos.core.users.User;
|
||||
@@ -28,7 +31,7 @@ public class UserTest {
|
||||
manager = (IUserManager) context.lookup("UserManagerBean/remote");
|
||||
confManager = (IConferenceManager) context.lookup("ConferenceManagerBean/remote");
|
||||
|
||||
user = manager.addUser("testUser1","mp","bruno","dupont","ipint","e@e.fr");
|
||||
user = manager.addUser("testUser1",User.hashPassword("mp"),"bruno","dupont","ipint","e@e.fr");
|
||||
|
||||
|
||||
Date dateArticles = new Date();
|
||||
@@ -51,7 +54,7 @@ public class UserTest {
|
||||
@Test
|
||||
public void testUserWritingReading() throws Exception{
|
||||
user = manager.addUser("testUser",
|
||||
"aPassword",
|
||||
User.hashPassword("aPassword"),
|
||||
"Bob", "Smith",
|
||||
"MIT", "bob.smith@yacos.mit.org");
|
||||
assertNotNull(user);
|
||||
@@ -64,7 +67,7 @@ public class UserTest {
|
||||
assertEquals("Bob", user.getFirstName());
|
||||
assertEquals("MIT", user.getOrganization());
|
||||
assertEquals("bob.smith@yacos.mit.org", user.getEmail());
|
||||
assertEquals("aPassword", user.getPassword());
|
||||
assertEquals(User.hashPassword("aPassword"), user.getPassword());
|
||||
|
||||
try{
|
||||
manager.addUser("testUser", "", "", "", "", "");
|
||||
@@ -93,10 +96,11 @@ public class UserTest {
|
||||
|
||||
@Test
|
||||
public void testAddRole(){
|
||||
int count = user.getRoles().size();
|
||||
assertFalse(user.hasRoleForConference(RoleType.AUTHOR, conference));
|
||||
List<Role> roles = manager.getRolesForUser(user.getLogin());
|
||||
int count = roles.size();
|
||||
manager.addRoleForConference(user.getLogin(),RoleType.AUTHOR,conference.getId());
|
||||
assertTrue(count+1 == user.getRoles().size());
|
||||
roles = manager.getRolesForUser(user.getLogin());
|
||||
assertTrue(count+1 == roles.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,14 +115,24 @@ public class UserTest {
|
||||
assertTrue(manager.exists("testUser1"));
|
||||
}
|
||||
|
||||
@Test(expected=PKAlreadyUsedException.class)
|
||||
public void testUserExistsException() throws Exception {
|
||||
manager.addUser("testUser1","pw","First","Last","Orga","someEmailNotUsedYet@somewhere.com");
|
||||
}
|
||||
|
||||
@Test(expected=UserEMailAlreadyExistsException.class)
|
||||
public void testUserEmailExistsException() throws Exception {
|
||||
manager.addUser("anotherUserLoginForTestUser1",User.hashPassword("mp"),"bruno","dupont","ipint","e@e.fr");
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup(){
|
||||
user = manager.getUser("testUser1");
|
||||
if(user != null){
|
||||
for(Role role : user.getRoles()){
|
||||
for(Role role : manager.getRolesForUser(user.getLogin())){
|
||||
manager.removeRole(user.getLogin(), role.getType(), role.getConference().getId());
|
||||
}
|
||||
manager.removeUser("testUser1");
|
||||
manager.removeUser(user.getLogin());
|
||||
}
|
||||
|
||||
if(conference != null){
|
||||
|
||||
Reference in New Issue
Block a user