adding a few tests
@@ -29,7 +29,10 @@ class SecretLeakageControllerTest {
private MockMvc mockMvc;
@Value("${password}")
private String hardcodedPassword;
-
+ @Value("${ARG_BASED_PASSWORD}")
+ private String argBasedPassword;
+ @Value("${DOCKER_ENV_PASSWORD}")
+ String hardcodedEnvPassword;
@BeforeEach
public void setup() {
@@ -38,17 +41,55 @@ class SecretLeakageControllerTest {
@Test
void spoil1() throws Exception {
- this.mockMvc.perform(MockMvcRequestBuilders.get("/spoil-1"))
- .andDo(print())
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andExpect(MockMvcResultMatchers.content().string(CoreMatchers.containsString(hardcodedPassword)));
+ testSpoil("/spoil-1", hardcodedPassword);
+ }
+
+ @Test
+ void spoil2() throws Exception {
+ testSpoil("/spoil-2", argBasedPassword);
+ }
+
+ @Test
+ void spoil3() throws Exception {
+ testSpoil("/spoil-3", hardcodedEnvPassword);
+ }
+
+ @Test
+ void spoil4() throws Exception {
+ testSpoil("/spoil-4", Constants.password);
}
@Test
void solveChallenge1() throws Exception {
+ solveChallenge("/challenge/1", hardcodedPassword);
+ }
+
+ @Test
+ void solveChallenge2() throws Exception {
+ solveChallenge("/challenge/2", argBasedPassword);
+ }
+
+ @Test
+ void solveChallenge3() throws Exception {
+ solveChallenge("/challenge/3", hardcodedEnvPassword);
+ }
+
+ @Test
+ void solveChallenge4() throws Exception {
+ solveChallenge("/challenge/4", Constants.password);
+ }
+
+
+ private void solveChallenge(String endpoint, String solution) throws Exception {
this.mockMvc.perform(MockMvcRequestBuilders.post("/challenge/1").param("solution", hardcodedPassword))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string(CoreMatchers.containsString("You&#39;re answer is correct!")));
}
+ private void testSpoil(String endpoint, String soluton) throws Exception {
+ this.mockMvc.perform(MockMvcRequestBuilders.get(endpoint))
+ .andDo(print())
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.content().string(CoreMatchers.containsString(soluton)));
+ }
}
