-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/remove-unused-controller' of github.com:campos2…
…0/statistics into feature/db-transaction
- Loading branch information
Showing
15 changed files
with
21 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
server/src/main/java/org/worldcubeassociation/statistics/controller/WcaController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
server/src/main/java/org/worldcubeassociation/statistics/service/WCAService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,3 @@ spring: | |
api: | ||
wca: | ||
baseurl: https://www.worldcubeassociation.org | ||
appid: ${APP_ID:cron} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,3 @@ spring: | |
api: | ||
wca: | ||
baseurl: https://www.worldcubeassociation.org | ||
appid: ${APP_ID} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,5 @@ spring: | |
api: | ||
wca: | ||
baseurl: http://localhost:3500 | ||
appid: example-application-id | ||
server: | ||
port: 8081 |
55 changes: 14 additions & 41 deletions
55
...test/java/org/worldcubeassociation/statistics/integration/controller/WcaControllerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
); | ||
} | ||
|
||
} |