-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spring mvc tests to java (open-telemetry#11114)
Co-authored-by: Lauri Tulmin <[email protected]>
- Loading branch information
1 parent
32df5ae
commit deac397
Showing
33 changed files
with
1,398 additions
and
1,162 deletions.
There are no files selected for viewing
61 changes: 0 additions & 61 deletions
61
...spring-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SecurityConfig.groovy
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
...g-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy
This file was deleted.
Oops, something went wrong.
90 changes: 0 additions & 90 deletions
90
...webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterConfig.groovy
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
...g-webmvc/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
...va/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v3_1/boot/SecurityConfig.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,67 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.spring.webmvc.v3_1.boot; | ||
|
||
import io.opentelemetry.instrumentation.spring.webmvc.boot.SavingAuthenticationProvider; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfig { | ||
|
||
@Bean | ||
SavingAuthenticationProvider savingAuthenticationProvider() { | ||
return new SavingAuthenticationProvider(); | ||
} | ||
|
||
/** | ||
* Following configuration is required for unauthorised call tests (form would redirect, we need | ||
* 401) | ||
*/ | ||
@Configuration | ||
@Order(1) | ||
static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.csrf() | ||
.disable() | ||
.antMatcher("/basicsecured/**") | ||
.authorizeRequests() | ||
.antMatchers("/basicsecured/**") | ||
.authenticated() | ||
.and() | ||
.httpBasic() | ||
.and() | ||
.authenticationProvider( | ||
getApplicationContext().getBean(SavingAuthenticationProvider.class)); | ||
} | ||
} | ||
|
||
/** Following configuration is required in order to get form login, needed by password tests */ | ||
@Configuration | ||
static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.csrf() | ||
.disable() | ||
.authorizeRequests() | ||
.antMatchers("/formsecured/**") | ||
.authenticated() | ||
.and() | ||
.formLogin() | ||
.and() | ||
.authenticationProvider( | ||
getApplicationContext().getBean(SavingAuthenticationProvider.class)); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
.../opentelemetry/javaagent/instrumentation/spring/webmvc/v3_1/boot/SpringBootBasedTest.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,62 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.spring.webmvc.v3_1.boot; | ||
|
||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.opentelemetry.instrumentation.spring.webmvc.boot.AbstractSpringBootBasedTest; | ||
import io.opentelemetry.instrumentation.spring.webmvc.boot.AppConfig; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
class SpringBootBasedTest extends AbstractSpringBootBasedTest { | ||
|
||
@RegisterExtension | ||
private static final InstrumentationExtension testing = | ||
HttpServerInstrumentationExtension.forAgent(); | ||
|
||
private ConfigurableApplicationContext context; | ||
|
||
@Override | ||
protected ConfigurableApplicationContext context() { | ||
return context; | ||
} | ||
|
||
@Override | ||
protected ConfigurableApplicationContext setupServer() { | ||
SpringApplication app = new SpringApplication(AppConfig.class, securityConfigClass()); | ||
app.setDefaultProperties( | ||
ImmutableMap.of( | ||
"server.port", | ||
port, | ||
"server.context-path", | ||
getContextPath(), | ||
"server.servlet.contextPath", | ||
getContextPath(), | ||
"server.error.include-message", | ||
"always")); | ||
context = app.run(); | ||
return context; | ||
} | ||
|
||
@Override | ||
public Class<?> securityConfigClass() { | ||
return SecurityConfig.class; | ||
} | ||
|
||
@Override | ||
protected void configure(HttpServerTestOptions options) { | ||
super.configure(options); | ||
options.setResponseCodeOnNonStandardHttpMethod( | ||
Boolean.getBoolean("testLatestDeps") ? 500 : 200); | ||
options.setExpectedException(new RuntimeException(EXCEPTION.getBody())); | ||
} | ||
} |
Oops, something went wrong.