-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HWORKS-869] Email validation regex doesn't support capital letters (…
…#1624)
- Loading branch information
Showing
10 changed files
with
157 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
hopsworks-common/src/test/io/hops/hopsworks/common/user/TestUserValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of Hopsworks | ||
* Copyright (C) 2023, Hopsworks AB. All rights reserved | ||
* | ||
* Hopsworks is free software: you can redistribute it and/or modify it under the terms of | ||
* the GNU Affero General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.hops.hopsworks.common.user; | ||
|
||
import io.hops.hopsworks.exceptions.UserException; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TestUserValidator { | ||
|
||
private UserValidator userValidator = new UserValidator(); | ||
|
||
@Test | ||
public void testIsValidEmail_emtpyEmail() { | ||
Assert.assertThrows(UserException.class, () -> userValidator.isValidEmail("")); | ||
} | ||
|
||
@Test | ||
public void testIsValidEmail_lowercaseEmail() throws UserException{ | ||
userValidator.isValidEmail("[email protected]"); | ||
} | ||
|
||
@Test | ||
public void testIsValidEmail_uppercaseEmail() throws UserException{ | ||
userValidator.isValidEmail("[email protected]"); | ||
} | ||
|
||
@Test | ||
public void testIsValidEmail_othercharsEmail() throws UserException{ | ||
userValidator.isValidEmail("[email protected]"); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
hopsworks-common/src/test/io/hops/hopsworks/common/user/TestUsersController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* This file is part of Hopsworks | ||
* Copyright (C) 2023, Hopsworks AB. All rights reserved | ||
* | ||
* Hopsworks is free software: you can redistribute it and/or modify it under the terms of | ||
* the GNU Affero General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.hops.hopsworks.common.user; | ||
|
||
import io.hops.hopsworks.common.dao.user.UserFacade; | ||
import io.hops.hopsworks.common.dao.user.UsersDTO; | ||
import io.hops.hopsworks.common.security.utils.SecurityUtils; | ||
import io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountStatus; | ||
import io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountType; | ||
import io.hops.hopsworks.persistence.entity.user.Users; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
public class TestUsersController { | ||
|
||
@InjectMocks | ||
private UsersController usersController = new UsersController(); | ||
|
||
@Mock | ||
private SecurityUtils securityUtils; | ||
|
||
@Mock | ||
private UserFacade userFacade; | ||
|
||
@Before | ||
public void setup() { | ||
MockitoAnnotations.openMocks(this); | ||
Mockito.when(securityUtils.generateSecret(Mockito.any())).thenCallRealMethod(); | ||
} | ||
|
||
@Test | ||
public void testCreateUserEmailLowercase() { | ||
String email = "[email protected]"; | ||
UsersDTO userDTO = new UsersDTO(); | ||
userDTO.setEmail(email); | ||
userDTO.setFirstName("first"); | ||
userDTO.setLastName("last"); | ||
userDTO.setTwoFactor(true); | ||
userDTO.setChosenPassword("lolololololo"); | ||
userDTO.setMaxNumProjects(1); | ||
Users user = | ||
usersController.createNewUser(userDTO, UserAccountStatus.VERIFIED_ACCOUNT, UserAccountType.M_ACCOUNT_TYPE); | ||
Assert.assertEquals(email.toLowerCase(), user.getEmail()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters