Skip to content

Commit

Permalink
Adapt both adapters according to the new introspect signature
Browse files Browse the repository at this point in the history
  • Loading branch information
KiKoS0 committed Sep 7, 2024
1 parent f77b498 commit 6c473fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -27,22 +28,16 @@ private HttpHeaders getHeaders() {
@Value("${inngest.serveOrigin:}")
private String serveOrigin;

@GetMapping()
@GetMapping
public ResponseEntity<String> index(
@RequestHeader(HttpHeaders.HOST) String hostHeader,
HttpServletRequest request
HttpServletRequest request,
@RequestHeader(name = "X-Inngest-Signature", required = false) String signature,
@RequestHeader(name = "X-Inngest-Server-Kind", required = false) String serverKind
) {
if (commHandler.getClient().getEnv() != InngestEnv.Dev) {
// TODO: Return an UnauthenticatedIntrospection instead when app diagnostics are implemented
return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body("Introspect endpoint is only available in development mode");
}
String origin = String.format("%s://%s", request.getScheme(), hostHeader);
if (this.serveOrigin != null && !this.serveOrigin.isEmpty()) {
origin = this.serveOrigin;
}
String response = commHandler.introspect(origin);
return ResponseEntity.ok().headers(getHeaders()).body(response);
String requestBody = "";
String response = commHandler.introspect(signature, requestBody, serverKind);
return ResponseEntity.ok().headers(getHeaders()).contentType(MediaType.APPLICATION_JSON).body(response);
}

@PutMapping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@

@Import(DemoTestConfiguration.class)
@WebMvcTest(DemoController.class)
public class DemoControllerTest {
public class IntrospectTest {

@Autowired
private MockMvc mockMvc;

@Test
public void shouldReturnSyncPayload() throws Exception {
public void shouldReturnInsecureIntrospectPayload() throws Exception {
mockMvc.perform(get("/api/inngest").header("Host", "localhost:8080"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(header().string(InngestHeaderKey.Framework.getValue(), "springboot"))
.andExpect(jsonPath("$.appName").value("spring_test_demo"))
.andExpect(jsonPath("$.url").value("http://localhost:8080/api/inngest"))
.andExpect(jsonPath("$.sdk").value("inngest-kt"));
.andExpect(jsonPath("$.authentication_succeeded").isEmpty())
.andExpect(jsonPath("$.function_count").isNumber())
.andExpect(jsonPath("$.has_event_key").value(false))
.andExpect(jsonPath("$.has_signing_key").value(false))
.andExpect(jsonPath("$.mode").value("dev"))
.andExpect(jsonPath("$.schema_version").value("2024-05-24"));
}
}
14 changes: 6 additions & 8 deletions inngest/src/main/kotlin/com/inngest/ktor/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ fun Route.serve(

route(path) {
get("") {
if (client.env != InngestEnv.Dev) {
// TODO: Return an UnauthenticatedIntrospection instead when app diagnostics are implemented
call.respond(HttpStatusCode.Forbidden, "Introspect endpoint is only available in development mode")
return@get
}
val signature = call.request.headers[InngestHeaderKey.Signature.value]
val serverKind = call.request.headers[InngestHeaderKey.ServerKind.value]

val origin = getOrigin(call)
val resp = comm.introspect(origin)
call.respond(HttpStatusCode.OK, resp)
val requestBody = call.receiveText()

val resp = comm.introspect(signature, requestBody, serverKind)
call.respondText(resp, ContentType.Application.Json, HttpStatusCode.OK)
}

post("") {
Expand Down

0 comments on commit 6c473fb

Please sign in to comment.