Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
KiKoS0 committed Sep 7, 2024
1 parent 6c473fb commit 11e6464
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inngest-spring-boot-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp:4.12.0")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.1.6")
}

dependencyManagement {
Expand All @@ -39,6 +40,7 @@ dependencyManagement {
tasks.withType<Test> {
useJUnitPlatform()
systemProperty("junit.jupiter.execution.parallel.enabled", true)
jvmArgs = listOf("-Dnet.bytebuddy.experimental=true")
testLogging {
events =
setOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.inngest.springbootdemo;

import com.inngest.*;
import com.inngest.springboot.InngestConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import java.util.HashMap;

public class InngestClientOnlyConfiguration extends InngestConfiguration {
@Override
protected HashMap<String, InngestFunction> functions() {
return new HashMap<>();
}

@Override
protected Inngest inngestClient() {
return new Inngest("spring_test_demo");
}

@Override
protected ServeConfig serve(Inngest client) {
return new ServeConfig(client);
}

@Bean
protected CommHandler commHandler(@Autowired Inngest inngestClient) {
ServeConfig serveConfig = new ServeConfig(inngestClient);
return new CommHandler(functions(), inngestClient, serveConfig, SupportedFrameworkName.SpringBoot);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.inngest.springbootdemo;

import com.inngest.InngestHeaderKey;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.web.servlet.MockMvc;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@ExtendWith(SystemStubsExtension.class)
public class SecureIntrospectTest {
@SystemStub
private static EnvironmentVariables environmentVariables;

@BeforeAll
static void beforeAll() {
environmentVariables.set("INNGEST_DEV", "0");
environmentVariables.set("INNGEST_SIGNING_KEY", "signkey-prod-2a89e554826a40672684e75eee6e34909b45aa4fd04fff5ff49bbe28c24ef424");
environmentVariables.set("INNGEST_EVENT_KEY", "test");
}

// The nested class is useful for setting the environment variables before the configuration class (Beans) runs.
// https://www.baeldung.com/java-system-stubs#environment-and-property-overrides-for-junit-5-spring-tests
@Import(InngestClientOnlyConfiguration.class)
@WebMvcTest(DemoController.class)
@Nested
class InnerSpringTest {
@Autowired
private MockMvc mockMvc;

@Test
public void shouldReturnFailedInsecureIntrospectionWhenSignatureIsMissing() 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("$.authentication_succeeded").value(false))
.andExpect(jsonPath("$.function_count").isNumber())
.andExpect(jsonPath("$.has_event_key").value(true))
.andExpect(jsonPath("$.has_signing_key").value(true))
.andExpect(jsonPath("$.mode").value("cloud"))
.andExpect(jsonPath("$.schema_version").value("2024-05-24"));
}
}
}

0 comments on commit 11e6464

Please sign in to comment.