-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathMeControllerTest.java
More file actions
46 lines (40 loc) · 1.87 KB
/
MeControllerTest.java
File metadata and controls
46 lines (40 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.faforever.api.user;
import com.faforever.api.AbstractIntegrationTest;
import com.faforever.api.security.FafRole;
import org.junit.jupiter.api.Test;
import java.util.Set;
import static com.faforever.api.data.domain.GroupPermission.ROLE_READ_ACCOUNT_PRIVATE_DETAILS;
import static com.faforever.api.data.domain.GroupPermission.ROLE_USER;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class MeControllerTest extends AbstractIntegrationTest {
@Test
public void withoutTokenUnauthorized() throws Exception {
mockMvc.perform(get("/me"))
.andExpect(status().isUnauthorized());
}
@Test
public void withActiveUserGetResult() throws Exception {
mockMvc.perform(get("/me")
.with(getOAuthTokenWithActiveUser(Set.of(), Set.of(ROLE_READ_ACCOUNT_PRIVATE_DETAILS))))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.id", is("me")))
.andExpect(jsonPath("$.data.attributes.userId", is(USERID_ACTIVE_USER)))
.andExpect(jsonPath("$.data.attributes.userName", is(AUTH_ACTIVE_USER)))
.andExpect(jsonPath("$.data.attributes.email", is("active-user@faforever.com")))
.andExpect(jsonPath("$.data.attributes.permissions",
containsInAnyOrder(
ROLE_READ_ACCOUNT_PRIVATE_DETAILS, FafRole.ROLE_PREFIX + ROLE_READ_ACCOUNT_PRIVATE_DETAILS,
ROLE_USER, FafRole.ROLE_PREFIX + ROLE_USER
)));
}
@Test
public void withServiceTokenUnauthorized() throws Exception {
mockMvc.perform(get("/me")
.with(getOAuthTokenWithService(Set.of())))
.andExpect(status().isForbidden());
}
}