Search in sources :

Example 1 with BeaconRestApiConfig

use of tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig in project teku by ConsenSys.

the class RestApiHostAllowlistIntegrationTest method shouldReturnForbiddenIfHostNotAuthorized.

@Test
public void shouldReturnForbiddenIfHostNotAuthorized() throws Exception {
    final Eth1Address depositContractAddress = new Eth1Address(Bytes.fromHexString("0xdddddddddddddddddddddddddddddddddddddddd"));
    final BeaconRestApiConfig config = BeaconRestApiConfig.builder().restApiPort(0).restApiEnabled(true).restApiDocsEnabled(false).eth1DepositContractAddress(depositContractAddress).restApiHostAllowlist(List.of("not.authorized.host")).restApiCorsAllowedOrigins(new ArrayList<>()).build();
    startPreGenesisRestAPIWithConfig(config);
    final Response response = getLatest();
    assertForbidden(response);
}
Also used : Response(okhttp3.Response) ArrayList(java.util.ArrayList) BeaconRestApiConfig(tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig) Eth1Address(tech.pegasys.teku.spec.datastructures.eth1.Eth1Address) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with BeaconRestApiConfig

use of tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig in project teku by ConsenSys.

the class BeaconRestApiOptionsTest method restApiHostAllowlist_shouldNotRequireAValue.

@Test
public void restApiHostAllowlist_shouldNotRequireAValue() {
    TekuConfiguration tekuConfiguration = getTekuConfigurationFromArguments("--rest-api-host-allowlist");
    final BeaconRestApiConfig config = getConfig(tekuConfiguration);
    assertThat(config.getRestApiHostAllowlist()).isEmpty();
    assertThat(createConfigBuilder().restApi(b -> b.restApiHostAllowlist(Collections.emptyList())).build()).usingRecursiveComparison().isEqualTo(tekuConfiguration);
}
Also used : TekuConfiguration(tech.pegasys.teku.config.TekuConfiguration) BeaconRestApiConfig(tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig) Test(org.junit.jupiter.api.Test) AbstractBeaconNodeCommandTest(tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)

Example 3 with BeaconRestApiConfig

use of tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig in project teku by ConsenSys.

the class BeaconRestApiOptionsTest method restApiCorsAllowedOrigins_shouldSupportAllowingMultipleHosts.

@Test
public void restApiCorsAllowedOrigins_shouldSupportAllowingMultipleHosts() {
    TekuConfiguration tekuConfiguration = getTekuConfigurationFromArguments("--rest-api-cors-origins", "my.host,their.host");
    final BeaconRestApiConfig config = getConfig(tekuConfiguration);
    assertThat(config.getRestApiCorsAllowedOrigins()).containsOnly("my.host", "their.host");
    assertThat(createConfigBuilder().restApi(b -> b.restApiCorsAllowedOrigins(List.of("my.host", "their.host"))).build()).usingRecursiveComparison().isEqualTo(tekuConfiguration);
}
Also used : TekuConfiguration(tech.pegasys.teku.config.TekuConfiguration) BeaconRestApiConfig(tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig) Test(org.junit.jupiter.api.Test) AbstractBeaconNodeCommandTest(tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)

Example 4 with BeaconRestApiConfig

use of tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig in project teku by ConsenSys.

the class BeaconRestApiOptionsTest method shouldReadFromConfigurationFile.

@Test
public void shouldReadFromConfigurationFile() {
    final BeaconRestApiConfig config = getConfig(getTekuConfigurationFromFile("beaconRestApiOptions_config.yaml"));
    assertThat(config.getRestApiInterface()).isEqualTo("127.100.0.1");
    assertThat(config.getRestApiPort()).isEqualTo(5055);
    assertThat(config.isRestApiDocsEnabled()).isTrue();
    assertThat(config.isRestApiEnabled()).isTrue();
    assertThat(config.getRestApiHostAllowlist()).containsExactly("test.domain.com", "11.12.13.14");
    assertThat(config.getRestApiCorsAllowedOrigins()).containsExactly("127.1.2.3", "origin.allowed.com");
    assertThat(config.getMaxUrlLength()).isEqualTo(65535);
}
Also used : BeaconRestApiConfig(tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig) Test(org.junit.jupiter.api.Test) AbstractBeaconNodeCommandTest(tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)

Example 5 with BeaconRestApiConfig

use of tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig in project teku by ConsenSys.

the class BeaconRestApiOptionsTest method restApiHostAllowlist_shouldSupportAllowingMultipleHosts.

@Test
public void restApiHostAllowlist_shouldSupportAllowingMultipleHosts() {
    TekuConfiguration tekuConfiguration = getTekuConfigurationFromArguments("--rest-api-host-allowlist", "my.host,their.host");
    final BeaconRestApiConfig config = getConfig(tekuConfiguration);
    assertThat(config.getRestApiHostAllowlist()).containsOnly("my.host", "their.host");
    assertThat(createConfigBuilder().restApi(b -> b.restApiHostAllowlist(List.of("my.host", "their.host"))).build()).usingRecursiveComparison().isEqualTo(tekuConfiguration);
}
Also used : TekuConfiguration(tech.pegasys.teku.config.TekuConfiguration) BeaconRestApiConfig(tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig) Test(org.junit.jupiter.api.Test) AbstractBeaconNodeCommandTest(tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)

Aggregations

Test (org.junit.jupiter.api.Test)13 BeaconRestApiConfig (tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig)13 AbstractBeaconNodeCommandTest (tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)12 TekuConfiguration (tech.pegasys.teku.config.TekuConfiguration)11 ArrayList (java.util.ArrayList)1 Response (okhttp3.Response)1 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)1 Eth1Address (tech.pegasys.teku.spec.datastructures.eth1.Eth1Address)1