From 9927f5fd731ee146db83fefd6eee89c8290aa1dd Mon Sep 17 00:00:00 2001 From: Dmytro Trotsenko Date: Thu, 21 Dec 2023 16:14:51 +0200 Subject: [PATCH 1/8] feat: added CI-Build --- .github/workflows/build.yml | 30 +++++++++++++++++ .github/workflows/deploy.yml | 65 ------------------------------------ 2 files changed, 30 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/deploy.yml 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!" From 6d8468f5348a86b12e60a1c6a3339bc875cab857 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsenko Date: Sat, 6 Jan 2024 16:24:06 +0200 Subject: [PATCH 2/8] bugfix: added forbidden symbols and cyrillic letters to password validation --- .../annotation/validator/PasswordValidator.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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(); From ec4b6b6c4ca9a6cd73e936eb53e97bc2ea111f8e Mon Sep 17 00:00:00 2001 From: Dmytro Trotsenko Date: Sat, 6 Jan 2024 16:25:15 +0200 Subject: [PATCH 3/8] bugfix: added unit tests to password validation --- .../PasswordValidationValidatorTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 = " Date: Mon, 8 Jan 2024 10:53:38 +0200 Subject: [PATCH 4/8] bugfix: added unit tests to nickname validation --- .../validator/NicknameValidationValidatorTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); From 7ccac22b3e2e94493342ae5f07504447970eb59e Mon Sep 17 00:00:00 2001 From: Dmytro Trotsenko Date: Mon, 8 Jan 2024 10:59:21 +0200 Subject: [PATCH 5/8] bugfix: added allowed symbols to nickname validation --- .../annotation/validator/NicknameValidator.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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; } From 59d60218c491d220841162389d793e66d31cfc2a Mon Sep 17 00:00:00 2001 From: Dmytro Trotsenko <106109140+Troha7@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:06:52 +0200 Subject: [PATCH 6/8] added github actions to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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 From 761053c93d2c17e8e291e7ad74b881ffe5d37ef6 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsenko Date: Mon, 8 Jan 2024 17:37:30 +0200 Subject: [PATCH 7/8] feat: create .gitattributes --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..cc754045 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +build.yml merge=ours \ No newline at end of file From a5b191436f97db56e689470ef13cd91605122298 Mon Sep 17 00:00:00 2001 From: Dmytro Trotsenko Date: Mon, 8 Jan 2024 18:20:11 +0200 Subject: [PATCH 8/8] delete .gitattributes --- .gitattributes | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index cc754045..00000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -build.yml merge=ours \ No newline at end of file