aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-03-20 15:18:29 +0300
committerGravatar Vitaly Takmazov2020-03-20 15:18:29 +0300
commitc3d889c92d8eacfd93bab2dbc2e9a4db61d9aae7 (patch)
tree1f9d64442f0ef7acf9f88840f9320b82bc605c7f /src/test/java/com
parentbdef56b6fc58dc3554171f3e14ac821655cb8ddd (diff)
enable spring boot actuator for admin users
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index ebfcda08..32db8544 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -161,7 +161,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource(properties = {
- "ios_app_id=12345678.com.juick.ExampleApp"
+ "ios_app_id=12345678.com.juick.ExampleApp",
+ "juick.admin_users=ugnich"
})
@AutoConfigureMockMvc
public class ServerTests {
@@ -2385,8 +2386,8 @@ public class ServerTests {
ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, ecSpec);
ECPublicKey publicKeyGenerated = (ECPublicKey) keyFactory.generatePublic(pubSpec);
- Jws<Claims> jwt = Jwts.parser()
- .setSigningKey(publicKeyGenerated)
+ Jws<Claims> jwt = Jwts.parserBuilder()
+ .setSigningKey(publicKeyGenerated).build()
.parseClaimsJws(secret);
Assert.assertThat(jwt.getHeader().get("kid"), is("keyid"));
Assert.assertThat(jwt.getHeader().get("alg"), is("ES256"));
@@ -2395,4 +2396,29 @@ public class ServerTests {
Assert.assertThat(claims.get("sub"), is("com.example.app"));
Assert.assertThat(claims.get("aud"), is("https://appleid.apple.com"));
}
+
+ @Test
+ public void adminsTest() throws Exception {
+ assertThat(userService.isAdminUser(ugnich), is(true));
+ assertThat(userService.isAdminUser(freefd), is(false));
+ MvcResult formLoginResult = mockMvc.perform(post("/login")
+ .param("username", ugnichName)
+ .param("password", ugnichPassword))
+ .andExpect(status().is3xxRedirection()).andReturn();
+ Cookie ugnichLogin = formLoginResult.getResponse().getCookie("juick-remember-me");
+
+ formLoginResult = mockMvc.perform(post("/login")
+ .param("username", freefdName)
+ .param("password", freefdPassword))
+ .andExpect(status().is3xxRedirection()).andReturn();
+ Cookie freefdLogin = formLoginResult.getResponse().getCookie("juick-remember-me");
+
+ mockMvc.perform(get("/actuator/health")
+ .cookie(ugnichLogin))
+ .andExpect(status().isOk());
+ mockMvc.perform(get("/actuator/health")
+ .cookie(freefdLogin))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
}