diff --git a/.github/workflows/gradle-on-pull-request.yml b/.github/workflows/gradle-on-pull-request.yml new file mode 100644 index 0000000..1ed85db --- /dev/null +++ b/.github/workflows/gradle-on-pull-request.yml @@ -0,0 +1,32 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Build and test + +on: + pull_request: + branches: [ "main" ] + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build with Gradle + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: build diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle-on-push-to-main.yml similarity index 97% rename from .github/workflows/gradle.yml rename to .github/workflows/gradle-on-push-to-main.yml index caffc18..57493f4 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle-on-push-to-main.yml @@ -5,7 +5,7 @@ # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle -name: CI Build +name: Build, test and update coverage badge on: push: diff --git a/src/main/kotlin/au/kilemon/messagequeue/rest/controller/AuthController.kt b/src/main/kotlin/au/kilemon/messagequeue/rest/controller/AuthController.kt index c05a3fc..d7761d4 100644 --- a/src/main/kotlin/au/kilemon/messagequeue/rest/controller/AuthController.kt +++ b/src/main/kotlin/au/kilemon/messagequeue/rest/controller/AuthController.kt @@ -139,24 +139,18 @@ open class AuthController : HasLogger { if (multiQueueAuthenticator.isRestricted(subQueue)) { - return if (multiQueueAuthenticator.removeRestriction(subQueue)) + if (clearQueue == true) { - if (clearQueue == true) - { - LOG.info("Restriction removed and clearing sub-queue [{}].", subQueue) - multiQueue.clearSubQueue(subQueue) - } - else - { - LOG.info("Removed restriction from sub-queue [{}] without clearing stored messages.", subQueue) - } - ResponseEntity.ok().build() + LOG.info("Removing restriction and clearing sub-queue [{}].", subQueue) + multiQueue.clearSubQueue(subQueue) } else { - LOG.error("Failed to remove restriction for sub-queue [{}].", subQueue) - ResponseEntity.internalServerError().build() + LOG.info("Removing restriction from sub-queue [{}] without clearing stored messages.", subQueue) } + + multiQueueAuthenticator.removeRestriction(subQueue) + return ResponseEntity.ok().build() } else { diff --git a/src/test/kotlin/au/kilemon/messagequeue/rest/controller/AuthControllerTest.kt b/src/test/kotlin/au/kilemon/messagequeue/rest/controller/AuthControllerTest.kt index 89350b5..b608dfb 100644 --- a/src/test/kotlin/au/kilemon/messagequeue/rest/controller/AuthControllerTest.kt +++ b/src/test/kotlin/au/kilemon/messagequeue/rest/controller/AuthControllerTest.kt @@ -285,33 +285,6 @@ class AuthControllerTest .andExpect(MockMvcResultMatchers.status().isNoContent) } - /** - * Ensure [AuthController.removeRestrictionFromSubQueue] returns - * [org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR] when there is an error when attempting to remove - * the restriction on the sub-queue. - */ - @Test - fun testRemoveRestrictionFromSubQueue_failedToRemoveRestriction() - { - Mockito.doReturn(RestrictionMode.HYBRID).`when`(multiQueueAuthenticator).getRestrictionMode() - Assertions.assertEquals(RestrictionMode.HYBRID, multiQueueAuthenticator.getRestrictionMode()) - - val subQueue = "testRemoveRestrictionFromSubQueue_failedToRemoveRestriction" - val token = jwtTokenProvider.createTokenForSubQueue(subQueue) - Assertions.assertTrue(token.isPresent) - - Assertions.assertTrue(multiQueueAuthenticator.addRestrictedEntry(subQueue)) - Assertions.assertTrue(multiQueueAuthenticator.isRestricted(subQueue)) - - Mockito.doReturn(false).`when`(multiQueueAuthenticator).removeRestriction(subQueue) - - mockMvc.perform( - MockMvcRequestBuilders.delete("${AuthController.AUTH_PATH}/${subQueue}") - .header(JwtAuthenticationFilter.AUTHORIZATION_HEADER, "${JwtAuthenticationFilter.BEARER_HEADER_VALUE}${token.get()}") - .contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(MockMvcResultMatchers.status().isInternalServerError) - } - /** * Ensure [AuthController.removeRestrictionFromSubQueue] returns [org.springframework.http.HttpStatus.OK] when * the sub-queue restriction is removed BUT the sub-queue is not cleared when the query parameter