diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..90fd3870 --- /dev/null +++ b/.github/workflows/build.yml @@ -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!" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index b157bef6..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: CI-CD-Pipeline-to-AWS -on: - push: - branches: - - master - -env: - AWS_REGION: eu-central-1 - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - EB_APP_NAME: chat-app - EB_ENV_NAME: Chat-app-env - JAVA_VERSION: '17' - JAR_FILE: chatYourWay-0.0.1-SNAPSHOT.jar - VERSION_LABEL: chat_${{ github.sha }} - -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: Upload JAR - uses: actions/upload-artifact@v2 - with: - name: artifact - path: target/${{ env.JAR_FILE }} - - - name: Print finished building - run: echo "The app building finished successfully!" - - deploy: - needs: build - name: Deploy - runs-on: ubuntu-latest - steps: - - name: Download JAR - uses: actions/download-artifact@v2 - with: - name: artifact - - - name: Deploy to EB - uses: einaregilsson/beanstalk-deploy@v13 - with: - aws_access_key: ${{ env.AWS_ACCESS_KEY_ID }} - aws_secret_key: ${{ env.AWS_SECRET_ACCESS_KEY }} - use_existing_version_if_available: false - application_name: ${{ env.EB_APP_NAME }} - environment_name: ${{ env.EB_ENV_NAME }} - version_label: ${{ env.VERSION_LABEL }} - region: ${{ env.AWS_REGION }} - deployment_package: ${{ env.JAR_FILE }} - - - name: Print finished deployment - run: echo "Deployment completed successfully!" diff --git a/.gitignore b/.gitignore index 043dea7f..f166d962 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ build/ ### VS Code ### .vscode/ + +### GitHub Actions ### +.github diff --git a/src/main/java/com/chat/yourway/annotation/validator/NicknameValidator.java b/src/main/java/com/chat/yourway/annotation/validator/NicknameValidator.java index 9175c943..66409823 100644 --- a/src/main/java/com/chat/yourway/annotation/validator/NicknameValidator.java +++ b/src/main/java/com/chat/yourway/annotation/validator/NicknameValidator.java @@ -10,7 +10,8 @@ public class NicknameValidator implements ConstraintValidator { - 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) { @@ -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; } diff --git a/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java b/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java index 4ba1e9f2..3096d422 100644 --- a/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java +++ b/src/main/java/com/chat/yourway/annotation/validator/PasswordValidator.java @@ -15,6 +15,10 @@ public class PasswordValidator implements ConstraintValidator;/.:'(),\\[\\]\"].*"); + private static final Pattern PASSWORD_FORBIDEN_CYRILLIC_LETTERS_PATTERN = + Pattern.compile(".*[а-яА-ЯІіЇї].*"); @Override public boolean isValid(String value, ConstraintValidatorContext context) { @@ -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(); diff --git a/src/test/java/com/chat/yourway/unit/annotation/validator/NicknameValidationValidatorTest.java b/src/test/java/com/chat/yourway/unit/annotation/validator/NicknameValidationValidatorTest.java index 059bc3b5..b1dd70f2 100644 --- a/src/test/java/com/chat/yourway/unit/annotation/validator/NicknameValidationValidatorTest.java +++ b/src/test/java/com/chat/yourway/unit/annotation/validator/NicknameValidationValidatorTest.java @@ -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( @@ -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); diff --git a/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java b/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java index b392935e..b5800f2d 100644 --- a/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java +++ b/src/test/java/com/chat/yourway/unit/annotation/validator/PasswordValidationValidatorTest.java @@ -142,7 +142,24 @@ public void shouldFailValidator_whenUserInputPasswordWithSpace() { @Test public void shouldFailValidator_whenUserInputPasswordWithForbiddenSymbols() { // Given - var password = "