Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge bug fixes to master #54

Merged
merged 10 commits into from
Jan 8, 2024
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI-Build
on:
push:
branches:
- develop
pull_request:
branches:
- develop

env:
JAVA_VERSION: '17'

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ env.JAVA_VERSION }}

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Print finished building
run: echo "The app building finished successfully!"
65 changes: 0 additions & 65 deletions .github/workflows/deploy.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ build/

### VS Code ###
.vscode/

### GitHub Actions ###
.github
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

public class NicknameValidator implements ConstraintValidator<NicknameValidation, String> {

private static final Pattern NICKNAME_PATTERN = Pattern.compile("^[a-zA-Z0-9а-яА-ЯІіЇї]{4,20}$");
private static final Pattern NICKNAME_PATTERN = Pattern.compile(
"^[a-zA-Z0-9а-яА-ЯІіЇї!@#$%^&*_\\-+=~?]{4,20}$");

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
Expand All @@ -23,13 +24,15 @@ public boolean isValid(String value, ConstraintValidatorContext context) {
return false;
} else if (!NICKNAME_PATTERN.matcher(value).matches()) {
context
.buildConstraintViolationWithTemplate("The nickname is invalid")
.buildConstraintViolationWithTemplate(
"The nickname should be 4-20 characters long and include only letters, numbers or "
+ "symbols [! @ # $ % ^ & * _ - + = ~ ?]")
.addConstraintViolation();
return false;
} else if (PATTERN_SPACE.matcher(value).matches()) {
context
.buildConstraintViolationWithTemplate("The nickname should not include space")
.addConstraintViolation();
.buildConstraintViolationWithTemplate("The nickname should not include space")
.addConstraintViolation();
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class PasswordValidator implements ConstraintValidator<PasswordValidation
Pattern.compile(".*[!@#$%^&*_\\-+=~?].*");
private static final Pattern PASSWORD_UPPER_CASE_PATTERN = Pattern.compile(".*[A-Z].*");
private static final Pattern PASSWORD_DIGIT_PATTERN = Pattern.compile(".*\\d.*");
private static final Pattern PASSWORD_FORBIDEN_SYMBOLS_PATTERN =
Pattern.compile(".*[<>;/.:'(),\\[\\]\"].*");
private static final Pattern PASSWORD_FORBIDEN_CYRILLIC_LETTERS_PATTERN =
Pattern.compile(".*[а-яА-ЯІіЇї].*");

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
Expand All @@ -35,7 +39,17 @@ public boolean isValid(String value, ConstraintValidatorContext context) {
.buildConstraintViolationWithTemplate("The password must not be longer than 12 characters.")
.addConstraintViolation();
return false;
} else if (!PASSWORD_SPECIAL_SYMBOLS_PATTERN.matcher(value).matches()) {
} else if (PASSWORD_FORBIDEN_SYMBOLS_PATTERN.matcher(value).matches()) {
context
.buildConstraintViolationWithTemplate("Password should not include symbols [< > ; / . : ' [ ] ( ) , ]")
.addConstraintViolation();
return false;
} else if (PASSWORD_FORBIDEN_CYRILLIC_LETTERS_PATTERN.matcher(value).matches()) {
context
.buildConstraintViolationWithTemplate("Password should not include cyrillic letters")
.addConstraintViolation();
return false;
}else if (!PASSWORD_SPECIAL_SYMBOLS_PATTERN.matcher(value).matches()) {
context
.buildConstraintViolationWithTemplate("Password must include at least 1 special symbol: [! @ # $ % ^ & * _ - + = ~ ?]")
.addConstraintViolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ public void shouldPassValidator_whenUserInputNickname() {
var nicknameFirstExample = "user123";
var nicknameSecondExample = "Username123";
var nicknameThirdExample = "abcd1234";
var nicknameWithSymbol = "Nickname!";

// When
var isValidFirstExample = nicknameValidator.isValid(nicknameFirstExample, context);
var isValidSecondExample = nicknameValidator.isValid(nicknameSecondExample, context);
var isValidThirdExample = nicknameValidator.isValid(nicknameThirdExample, context);
var isValid4Example = nicknameValidator.isValid(nicknameWithSymbol, context);

// Then
assertTrue(isValidFirstExample);
assertTrue(isValidSecondExample);
assertTrue(isValidThirdExample);
assertTrue(isValid4Example);
}

@DisplayName(
Expand All @@ -73,7 +76,7 @@ public void shouldFailValidator_whenUserInputNicknameWithInvalidLength() {
public void shouldFailValidator_whenUserInputNicknameWithInvalidCharacters() {
// Given
var nicknameFirstExample = "user 123";
var nicknameSecondExample = "user@123";
var nicknameSecondExample = "user)123";

// When
var isValidFirstExample = nicknameValidator.isValid(nicknameFirstExample, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,24 @@ public void shouldFailValidator_whenUserInputPasswordWithSpace() {
@Test
public void shouldFailValidator_whenUserInputPasswordWithForbiddenSymbols() {
// Given
var password = "<Password!";
var password1 = "<Password!";
var password2 = "hjj;^33N";

// When
var isValid1 = passwordValidator.isValid(password1, context);
var isValid2 = passwordValidator.isValid(password2, context);

// Then
assertFalse(isValid1);
assertFalse(isValid2);
}

@DisplayName(
"PasswordValidator should fail validator when user input password with cyrillic letters")
@Test
public void shouldFailValidator_whenUserInputPasswordWithCyrillicLetters() {
// Given
var password = "Ася_77";

// When
var isValid = passwordValidator.isValid(password, context);
Expand Down
Loading