-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start to build out a new integration test framework (#1266)
* feat: start to build out a new integration test framework * feat: start to build out a new integration test framework * allow disabling rate limits + add tests for pages * moar (also fixes #1268) * disable tests for now
- Loading branch information
1 parent
36e43d5
commit fb570d5
Showing
23 changed files
with
651 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
backend/src/test/java/io/papermc/hangar/controller/api/v1/ApiKeysControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.papermc.hangar.controller.api.v1; | ||
|
||
import io.papermc.hangar.controller.api.v1.helper.ControllerTest; | ||
import io.papermc.hangar.controller.api.v1.helper.TestData; | ||
import io.papermc.hangar.model.common.NamedPermission; | ||
import io.papermc.hangar.model.internal.api.requests.CreateAPIKeyForm; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
class ApiKeysControllerTest extends ControllerTest { | ||
|
||
@Test | ||
void testCreateGetDeleteKey() throws Exception { | ||
// create | ||
final String newKey = this.mockMvc.perform(post("/api/v1/keys") | ||
.with(this.apiKey(TestData.KEY_ADMIN)) | ||
.header("Content-Type", "application/json") | ||
.content(this.objectMapper.writeValueAsBytes(new CreateAPIKeyForm("cool_key", Set.of(NamedPermission.CREATE_PROJECT, NamedPermission.CREATE_ORGANIZATION))))) | ||
.andExpect(status().is(201)) | ||
.andReturn().getResponse().getContentAsString(); | ||
final String identifier = newKey.split("\\.")[0]; | ||
|
||
// get to make sure create worked | ||
this.mockMvc.perform(get("/api/v1/keys").with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(jsonPath("$[*].name").value(hasItem("cool_key"))) | ||
.andExpect(jsonPath("$[*].tokenIdentifier").value(hasItem(identifier))); | ||
|
||
// delete | ||
this.mockMvc.perform(delete("/api/v1/keys?name=cool_key").with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(204)); | ||
|
||
// get again to make sure delete worked | ||
this.mockMvc.perform(get("/api/v1/keys").with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(jsonPath("$[*].name").value(not(hasItem("cool_key")))) | ||
.andExpect(jsonPath("$[*].tokenIdentifier").value(not(hasItem(identifier)))); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
backend/src/test/java/io/papermc/hangar/controller/api/v1/PagesControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package io.papermc.hangar.controller.api.v1; | ||
|
||
import io.papermc.hangar.controller.api.v1.helper.ControllerTest; | ||
import io.papermc.hangar.controller.api.v1.helper.TestData; | ||
import io.papermc.hangar.model.api.project.PageEditForm; | ||
import io.papermc.hangar.model.common.NamedPermission; | ||
import io.papermc.hangar.model.internal.api.requests.CreateAPIKeyForm; | ||
import io.papermc.hangar.model.internal.api.requests.StringContent; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.MediaType; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
class PagesControllerTest extends ControllerTest { | ||
|
||
@Test | ||
void testGetMainPage() throws Exception { | ||
this.mockMvc.perform(get("/api/v1/pages/main/" + TestData.PROJECT.getSlug()) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(content().string(startsWith("# Test"))); | ||
} | ||
|
||
@Test | ||
void testEditMainPage() throws Exception { | ||
// edit | ||
this.mockMvc.perform(patch("/api/v1/pages/editmain/" + TestData.PROJECT.getSlug()) | ||
.content(this.objectMapper.writeValueAsBytes(new StringContent("# Test\nEdited"))) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)); | ||
|
||
// validate | ||
this.mockMvc.perform(get("/api/v1/pages/main/" + TestData.PROJECT.getSlug()) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(content().string(containsString("Edited"))); | ||
} | ||
|
||
@Test | ||
void testGetOtherPage() throws Exception { | ||
this.mockMvc.perform(get("/api/v1/pages/page/" + TestData.PROJECT.getSlug() + "?path=" + TestData.PAGE_PARENT.getSlug()) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(content().string(startsWith("# TestParentPage"))); | ||
} | ||
|
||
@Test | ||
void testSlashes() throws Exception { | ||
this.mockMvc.perform(get("/api/v1/pages/page/" + TestData.PROJECT.getSlug() + "?path=/" + TestData.PAGE_PARENT.getSlug() + "/") | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(content().string(startsWith("# TestParentPage"))); | ||
} | ||
|
||
@Test | ||
void testEditOtherPage() throws Exception { | ||
// edit | ||
this.mockMvc.perform(patch("/api/v1/pages/edit/" + TestData.PROJECT.getSlug()) | ||
.content(this.objectMapper.writeValueAsBytes(new PageEditForm(TestData.PAGE_PARENT.getSlug(), "# TestParentPage\nEdited"))) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)); | ||
|
||
// validate | ||
this.mockMvc.perform(get("/api/v1/pages/page/" + TestData.PROJECT.getSlug() + "?path=" + TestData.PAGE_PARENT.getSlug()) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(content().string(containsString("Edited"))); | ||
} | ||
|
||
@Test | ||
void testGetChildPage() throws Exception { | ||
this.mockMvc.perform(get("/api/v1/pages/page/" + TestData.PROJECT.getSlug() + "?path=" + TestData.PAGE_CHILD.getSlug()) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(content().string(startsWith("# TestChildPage"))); | ||
} | ||
|
||
@Test | ||
void testEditChildPage() throws Exception { | ||
// edit | ||
this.mockMvc.perform(patch("/api/v1/pages/edit/" + TestData.PROJECT.getSlug()) | ||
.content(this.objectMapper.writeValueAsBytes(new PageEditForm(TestData.PAGE_CHILD.getSlug(), "# TestChildPage\nEdited"))) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)); | ||
|
||
// validate | ||
this.mockMvc.perform(get("/api/v1/pages/page/" + TestData.PROJECT.getSlug() + "?path=" + TestData.PAGE_CHILD.getSlug()) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)) | ||
.andExpect(content().string(containsString("Edited"))); | ||
} | ||
|
||
@Test | ||
void testGetInvalidProject() throws Exception { | ||
this.mockMvc.perform(get("/api/v1/pages/main/Dum") | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(404)); | ||
} | ||
|
||
@Test | ||
void testGetInvalidPage() throws Exception { | ||
this.mockMvc.perform(get("/api/v1/pages/page/" + TestData.PROJECT.getSlug() + "?path=Dum") | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(404)); | ||
} | ||
|
||
@Test | ||
void testEditInvalidProject() throws Exception { | ||
this.mockMvc.perform(patch("/api/v1/pages/editmain/Dum") | ||
.content(this.objectMapper.writeValueAsBytes(new StringContent("# Dum"))) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(404)); | ||
} | ||
|
||
@Test | ||
void testEditInvalidPage() throws Exception { | ||
this.mockMvc.perform(patch("/api/v1/pages/edit/" + TestData.PROJECT.getSlug()) | ||
.content(this.objectMapper.writeValueAsBytes(new PageEditForm(TestData.PAGE_PARENT.getSlug(), "# TestParentPage\nEdited"))) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.with(this.apiKey(TestData.KEY_ADMIN))) | ||
.andExpect(status().is(200)); | ||
} | ||
} |
Oops, something went wrong.