feature/approve-reject-request #110
@ -1,11 +0,0 @@
|
|||||||
meta {
|
|
||||||
name: Get tunnels
|
|
||||||
type: http
|
|
||||||
seq: 4
|
|
||||||
}
|
|
||||||
|
|
||||||
get {
|
|
||||||
url: {{base_url}}/cloudflare/tunnels
|
|
||||||
body: none
|
|
||||||
auth: none
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
meta {
|
|
||||||
name: Tunnel
|
|
||||||
type: http
|
|
||||||
seq: 5
|
|
||||||
}
|
|
||||||
|
|
||||||
get {
|
|
||||||
url: {{base_url}}/cloudflare/tunnel/{{tunnel_id}}
|
|
||||||
body: none
|
|
||||||
auth: none
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
meta {
|
|
||||||
name: Write ingress
|
|
||||||
type: http
|
|
||||||
seq: 2
|
|
||||||
}
|
|
||||||
|
|
||||||
put {
|
|
||||||
url: {{base_url}}/cloudflare/tunnel/{{tunnel_id}}/add
|
|
||||||
body: json
|
|
||||||
auth: none
|
|
||||||
}
|
|
||||||
|
|
||||||
body:json {
|
|
||||||
{
|
|
||||||
"service": "http://192.168.0.100:3457",
|
|
||||||
"hostname": "random.hithomelabs.com",
|
|
||||||
"originRequest": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "1",
|
|
||||||
"name": "CFTunnels",
|
|
||||||
"type": "collection",
|
|
||||||
"ignore": [
|
|
||||||
"node_modules",
|
|
||||||
".git"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
meta {
|
|
||||||
name: delete mapping
|
|
||||||
type: http
|
|
||||||
seq: 3
|
|
||||||
}
|
|
||||||
|
|
||||||
put {
|
|
||||||
url: {{base_url}}/cloudflare/tunnel/{{tunnel_id}}/delete
|
|
||||||
body: json
|
|
||||||
auth: none
|
|
||||||
}
|
|
||||||
|
|
||||||
body:json {
|
|
||||||
{
|
|
||||||
"service": "http://192.168.0.100:6000",
|
|
||||||
"hostname": "random.hithomelabs.com",
|
|
||||||
"originRequest": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
vars {
|
|
||||||
tunnel_id: 50df9101-f625-4618-b7c5-100338a57124
|
|
||||||
base_url: http://localhost:8080
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
vars {
|
|
||||||
tunnel_id: 50df9101-f625-4618-b7c5-100338a57124
|
|
||||||
base_url: https://testcf.hithomelabs.com
|
|
||||||
}
|
|
||||||
@ -10,7 +10,6 @@ import com.hithomelabs.CFTunnels.Entity.User;
|
|||||||
import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader;
|
import com.hithomelabs.CFTunnels.Headers.AuthKeyEmailHeader;
|
||||||
import com.hithomelabs.CFTunnels.Models.Config;
|
import com.hithomelabs.CFTunnels.Models.Config;
|
||||||
import com.hithomelabs.CFTunnels.Models.Ingress;
|
import com.hithomelabs.CFTunnels.Models.Ingress;
|
||||||
import com.hithomelabs.CFTunnels.Models.PaginationRequest;
|
|
||||||
import com.hithomelabs.CFTunnels.Models.TunnelResponse;
|
import com.hithomelabs.CFTunnels.Models.TunnelResponse;
|
||||||
import com.hithomelabs.CFTunnels.Models.TunnelsResponse;
|
import com.hithomelabs.CFTunnels.Models.TunnelsResponse;
|
||||||
import com.hithomelabs.CFTunnels.Repositories.UserRepository;
|
import com.hithomelabs.CFTunnels.Repositories.UserRepository;
|
||||||
@ -22,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.http.*;
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
@ -112,21 +108,12 @@ public class TunnelController implements ErrorController {
|
|||||||
|
|
||||||
@PreAuthorize("hasAnyRole('USER')")
|
@PreAuthorize("hasAnyRole('USER')")
|
||||||
@GetMapping("/requests")
|
@GetMapping("/requests")
|
||||||
public ResponseEntity<Map<String,Object>> getAllRequests(
|
public ResponseEntity<Map<String,Object>> getAllRequests() {
|
||||||
@RequestParam(required = false) Request.RequestStatus status,
|
|
||||||
@ModelAttribute PaginationRequest paginationRequest) {
|
|
||||||
try {
|
try {
|
||||||
Sort sort = paginationRequest.getSort() != null && paginationRequest.getSort().length > 0
|
List<Request> requests = mappingRequestService.getAllRequests();
|
||||||
? Sort.by(paginationRequest.getSort())
|
|
||||||
: Sort.by("id");
|
|
||||||
Pageable pageable = PageRequest.of(paginationRequest.getPage(), paginationRequest.getSize(), sort);
|
|
||||||
Page<Request> requests = mappingRequestService.getAllRequests(status, pageable);
|
|
||||||
Map<String, Object> jsonResponse = new HashMap<>();
|
Map<String, Object> jsonResponse = new HashMap<>();
|
||||||
jsonResponse.put("status", "success");
|
jsonResponse.put("status", "success");
|
||||||
jsonResponse.put("data", requests.getContent());
|
jsonResponse.put("data", requests);
|
||||||
jsonResponse.put("currentPage", requests.getNumber());
|
|
||||||
jsonResponse.put("totalItems", requests.getTotalElements());
|
|
||||||
jsonResponse.put("totalPages", requests.getTotalPages());
|
|
||||||
return ResponseEntity.ok(jsonResponse);
|
return ResponseEntity.ok(jsonResponse);
|
||||||
} catch (DataAccessException e) {
|
} catch (DataAccessException e) {
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
package com.hithomelabs.CFTunnels.Models;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PaginationRequest {
|
|
||||||
private int page = 0;
|
|
||||||
private int size = 10;
|
|
||||||
private String[] sort = {"id"};
|
|
||||||
}
|
|
||||||
@ -11,8 +11,6 @@ import com.hithomelabs.CFTunnels.Repositories.RequestRepository;
|
|||||||
import com.hithomelabs.CFTunnels.Repositories.TunnelRepository;
|
import com.hithomelabs.CFTunnels.Repositories.TunnelRepository;
|
||||||
import com.hithomelabs.CFTunnels.Repositories.UserRepository;
|
import com.hithomelabs.CFTunnels.Repositories.UserRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
|
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -61,11 +59,8 @@ public class MappingRequestService {
|
|||||||
return createRequest(mapping, user);
|
return createRequest(mapping, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Request> getAllRequests(Request.RequestStatus status, Pageable pageable) {
|
public List<Request> getAllRequests() {
|
||||||
if (status != null) {
|
return requestRepository.findAll();
|
||||||
return requestRepository.findByStatus(status, pageable);
|
|
||||||
}
|
|
||||||
return requestRepository.findAll(pageable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User mapUser(OidcUser oidcUser){
|
public User mapUser(OidcUser oidcUser){
|
||||||
|
|||||||
@ -7,4 +7,6 @@ management.endpoint.health.show-details=always
|
|||||||
logging.level.org.hibernate.SQL=DEBUG
|
logging.level.org.hibernate.SQL=DEBUG
|
||||||
debug=true
|
debug=true
|
||||||
|
|
||||||
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
|
spring.jpa.show-sql=true
|
||||||
spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel
|
spring.datasource.url=jdbc:postgresql://localhost:5432/cftunnel
|
||||||
|
|||||||
@ -204,197 +204,22 @@ class TunnelControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("should return list of requests with pagination")
|
@DisplayName("should return list of requests")
|
||||||
void getAllRequests_Success() throws Exception {
|
void getAllRequests_Success() throws Exception {
|
||||||
List<com.hithomelabs.CFTunnels.Entity.Request> requests = Arrays.asList(
|
List<com.hithomelabs.CFTunnels.Entity.Request> requests = Arrays.asList(
|
||||||
createTestRequest(UUID.randomUUID(), com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.PENDING),
|
createTestRequest(UUID.randomUUID(), com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.PENDING),
|
||||||
createTestRequest(UUID.randomUUID(), com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.APPROVED)
|
createTestRequest(UUID.randomUUID(), com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.APPROVED)
|
||||||
);
|
);
|
||||||
Page<com.hithomelabs.CFTunnels.Entity.Request> page = new PageImpl<>(requests, PageRequest.of(0, 10), 2);
|
|
||||||
|
|
||||||
when(mappingRequestService.getAllRequests(any(), any(PageRequest.class))).thenReturn(page);
|
when(mappingRequestService.getAllRequests()).thenReturn(requests);
|
||||||
|
|
||||||
mockMvc.perform(get("/cloudflare/requests")
|
mockMvc.perform(get("/cloudflare/requests")
|
||||||
.with(oauth2Login().oauth2User(buildOidcUser("username", Groups.GITEA_USER)))
|
.with(oauth2Login().oauth2User(buildOidcUser("username", Groups.GITEA_USER))))
|
||||||
.param("page", "0")
|
|
||||||
.param("size", "10"))
|
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON))
|
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(jsonPath("$.status").value("success"))
|
.andExpect(jsonPath("$.status").value("success"))
|
||||||
.andExpect(jsonPath("$.data").isArray())
|
.andExpect(jsonPath("$.data").isArray())
|
||||||
.andExpect(jsonPath("$.totalItems").value(2))
|
.andExpect(jsonPath("$.data.length()").value(2));
|
||||||
.andExpect(jsonPath("$.totalPages").value(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should filter requests by status")
|
|
||||||
void getAllRequests_WithStatusFilter() throws Exception {
|
|
||||||
List<com.hithomelabs.CFTunnels.Entity.Request> requests = List.of(
|
|
||||||
createTestRequest(UUID.randomUUID(), com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.PENDING)
|
|
||||||
);
|
|
||||||
Page<com.hithomelabs.CFTunnels.Entity.Request> page = new PageImpl<>(requests, PageRequest.of(0, 10), 1);
|
|
||||||
|
|
||||||
when(mappingRequestService.getAllRequests(eq(com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.PENDING), any(PageRequest.class))).thenReturn(page);
|
|
||||||
|
|
||||||
mockMvc.perform(get("/cloudflare/requests")
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUser("username", Groups.GITEA_USER)))
|
|
||||||
.param("status", "PENDING"))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(jsonPath("$.status").value("success"))
|
|
||||||
.andExpect(jsonPath("$.data[0].status").value("PENDING"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should create mapping request successfully")
|
|
||||||
void createTunnelMappingRequest_Success() throws Exception {
|
|
||||||
UUID tunnelId = UUID.randomUUID();
|
|
||||||
com.hithomelabs.CFTunnels.Entity.Request createdRequest = new com.hithomelabs.CFTunnels.Entity.Request();
|
|
||||||
createdRequest.setId(UUID.randomUUID());
|
|
||||||
createdRequest.setStatus(com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.PENDING);
|
|
||||||
|
|
||||||
when(mappingRequestService.createMappingRequest(any(String.class), any(com.hithomelabs.CFTunnels.Models.Ingress.class), any())).thenReturn(createdRequest);
|
|
||||||
|
|
||||||
mockMvc.perform(post("/cloudflare/tunnels/configure/{tunnelId}/requests", tunnelId.toString())
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUser("developer", Groups.HOMELAB_DEVELOPER)))
|
|
||||||
.with(csrf())
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.content(ingressJson))
|
|
||||||
.andExpect(status().isCreated())
|
|
||||||
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON))
|
|
||||||
.andExpect(jsonPath("$.status").value("PENDING"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private com.hithomelabs.CFTunnels.Entity.Request createTestRequest(UUID id, com.hithomelabs.CFTunnels.Entity.Request.RequestStatus status) {
|
|
||||||
com.hithomelabs.CFTunnels.Entity.Request request = new com.hithomelabs.CFTunnels.Entity.Request();
|
|
||||||
request.setId(id);
|
|
||||||
request.setStatus(status);
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should approve mapping request successfully")
|
|
||||||
void approveMappingRequest_Success() throws Exception {
|
|
||||||
UUID requestId = UUID.randomUUID();
|
|
||||||
com.hithomelabs.CFTunnels.Entity.User approverUser = new com.hithomelabs.CFTunnels.Entity.User();
|
|
||||||
approverUser.setEmail("approver@example.com");
|
|
||||||
approverUser.setName("Approver");
|
|
||||||
|
|
||||||
com.hithomelabs.CFTunnels.Entity.Request approvedRequest = new com.hithomelabs.CFTunnels.Entity.Request();
|
|
||||||
approvedRequest.setId(requestId);
|
|
||||||
approvedRequest.setStatus(com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.APPROVED);
|
|
||||||
|
|
||||||
when(mappingRequestService.approveRequest(eq(requestId), any(com.hithomelabs.CFTunnels.Entity.User.class)))
|
|
||||||
.thenReturn(approvedRequest);
|
|
||||||
when(userRepository.findByEmail("approver@example.com"))
|
|
||||||
.thenReturn(java.util.Optional.of(approverUser));
|
|
||||||
|
|
||||||
mockMvc.perform(put("/cloudflare/requests/{requestId}/approve", requestId)
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUserWithEmail("approver", Groups.SYSTEM_ADMIN, "approver@example.com")))
|
|
||||||
.with(csrf()))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON))
|
|
||||||
.andExpect(jsonPath("$.status").value("APPROVED"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should return 404 when request not found")
|
|
||||||
void approveMappingRequest_NotFound() throws Exception {
|
|
||||||
UUID requestId = UUID.randomUUID();
|
|
||||||
com.hithomelabs.CFTunnels.Entity.User approverUser = new com.hithomelabs.CFTunnels.Entity.User();
|
|
||||||
approverUser.setEmail("approver@example.com");
|
|
||||||
approverUser.setName("Approver");
|
|
||||||
|
|
||||||
when(mappingRequestService.approveRequest(eq(requestId), any(com.hithomelabs.CFTunnels.Entity.User.class)))
|
|
||||||
.thenThrow(new NoSuchElementException("Request not found"));
|
|
||||||
when(userRepository.findByEmail("approver@example.com"))
|
|
||||||
.thenReturn(java.util.Optional.of(approverUser));
|
|
||||||
|
|
||||||
mockMvc.perform(put("/cloudflare/requests/{requestId}/approve", requestId)
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUserWithEmail("approver", Groups.SYSTEM_ADMIN, "approver@example.com")))
|
|
||||||
.with(csrf()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should return 500 when mapping creation fails")
|
|
||||||
void approveMappingRequest_InternalServerError() throws Exception {
|
|
||||||
UUID requestId = UUID.randomUUID();
|
|
||||||
com.hithomelabs.CFTunnels.Entity.User approverUser = new com.hithomelabs.CFTunnels.Entity.User();
|
|
||||||
approverUser.setEmail("approver@example.com");
|
|
||||||
approverUser.setName("Approver");
|
|
||||||
|
|
||||||
when(mappingRequestService.approveRequest(eq(requestId), any(com.hithomelabs.CFTunnels.Entity.User.class)))
|
|
||||||
.thenThrow(new RuntimeException("Failed to add mapping to Cloudflare"));
|
|
||||||
when(userRepository.findByEmail("approver@example.com"))
|
|
||||||
.thenReturn(java.util.Optional.of(approverUser));
|
|
||||||
|
|
||||||
mockMvc.perform(put("/cloudflare/requests/{requestId}/approve", requestId)
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUserWithEmail("approver", Groups.SYSTEM_ADMIN, "approver@example.com")))
|
|
||||||
.with(csrf()))
|
|
||||||
.andExpect(status().isInternalServerError());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should reject mapping request successfully")
|
|
||||||
void rejectMappingRequest_Success() throws Exception {
|
|
||||||
UUID requestId = UUID.randomUUID();
|
|
||||||
com.hithomelabs.CFTunnels.Entity.User rejecterUser = new com.hithomelabs.CFTunnels.Entity.User();
|
|
||||||
rejecterUser.setEmail("rejecter@example.com");
|
|
||||||
rejecterUser.setName("Rejecter");
|
|
||||||
|
|
||||||
com.hithomelabs.CFTunnels.Entity.Request rejectedRequest = new com.hithomelabs.CFTunnels.Entity.Request();
|
|
||||||
rejectedRequest.setId(requestId);
|
|
||||||
rejectedRequest.setStatus(com.hithomelabs.CFTunnels.Entity.Request.RequestStatus.REJECTED);
|
|
||||||
|
|
||||||
when(mappingRequestService.rejectRequest(eq(requestId), any(com.hithomelabs.CFTunnels.Entity.User.class)))
|
|
||||||
.thenReturn(rejectedRequest);
|
|
||||||
when(userRepository.findByEmail("rejecter@example.com"))
|
|
||||||
.thenReturn(java.util.Optional.of(rejecterUser));
|
|
||||||
|
|
||||||
mockMvc.perform(put("/cloudflare/requests/{requestId}/reject", requestId)
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUserWithEmail("rejecter", Groups.SYSTEM_ADMIN, "rejecter@example.com")))
|
|
||||||
.with(csrf()))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON))
|
|
||||||
.andExpect(jsonPath("$.status").value("REJECTED"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should return 404 when rejecting non-existent request")
|
|
||||||
void rejectMappingRequest_NotFound() throws Exception {
|
|
||||||
UUID requestId = UUID.randomUUID();
|
|
||||||
com.hithomelabs.CFTunnels.Entity.User rejecterUser = new com.hithomelabs.CFTunnels.Entity.User();
|
|
||||||
rejecterUser.setEmail("rejecter@example.com");
|
|
||||||
rejecterUser.setName("Rejecter");
|
|
||||||
|
|
||||||
when(mappingRequestService.rejectRequest(eq(requestId), any(com.hithomelabs.CFTunnels.Entity.User.class)))
|
|
||||||
.thenThrow(new NoSuchElementException("Request not found"));
|
|
||||||
when(userRepository.findByEmail("rejecter@example.com"))
|
|
||||||
.thenReturn(java.util.Optional.of(rejecterUser));
|
|
||||||
|
|
||||||
mockMvc.perform(put("/cloudflare/requests/{requestId}/reject", requestId)
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUserWithEmail("rejecter", Groups.SYSTEM_ADMIN, "rejecter@example.com")))
|
|
||||||
.with(csrf()))
|
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("should return 409 when rejecting already processed request")
|
|
||||||
void rejectMappingRequest_Conflict() throws Exception {
|
|
||||||
UUID requestId = UUID.randomUUID();
|
|
||||||
com.hithomelabs.CFTunnels.Entity.User rejecterUser = new com.hithomelabs.CFTunnels.Entity.User();
|
|
||||||
rejecterUser.setEmail("rejecter@example.com");
|
|
||||||
rejecterUser.setName("Rejecter");
|
|
||||||
|
|
||||||
when(mappingRequestService.rejectRequest(eq(requestId), any(com.hithomelabs.CFTunnels.Entity.User.class)))
|
|
||||||
.thenThrow(new IllegalStateException("Request is not in PENDING status"));
|
|
||||||
when(userRepository.findByEmail("rejecter@example.com"))
|
|
||||||
.thenReturn(java.util.Optional.of(rejecterUser));
|
|
||||||
|
|
||||||
mockMvc.perform(put("/cloudflare/requests/{requestId}/reject", requestId)
|
|
||||||
.with(oauth2Login().oauth2User(buildOidcUserWithEmail("rejecter", Groups.SYSTEM_ADMIN, "rejecter@example.com")))
|
|
||||||
.with(csrf()))
|
|
||||||
.andExpect(status().isConflict());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -437,6 +262,13 @@ class TunnelControllerTest {
|
|||||||
.andExpect(jsonPath("$.data.result.config.ingress[*].hostname", hasItem("random.hithomelabs.com")));
|
.andExpect(jsonPath("$.data.result.config.ingress[*].hostname", hasItem("random.hithomelabs.com")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private com.hithomelabs.CFTunnels.Entity.Request createTestRequest(UUID id, com.hithomelabs.CFTunnels.Entity.Request.RequestStatus status) {
|
||||||
|
com.hithomelabs.CFTunnels.Entity.Request request = new com.hithomelabs.CFTunnels.Entity.Request();
|
||||||
|
request.setId(id);
|
||||||
|
request.setStatus(status);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteTunnelConfiguration() throws Exception {
|
void deleteTunnelConfiguration() throws Exception {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user