From dc7004f5fc1b2778243ebb61903ec04f5c82a690 Mon Sep 17 00:00:00 2001 From: Alexandre Henrique Afonso Campos Date: Thu, 18 Jul 2024 09:30:53 -0300 Subject: [PATCH] Remove unused method (#113) * Remove unused authentication method * Remove unused endpoint for authantication (FE handles it) * Remove test for deleted method * Remove app id from iac --- client/src/main/api/statistics.api.ts | 8 +-- .../src/main/model/AuthenticationResponse.ts | 4 -- iac/README.md | 1 - iac/data-ssm.tf | 4 -- iac/ecs.tf | 1 - .../ecs/statistics_server_app.json.tpl | 4 -- .../statistics/controller/WcaController.java | 12 ++-- .../controller/impl/WcaControllerImpl.java | 6 -- .../statistics/service/WCAService.java | 2 - .../service/impl/WCAServiceImpl.java | 13 +---- .../src/main/resources/application-cron.yaml | 1 - .../src/main/resources/application-local.yaml | 3 +- .../src/main/resources/application-prod.yaml | 1 - .../src/main/resources/application-test.yaml | 1 - .../controller/WcaControllerIT.java | 55 +++++-------------- 15 files changed, 21 insertions(+), 95 deletions(-) delete mode 100644 client/src/main/model/AuthenticationResponse.ts diff --git a/client/src/main/api/statistics.api.ts b/client/src/main/api/statistics.api.ts index 0c39fa38..d110c26a 100644 --- a/client/src/main/api/statistics.api.ts +++ b/client/src/main/api/statistics.api.ts @@ -1,10 +1,9 @@ import Axios from "axios"; -import { AuthenticationResponse } from "../model/AuthenticationResponse"; +import { API_URL } from "../config/EnvVarConfig"; import BestEverRank from "../model/BestEverRank"; import { Statistics } from "../model/Statistic"; import { StatisticsList } from "../model/StatisticsList"; import UserInfo from "../model/UserInfo"; -import { API_URL } from "../config/EnvVarConfig"; export class StatisticsApi { BASE_URL: string; @@ -15,11 +14,6 @@ export class StatisticsApi { this.queryDatabaseEndpoint = "/database/query"; } - getWcaAuthenticationUrl = (frontendHost: string, redirect: string) => - Axios.get(this.BASE_URL + "/wca/authentication", { - params: { frontendHost, redirect }, - }); - getUserInfo = () => Axios.get(this.BASE_URL + "/wca/user"); getStatisticsGroups = (term?: string) => diff --git a/client/src/main/model/AuthenticationResponse.ts b/client/src/main/model/AuthenticationResponse.ts deleted file mode 100644 index 570447ea..00000000 --- a/client/src/main/model/AuthenticationResponse.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface AuthenticationResponse { - frontendHost: string; - url: string; -} diff --git a/iac/README.md b/iac/README.md index 0d8f6631..12d3addc 100644 --- a/iac/README.md +++ b/iac/README.md @@ -41,7 +41,6 @@ export read_password="ANOTHER_STRONG_PASSWORD_HERE" ``` ```bash -aws ssm put-parameter --name "/config/$environment/statistics/app/id" --value $app_id --overwrite --region $region --type String aws ssm put-parameter --name "/config/$environment/statistics/dumped_db/write_user" --value $write_user --overwrite --region $region --type String aws ssm put-parameter --name "/config/$environment/statistics/dumped_db/write_password" --value $write_password --overwrite --region $region --type String aws ssm put-parameter --name "/config/$environment/statistics/dumped_db/read_user" --value $read_user --overwrite --region $region --type String diff --git a/iac/data-ssm.tf b/iac/data-ssm.tf index 8915194e..d7cda7cf 100644 --- a/iac/data-ssm.tf +++ b/iac/data-ssm.tf @@ -1,7 +1,3 @@ -data "aws_ssm_parameter" "statistics_app_id" { - name = "/config/${terraform.workspace}/statistics/app/id" -} - data "aws_ssm_parameter" "dumped_db_write_user" { name = "/config/${terraform.workspace}/statistics/dumped_db/write_user" } diff --git a/iac/ecs.tf b/iac/ecs.tf index a7755358..85b2ce91 100644 --- a/iac/ecs.tf +++ b/iac/ecs.tf @@ -24,7 +24,6 @@ resource "aws_ecs_task_definition" "statistics_server_task_definition" { fargate_memory = var.statistics_fargate_memory aws_region = var.aws_region spring_profile = terraform.workspace - app_id = data.aws_ssm_parameter.statistics_app_id.value db_port = var.default_mysql_port db_host = aws_db_instance.dumped_db.address db_name = var.dumped_db_name diff --git a/iac/templates/ecs/statistics_server_app.json.tpl b/iac/templates/ecs/statistics_server_app.json.tpl index c9786651..b163aacf 100644 --- a/iac/templates/ecs/statistics_server_app.json.tpl +++ b/iac/templates/ecs/statistics_server_app.json.tpl @@ -20,10 +20,6 @@ } ], "environment": [ - { - "name": "APP_ID", - "value": "${app_id}" - }, { "name": "DB_USERNAME", "value": "${db_username}" diff --git a/server/src/main/java/org/worldcubeassociation/statistics/controller/WcaController.java b/server/src/main/java/org/worldcubeassociation/statistics/controller/WcaController.java index 11bd5b60..fe7ba771 100644 --- a/server/src/main/java/org/worldcubeassociation/statistics/controller/WcaController.java +++ b/server/src/main/java/org/worldcubeassociation/statistics/controller/WcaController.java @@ -1,21 +1,17 @@ package org.worldcubeassociation.statistics.controller; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; import org.worldcubeassociation.statistics.dto.UserInfoDTO; -import org.worldcubeassociation.statistics.response.AuthenticationResponse; - -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; @Validated @RequestMapping("wca") @CrossOrigin(origins = "*", allowedHeaders = "*") // Enable this for testing public interface WcaController { - @GetMapping("authentication") - AuthenticationResponse getWcaAuthenticationUrl(@Valid @NotBlank(message = "Frontend can not be blank") @RequestParam String frontendHost, @Valid @NotBlank(message = "Redirect can not be blank") @RequestParam String redirect); - @GetMapping("user") UserInfoDTO getUserInfo(@RequestHeader(value = "Authorization", required = false) String token); } diff --git a/server/src/main/java/org/worldcubeassociation/statistics/controller/impl/WcaControllerImpl.java b/server/src/main/java/org/worldcubeassociation/statistics/controller/impl/WcaControllerImpl.java index a0ec7b32..8b56d615 100644 --- a/server/src/main/java/org/worldcubeassociation/statistics/controller/impl/WcaControllerImpl.java +++ b/server/src/main/java/org/worldcubeassociation/statistics/controller/impl/WcaControllerImpl.java @@ -6,7 +6,6 @@ import org.worldcubeassociation.statistics.controller.WcaController; import org.worldcubeassociation.statistics.dto.UserInfoDTO; import org.worldcubeassociation.statistics.exception.UnauthorizedException; -import org.worldcubeassociation.statistics.response.AuthenticationResponse; import org.worldcubeassociation.statistics.service.WCAService; @RestController @@ -15,11 +14,6 @@ public class WcaControllerImpl implements WcaController { @Autowired private WCAService wcaService; - @Override - public AuthenticationResponse getWcaAuthenticationUrl(String frontendHost, String redirect) { - return wcaService.getWcaAuthenticationUrl(frontendHost, redirect); - } - @Override public UserInfoDTO getUserInfo(String token) { if (StringUtils.isBlank(token)) { diff --git a/server/src/main/java/org/worldcubeassociation/statistics/service/WCAService.java b/server/src/main/java/org/worldcubeassociation/statistics/service/WCAService.java index 6eef782b..336c4554 100644 --- a/server/src/main/java/org/worldcubeassociation/statistics/service/WCAService.java +++ b/server/src/main/java/org/worldcubeassociation/statistics/service/WCAService.java @@ -1,10 +1,8 @@ package org.worldcubeassociation.statistics.service; import org.worldcubeassociation.statistics.dto.UserInfoDTO; -import org.worldcubeassociation.statistics.response.AuthenticationResponse; public interface WCAService { - AuthenticationResponse getWcaAuthenticationUrl(String frontendHost, String redirect); UserInfoDTO getUserInfo(String token); } diff --git a/server/src/main/java/org/worldcubeassociation/statistics/service/impl/WCAServiceImpl.java b/server/src/main/java/org/worldcubeassociation/statistics/service/impl/WCAServiceImpl.java index 6aa92ef1..50ffa396 100644 --- a/server/src/main/java/org/worldcubeassociation/statistics/service/impl/WCAServiceImpl.java +++ b/server/src/main/java/org/worldcubeassociation/statistics/service/impl/WCAServiceImpl.java @@ -5,30 +5,19 @@ import org.springframework.stereotype.Service; import org.worldcubeassociation.statistics.api.WCAApi; import org.worldcubeassociation.statistics.dto.UserInfoDTO; -import org.worldcubeassociation.statistics.response.AuthenticationResponse; import org.worldcubeassociation.statistics.service.WCAService; @Service public class WCAServiceImpl implements WCAService { + @Value("${api.wca.baseurl}") private String wcaBaseUrl; - @Value("${api.wca.appid}") - private String wcaAppId; - @Autowired private WCAApi wcaApi; - @Override - public AuthenticationResponse getWcaAuthenticationUrl(String frontendHost, String redirect) { - return AuthenticationResponse.builder().frontendHost(frontendHost).url(String - .format("%s/oauth/authorize?client_id=%s&redirect_uri=%s?redirect=%s&response_type=token&scope=public", wcaBaseUrl, - wcaAppId, frontendHost, redirect)).build(); - } - @Override public UserInfoDTO getUserInfo(String token) { return wcaApi.getUserInfo(token); } - } diff --git a/server/src/main/resources/application-cron.yaml b/server/src/main/resources/application-cron.yaml index 9efd6b6b..0a03cb34 100644 --- a/server/src/main/resources/application-cron.yaml +++ b/server/src/main/resources/application-cron.yaml @@ -8,4 +8,3 @@ spring: api: wca: baseurl: https://www.worldcubeassociation.org - appid: ${APP_ID:cron} diff --git a/server/src/main/resources/application-local.yaml b/server/src/main/resources/application-local.yaml index aa72c726..50596e01 100644 --- a/server/src/main/resources/application-local.yaml +++ b/server/src/main/resources/application-local.yaml @@ -7,5 +7,4 @@ spring: initialization-mode: always api: wca: - baseurl: https://staging.worldcubeassociation.org - appid: example-application-id + baseurl: https://www.worldcubeassociation.org diff --git a/server/src/main/resources/application-prod.yaml b/server/src/main/resources/application-prod.yaml index 06b3c8fa..ee24ab25 100644 --- a/server/src/main/resources/application-prod.yaml +++ b/server/src/main/resources/application-prod.yaml @@ -7,4 +7,3 @@ spring: api: wca: baseurl: https://www.worldcubeassociation.org - appid: ${APP_ID} diff --git a/server/src/main/resources/application-test.yaml b/server/src/main/resources/application-test.yaml index 87f429d9..5f283ad7 100644 --- a/server/src/main/resources/application-test.yaml +++ b/server/src/main/resources/application-test.yaml @@ -8,6 +8,5 @@ spring: api: wca: baseurl: http://localhost:3500 - appid: example-application-id server: port: 8081 \ No newline at end of file diff --git a/server/src/test/java/org/worldcubeassociation/statistics/integration/controller/WcaControllerIT.java b/server/src/test/java/org/worldcubeassociation/statistics/integration/controller/WcaControllerIT.java index 0af2ccd6..d00c1ec3 100644 --- a/server/src/test/java/org/worldcubeassociation/statistics/integration/controller/WcaControllerIT.java +++ b/server/src/test/java/org/worldcubeassociation/statistics/integration/controller/WcaControllerIT.java @@ -1,6 +1,9 @@ package org.worldcubeassociation.statistics.integration.controller; +import static io.restassured.RestAssured.given; + import io.restassured.response.Response; +import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -8,62 +11,32 @@ import org.springframework.http.HttpStatus; import org.worldcubeassociation.statistics.integration.AbstractTest; -import java.util.Map; -import java.util.stream.Stream; - -import static io.restassured.RestAssured.given; - @DisplayName("WCA") public class WcaControllerIT extends AbstractTest { - private static final String BASE_PATH = "/wca/"; - - @DisplayName("WCA authentication") - @MethodSource("authenticationArguments") - @ParameterizedTest(name = "index {0} status {1} params {2} reason {3}") - public void authentication(int index, HttpStatus status, Map params, String reason) { - Response response = given() - .spec(super.SPEC) - .when() - .queryParams(params) - .get(BASE_PATH + "authentication") - .then() - .statusCode(status.value()) - .extract() - .response(); - super.validateResponse(index, response); - } - - private static Stream authenticationArguments() { - return Stream.of( - Arguments.of(0, HttpStatus.OK, Map.of("frontendHost", "https://statistics.worldcubeassociation.org/"), "Happy path"), - Arguments.of(1, HttpStatus.OK, Map.of("frontendHost", "http://localhost:3000"), "Happy path for local test"), - Arguments.of(2, HttpStatus.BAD_REQUEST, Map.of("frontendHost", ""), "No frontend host") - ); - } + private static final String BASE_PATH = "/wca/"; @DisplayName("WCA user info") @MethodSource("userInfoArguments") @ParameterizedTest(name = "index {0} status {1} token {2} reason {3}") public void userInfo(int index, HttpStatus status, String token, String reason) { Response response = given() - .spec(super.SPEC) - .header("Authorization", token) - .when() - .get(BASE_PATH + "user") - .then() - .statusCode(status.value()) - .extract() - .response(); + .spec(super.SPEC) + .header("Authorization", token) + .when() + .get(BASE_PATH + "user") + .then() + .statusCode(status.value()) + .extract() + .response(); super.validateResponse(index, response); } private static Stream userInfoArguments() { return Stream.of( - Arguments.of(0, HttpStatus.OK, "Bearer token", "Happy path"), - Arguments.of(1, HttpStatus.UNAUTHORIZED, "", "Unauthorized") + Arguments.of(0, HttpStatus.OK, "Bearer token", "Happy path"), + Arguments.of(1, HttpStatus.UNAUTHORIZED, "", "Unauthorized") ); } - }