Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions client/src/main/api/statistics.api.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,11 +14,6 @@ export class StatisticsApi {
this.queryDatabaseEndpoint = "/database/query";
}

getWcaAuthenticationUrl = (frontendHost: string, redirect: string) =>
Axios.get<AuthenticationResponse>(this.BASE_URL + "/wca/authentication", {
params: { frontendHost, redirect },
});

getUserInfo = () => Axios.get<UserInfo>(this.BASE_URL + "/wca/user");

getStatisticsGroups = (term?: string) =>
Expand Down
4 changes: 0 additions & 4 deletions client/src/main/model/AuthenticationResponse.ts

This file was deleted.

1 change: 0 additions & 1 deletion iac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions iac/data-ssm.tf
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
1 change: 0 additions & 1 deletion iac/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions iac/templates/ecs/statistics_server_app.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
}
],
"environment": [
{
"name": "APP_ID",
"value": "${app_id}"
},
{
"name": "DB_USERNAME",
"value": "${db_username}"
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
1 change: 0 additions & 1 deletion server/src/main/resources/application-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ spring:
api:
wca:
baseurl: https://www.worldcubeassociation.org
appid: ${APP_ID:cron}
3 changes: 1 addition & 2 deletions server/src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ spring:
initialization-mode: always
api:
wca:
baseurl: https://staging.worldcubeassociation.org
appid: example-application-id
baseurl: https://www.worldcubeassociation.org
1 change: 0 additions & 1 deletion server/src/main/resources/application-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ spring:
api:
wca:
baseurl: https://www.worldcubeassociation.org
appid: ${APP_ID}
1 change: 0 additions & 1 deletion server/src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ spring:
api:
wca:
baseurl: http://localhost:3500
appid: example-application-id
server:
port: 8081
Original file line number Diff line number Diff line change
@@ -1,69 +1,42 @@
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;
import org.junit.jupiter.params.provider.MethodSource;
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<String, Object> 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<Arguments> 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<Arguments> 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")
);
}

}