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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 ByteFight Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,15 @@ The webserver is organized into decoupled modules, each handling a specific aspe

## Configuration

HIGHLY RECOMMENDED: Use Intellij. The information in this README assumes you are using IntelliJ. it does not matter if you have IntelliJ ultimate.
Coming soon...

Must have Java 17 installed and set in project. To do so:
```
file > Project Structure > Project > SDK
```
Also set the Language level to SDK default. If you have OpenJDK 17 from Oracle, use that. Else, you can download Amazon Corretto 7.0.13 from Intellij Directly if you click Download JDK in SDK
## Maintainer

# Making Changes
The current primary maintainer of this repository is:
- Jaeheon Shim (jaeheon.shim@gatech.edu)

To make changes create a branch with a name corresponding to the feature you are developing. For example, the branch corresponding to updating the ranking system to use glicko rather than elo was named
```
glicko_branch
```
Of course, the fact that this is a branch is implied, and you probably don't need to specify that in the branch name.
Please address all concerns related to security or competition integrity directly to the ByteFight developers or to the maintainer. Do NOT create a public issue on this repository.

Once you are done making your changes, create a pull request merging into main. This should trigger GitHub actions that verify your code passes the necessary tests before allowing you to merge. Send your PR to infrastructure lead (currently Tyler) for review. Once your code passes the CI checks, and is approved by the lead, merge your code.
## License

Working on this repository should NOT require production database or storage access. Instead, verify that your changes work via unit/integration tests provided. When working on a specific component dependent on other components, it should be assumed that the other components work as intended. For this reason, when testing, use Mocks. More information about mock testing can be found int the [Mockito Docs](https://site.mockito.org/)
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. The MIT License is a permissive open source license that allows you to use, modify, and distribute this software with minimal restrictions.
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ repositories {
}

def springCloudGcpVersion = '5.0.0'
def springCloudVersion = '2023.0.0'
def jjwtVersion = '0.11.5'
def testcontainersVersion = '1.18.3'
def springCloudVersion = '2024.0.0'
def jjwtVersion = '0.12.6'
def testcontainersVersion = '1.20.3'

configurations {
compileOnly {
Expand All @@ -32,13 +32,13 @@ configurations {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'net.logstash.logback:logstash-logback-encoder:8.0'
implementation 'com.github.loki4j:loki-logback-appender:1.4.1'
implementation 'net.logstash.logback:logstash-logback-encoder:8.1'
implementation 'com.github.loki4j:loki-logback-appender:1.4.2'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-amqp'

implementation 'com.github.luben:zstd-jni:1.5.6-9'
implementation 'com.github.luben:zstd-jni:1.5.6-10'

implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
Expand All @@ -48,7 +48,7 @@ dependencies {
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-database-postgresql'

implementation platform('com.google.cloud:libraries-bom:26.29.0')
implementation platform('com.google.cloud:libraries-bom:26.40.0')
implementation 'com.google.cloud:google-cloud-storage'

implementation platform('org.hibernate.search:hibernate-search-bom:7.0.1.Final')
Expand All @@ -61,7 +61,7 @@ dependencies {

implementation 'me.paulschwarz:spring-dotenv:3.0.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.13'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.15'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand All @@ -72,7 +72,7 @@ dependencies {
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

testImplementation 'org.springframework.boot:spring-boot-testcontainers:3.3.5'
testImplementation 'org.springframework.boot:spring-boot-testcontainers:3.5.5'
testImplementation "org.testcontainers:junit-jupiter:${testcontainersVersion}"
testImplementation "org.testcontainers:postgresql:${testcontainersVersion}"
testImplementation "org.testcontainers:rabbitmq:${testcontainersVersion}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.bytefight.webserver.gamematch.application;

import jakarta.transaction.Transactional;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import jakarta.transaction.Transactional;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.*;

import org.bytefight.webserver.competition.domain.Competition;
Expand Down Expand Up @@ -309,6 +308,7 @@ public Optional<GameMatchDto> getDTOByUuid(String uuid) {

return Optional.of(GameMatchDto.fromEntity(dto.get()));
}

public long countTeamQueuedMatchesByLadder(Team team, Ladder ladder) {
return gameMatchRepository.countTeamMatchesByLadderAndStatus(
team, ladder.getLadder(), Set.of(MatchStatus.waiting, MatchStatus.in_progress));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public AdminGameMatchController(

@PostMapping("/schedule")
public ResponseEntity<Void> adminScheduleMatches(@RequestBody List<String> matchUuids) {
for(String uuid : matchUuids) {
for (String uuid : matchUuids) {
GameMatch gameMatch = gameMatchService.getGameMatch(UUID.fromString(uuid)).orElse(null);
if(gameMatch == null) continue;
if (gameMatch == null) continue;

gameMatchService.scheduleMatch(gameMatch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static TeamGlickoHistoryDto from(
List<Long> timestamps = new ArrayList<>(histories.size());
List<Double> glickos = new ArrayList<>(histories.size());

if(!histories.isEmpty()) {
if (!histories.isEmpty()) {
TeamGlickoHistory initial = histories.get(0);
timestamps.add(team.getCreatedAt().getEpochSecond());
glickos.add(initial.getOldGlicko());
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/org/bytefight/webserver/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public class SecurityConfig {
public SecurityFilterChain securityFilterChain(
HttpSecurity http,
JwtDecoder jwtDecoder,
Converter<Jwt, ? extends AbstractAuthenticationToken> jwtToUser)
Converter<Jwt, ? extends AbstractAuthenticationToken> jwtToUser,
CorsConfigurationSource corsConfigurationSource)
throws Exception {
http.cors(cors -> cors.configurationSource(corsConfigurationSource()))
http.cors(cors -> cors.configurationSource(corsConfigurationSource))
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(
session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
Expand Down Expand Up @@ -65,8 +66,9 @@ public SecurityFilterChain securityFilterChain(
return http.build();
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
@Bean(name = "corsConfigurationSource")
@Profile("!prod")
public CorsConfigurationSource corsConfigurationSourceDev() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*"));
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
Expand All @@ -78,6 +80,21 @@ public CorsConfigurationSource corsConfigurationSource() {
return source;
}

@Bean(name = "corsConfigurationSource")
@Profile("prod")
public CorsConfigurationSource corsConfigurationSourceProd() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(
List.of("https://staging.bytefight.org", "https://bytefight.org"));
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
configuration.setAllowedHeaders(List.of("*"));
configuration.setExposedHeaders(List.of("Authorization", "Content-Range"));

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}

@Bean
@Profile("!prod")
public JwtDecoder jwtDecoderDev(@Value("${app.auth.jwt-secret}") String secret) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.bytefight.webserver.shared.web;

import jakarta.validation.ConstraintViolationException;
import lombok.extern.slf4j.Slf4j;

import java.time.OffsetDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;

import org.bytefight.webserver.auth.domain.RegistrationException;
import org.bytefight.webserver.common.domain.PermissionDeniedException;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class AdminUserController {
private static final String DEFAULT_SORT_FIELD = "createdAt";
private static final Set<String> ALLOWED_SORT_FIELDS =
Set.of("createdAt", "email", "isAdmin", "uuid", "resumeUuid");
private static final Map<String, String> SORT_FIELD_MAPPING =
Map.of("resumeUuid", "r.uuid");
private static final Map<String, String> SORT_FIELD_MAPPING = Map.of("resumeUuid", "r.uuid");

private final AdminUserService adminUserService;

Expand All @@ -48,7 +47,8 @@ public AdminUserController(AdminUserService adminUserService) {

@GetMapping
@Operation(operationId = "adminListAllUsers", summary = "REST endpoint to list all users")
public Page<AdminUserWithPlayerAndResumeDto> listAll(@ModelAttribute RestPageRequest pageRequest) {
public Page<AdminUserWithPlayerAndResumeDto> listAll(
@ModelAttribute RestPageRequest pageRequest) {
Pageable pageable =
pageRequest.toPageable(
DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, DEFAULT_SORT_FIELD, ALLOWED_SORT_FIELDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public ResponseEntity<Void> uploadResume(
}

@DeleteMapping(value = "/resume")
@Operation(
operationId = "deleteResume",
summary = "Delete the authenticated user's resume")
@Operation(operationId = "deleteResume", summary = "Delete the authenticated user's resume")
public ResponseEntity<Void> deleteResume(@AuthenticationPrincipal User user) {
userService.deleteResume(user.getUuid());
return ResponseEntity.noContent().build();
Expand All @@ -62,7 +60,7 @@ public ResponseEntity<Void> deleteResume(@AuthenticationPrincipal User user) {
public ResponseEntity<ResumeDto> getResume(@AuthenticationPrincipal User user) {
try {
return ResponseEntity.ok(userService.getResume(user.getUuid()));
} catch(NoSuchElementException e) {
} catch (NoSuchElementException e) {
return ResponseEntity.notFound().build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ void handleGameMatchResultIsIdempotent() {

UUID matchUuid = (UUID) ReflectionTestUtils.getField(match, "uuid");
String uuid = matchUuid.toString();
gameMatchResultHandler.handleGameMatchResult(
createResult(uuid, MatchStatus.team_a_win));
gameMatchResultHandler.handleGameMatchResult(createResult(uuid, MatchStatus.team_a_win));

GameMatch afterFirst = gameMatchRepository.findByUuid(matchUuid).orElseThrow();
MatchStatus firstStatus = (MatchStatus) ReflectionTestUtils.getField(afterFirst, "status");
Expand All @@ -88,7 +87,8 @@ void handleGameMatchResultIsIdempotent() {

private GameMatchResult createResult(String uuid, MatchStatus status) {
try {
var constructor = GameMatchResult.class.getDeclaredConstructor(String.class, MatchStatus.class);
var constructor =
GameMatchResult.class.getDeclaredConstructor(String.class, MatchStatus.class);
constructor.setAccessible(true);
return constructor.newInstance(uuid, status);
} catch (ReflectiveOperationException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class SubmissionValidationIT extends FullStackIntegrationTestBase {

@Autowired private GameMatchService gameMatchService;

@Autowired private org.bytefight.webserver.gamematch.infra.GameMatchRepository gameMatchRepository;
@Autowired
private org.bytefight.webserver.gamematch.infra.GameMatchRepository gameMatchRepository;

@Autowired private SubmissionRepository submissionRepository;

Expand Down
Loading