Public Access
feat(profile): leave out hidden public profile sections
This commit is contained in:
1 parent
5c0c0c6a78
commit
07d287cd43
9 files changed
+134
-28
No files matched your search
@@ -106,7 +106,7 @@ class JwtServiceTest extends AbstractUnitTest {
|
||||
|
||||
@Test
|
||||
void verifyProfileTicket_ReturnsTheUser() {
|
||||
assertEquals(Optional.of(new ProfileTicket(42L, Set.of())),
|
||||
assertEquals(Optional.of(new ProfileTicket(42L, Set.of(), null)),
|
||||
jwtService.verifyProfileTicket(signTicket("public-profile", "42", 60_000)));
|
||||
}
|
||||
|
||||
@@ -116,7 +116,16 @@ class JwtServiceTest extends AbstractUnitTest {
|
||||
.claim("profileStats", List.of("PILE", "TREND"))
|
||||
.expiration(new Date(System.currentTimeMillis() + 60_000)).signWith(signingKey, Jwts.SIG.EdDSA).compact();
|
||||
|
||||
assertEquals(Optional.of(new ProfileTicket(42L, Set.of("PILE", "TREND"))), jwtService.verifyProfileTicket(ticket));
|
||||
assertEquals(Optional.of(new ProfileTicket(42L, Set.of("PILE", "TREND"), null)), jwtService.verifyProfileTicket(ticket));
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyProfileTicket_ReadsTheShownSections() {
|
||||
String ticket = Jwts.builder().subject("public-profile").claim("typ", "public-profile").claim("profileUserId", "42")
|
||||
.claim("sections", List.of("PLAYING", "STATS"))
|
||||
.expiration(new Date(System.currentTimeMillis() + 60_000)).signWith(signingKey, Jwts.SIG.EdDSA).compact();
|
||||
|
||||
assertEquals(Optional.of(new ProfileTicket(42L, Set.of(), Set.of("PLAYING", "STATS"))), jwtService.verifyProfileTicket(ticket));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -59,6 +59,12 @@ class PublicProfileControllerTest extends AbstractIntegrationTest {
|
||||
.expiration(new Date(System.currentTimeMillis() + 60_000)).signWith(TEST_KEYS.getPrivate(), Jwts.SIG.EdDSA).compact();
|
||||
}
|
||||
|
||||
private static String ticket(long userId, List<String> profileStats, List<String> sections) {
|
||||
return Jwts.builder().subject("public-profile").claim("typ", "public-profile").claim("profileUserId", String.valueOf(userId))
|
||||
.claim("profileStats", profileStats).claim("sections", sections)
|
||||
.expiration(new Date(System.currentTimeMillis() + 60_000)).signWith(TEST_KEYS.getPrivate(), Jwts.SIG.EdDSA).compact();
|
||||
}
|
||||
|
||||
private UserGame game(long appid, int playtime, GameStatus status, Integer rating) {
|
||||
UserGame game = new UserGame(USER_ID, appid, playtime, Instant.now(), Instant.now());
|
||||
game.setStatus(status);
|
||||
@@ -94,6 +100,7 @@ class PublicProfileControllerTest extends AbstractIntegrationTest {
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.totalGames").value(3))
|
||||
.andExpect(jsonPath("$.totalPlaytimeMinutes").value(1260))
|
||||
.andExpect(jsonPath("$.finishedGames").value(2))
|
||||
.andExpect(jsonPath("$.byStatus.FINISHED").value(1))
|
||||
.andExpect(jsonPath("$.byStatus.COMPLETED").value(1))
|
||||
.andExpect(jsonPath("$.playing", hasSize(1)))
|
||||
@@ -142,6 +149,41 @@ class PublicProfileControllerTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("$.stats.trend").value(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publicLibrary_HiddenSections_SendNoData() throws Exception {
|
||||
mockMvc.perform(get("/api/public/profiles/library")
|
||||
.header("X-Profile-Ticket", ticket(USER_ID, List.of("TOP_GAMES"), List.of("PLAYING"))))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.playing", hasSize(1)))
|
||||
.andExpect(jsonPath("$.totalGames").value(nullValue()))
|
||||
.andExpect(jsonPath("$.totalPlaytimeMinutes").value(nullValue()))
|
||||
.andExpect(jsonPath("$.finishedGames").value(nullValue()))
|
||||
.andExpect(jsonPath("$.perfectGames").value(nullValue()))
|
||||
.andExpect(jsonPath("$.byStatus").value(nullValue()))
|
||||
.andExpect(jsonPath("$.finished").value(nullValue()))
|
||||
.andExpect(jsonPath("$.stats").value(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publicLibrary_SummaryWithoutStatus_KeepsTheFinishedCountButNoStatusCounts() throws Exception {
|
||||
mockMvc.perform(get("/api/public/profiles/library")
|
||||
.header("X-Profile-Ticket", ticket(USER_ID, List.of(), List.of("SUMMARY"))))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.totalGames").value(3))
|
||||
.andExpect(jsonPath("$.finishedGames").value(2))
|
||||
.andExpect(jsonPath("$.byStatus").value(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publicLibrary_OnlyStatusShown_HasTheCountsButNoTotals() throws Exception {
|
||||
mockMvc.perform(get("/api/public/profiles/library")
|
||||
.header("X-Profile-Ticket", ticket(USER_ID, List.of(), List.of("STATUS", "MONEY"))))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.byStatus.FINISHED").value(1))
|
||||
.andExpect(jsonPath("$.totalGames").value(nullValue()))
|
||||
.andExpect(jsonPath("$.playing").value(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publicLibrary_WithoutOrWithABadTicket_Is401() throws Exception {
|
||||
mockMvc.perform(get("/api/public/profiles/library")).andExpect(status().isUnauthorized());
|
||||
|
||||
Reference in new issue
Block a user