Skip to content

Commit

Permalink
Remove spring-jdbc from the security tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-alvarez-alvarez committed Sep 18, 2024
1 parent 59fefb9 commit d05d199
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 129 deletions.
3 changes: 0 additions & 3 deletions dd-java-agent/instrumentation/spring-security-5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ dependencies {
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: springBootVersion
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: springBootVersion

latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.+'

testRuntimeOnly project(':dd-java-agent:instrumentation:tomcat-appsec-6')
testRuntimeOnly project(':dd-java-agent:instrumentation:tomcat-5.5')
testRuntimeOnly 'com.h2database:h2:2.1.212'
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ com.google.guava:guava:27.0.1-jre=annotationProcessor,latestDepTestAnnotationPro
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor
com.google.j2objc:j2objc-annotations:1.1=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor
com.google.re2j:re2j:1.7=instrumentPluginClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
com.h2database:h2:2.1.212=latestDepTestRuntimeClasspath,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.6.0=testCompileClasspath,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.7.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
com.squareup.moshi:moshi:1.11.0=compileClasspath,instrumentPluginClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand All @@ -61,7 +60,6 @@ com.squareup.okhttp3:okhttp:3.12.12=latestDepTestCompileClasspath,latestDepTestR
com.squareup.okio:okio:1.17.5=compileClasspath,instrumentPluginClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.thoughtworks.qdox:qdox:1.12.1=latestDepTestRuntimeClasspath,testRuntimeClasspath
com.vaadin.external.google:android-json:0.0.20131108.vaadin1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.zaxxer:HikariCP:4.0.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
commons-codec:commons-codec:1.15=spotbugs
commons-fileupload:commons-fileupload:1.5=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
commons-io:commons-io:2.11.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -195,8 +193,6 @@ org.spockframework:spock-core:2.2-groovy-3.0=latestDepTestCompileClasspath,lates
org.spockframework:spock-junit4:2.2-groovy-3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-autoconfigure:2.6.0=testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-autoconfigure:2.7.18=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework.boot:spring-boot-starter-jdbc:2.6.0=testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-starter-jdbc:2.7.18=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework.boot:spring-boot-starter-json:2.6.0=testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-starter-json:2.7.18=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework.boot:spring-boot-starter-logging:2.6.0=testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -245,12 +241,8 @@ org.springframework:spring-expression:5.3.31=latestDepTestCompileClasspath,lates
org.springframework:spring-jcl:5.3.13=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-jcl:5.3.25=compileClasspath
org.springframework:spring-jcl:5.3.31=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-jdbc:5.3.13=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-jdbc:5.3.31=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-test:5.3.13=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-test:5.3.31=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-tx:5.3.13=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-tx:5.3.31=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-web:5.3.13=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-web:5.3.31=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-webmvc:5.3.13=testCompileClasspath,testRuntimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ package datadog.trace.instrumentation.springsecurity5

import custom.CustomAuthenticationFilter
import custom.CustomAuthenticationProvider
import org.springframework.boot.jdbc.DataSourceBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.authentication.AuthenticationManager
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.configurers.AbstractHttpConfigurer
import org.springframework.security.provisioning.JdbcUserDetailsManager
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.security.provisioning.UserDetailsManager
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

import javax.sql.DataSource

import static datadog.trace.instrumentation.springsecurity5.SecurityConfig.CustomDsl.customDsl

@Configuration
Expand All @@ -34,19 +32,17 @@ class SecurityConfig {
return http.build()
}

@Bean
DataSource getDataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create()
dataSourceBuilder.driverClassName("org.h2.Driver")
dataSourceBuilder.url("jdbc:h2:mem:authDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=RUNSCRIPT FROM 'classpath:schema.sql';")
dataSourceBuilder.username("SA")
dataSourceBuilder.password("")
return dataSourceBuilder.build()
}

@Bean
UserDetailsManager userDetailsService() {
return new JdbcUserDetailsManager(dataSource)
return new InMemoryUserDetailsManager() {
@Override
void createUser(UserDetails user) {
if (user.username == 'cant_create_me') {
throw new IllegalArgumentException('cannot create user')
}
super.createUser(user)
}
}
}

static class CustomDsl extends AbstractHttpConfigurer<CustomDsl, HttpSecurity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class SpringBootBasedTest extends AppSecHttpServerTest<ConfigurableApplicationCo
void 'test failed signup'() {
setup:
final formBody = new FormBody.Builder()
.add('username', randomString(1_000))
.add('username', 'cant_create_me')
.add('password', 'cant_create_me')
.build()

Expand Down Expand Up @@ -288,11 +288,4 @@ class SpringBootBasedTest extends AppSecHttpServerTest<ConfigurableApplicationCo
span.getTag("usr.id") == 'admin'
span.getTag("_dd.appsec.user.collection_mode") == 'ident'
}

@SuppressWarnings('GroovyAssignabilityCheck')
private static String randomString(int length) {
return new Random().with { random ->
(1..length).collect { Character.valueOf((char) (random.nextInt(26) + (char)'a')) }
}.join()
}
}

This file was deleted.

3 changes: 0 additions & 3 deletions dd-java-agent/instrumentation/spring-security-6/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ dependencies {
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: springBootVersion
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: springBootVersion

latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '+'

testRuntimeOnly project(':dd-java-agent:instrumentation:tomcat-appsec-6')
testRuntimeOnly project(':dd-java-agent:instrumentation:tomcat-5.5')
testRuntimeOnly 'com.h2database:h2:2.1.212'
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ com.google.guava:guava:27.0.1-jre=annotationProcessor,latestDepTestAnnotationPro
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor
com.google.j2objc:j2objc-annotations:1.1=annotationProcessor,latestDepTestAnnotationProcessor,testAnnotationProcessor
com.google.re2j:re2j:1.7=instrumentPluginClasspath,latestDepTestRuntimeClasspath,main_java17RuntimeClasspath,muzzleTooling,runtimeClasspath,testRuntimeClasspath
com.h2database:h2:2.1.212=latestDepTestRuntimeClasspath,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.7.0=testCompileClasspath,testRuntimeClasspath
com.jayway.jsonpath:json-path:2.9.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
com.squareup.moshi:moshi:1.11.0=compileClasspath,instrumentPluginClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,main_java17CompileClasspath,main_java17RuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand All @@ -62,8 +61,6 @@ com.squareup.okhttp3:okhttp:3.12.12=latestDepTestCompileClasspath,latestDepTestR
com.squareup.okio:okio:1.17.5=compileClasspath,instrumentPluginClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,main_java17CompileClasspath,main_java17RuntimeClasspath,muzzleTooling,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.thoughtworks.qdox:qdox:1.12.1=latestDepTestRuntimeClasspath,testRuntimeClasspath
com.vaadin.external.google:android-json:0.0.20131108.vaadin1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
com.zaxxer:HikariCP:5.0.1=testCompileClasspath,testRuntimeClasspath
com.zaxxer:HikariCP:5.1.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
commons-codec:commons-codec:1.15=spotbugs
commons-fileupload:commons-fileupload:1.5=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
commons-io:commons-io:2.11.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -218,8 +215,6 @@ org.spockframework:spock-core:2.2-groovy-3.0=latestDepTestCompileClasspath,lates
org.spockframework:spock-junit4:2.2-groovy-3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-autoconfigure:3.0.0=testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-autoconfigure:3.3.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework.boot:spring-boot-starter-jdbc:3.0.0=testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-starter-jdbc:3.3.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework.boot:spring-boot-starter-json:3.0.0=testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-starter-json:3.3.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework.boot:spring-boot-starter-logging:3.0.0=testCompileClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -260,12 +255,8 @@ org.springframework:spring-expression:6.0.2=testCompileClasspath,testRuntimeClas
org.springframework:spring-expression:6.1.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-jcl:6.0.2=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-jcl:6.1.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-jdbc:6.0.2=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-jdbc:6.1.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-test:6.0.2=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-test:6.1.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-tx:6.0.2=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-tx:6.1.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-web:6.0.2=testCompileClasspath,testRuntimeClasspath
org.springframework:spring-web:6.1.12=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.springframework:spring-webmvc:6.0.2=testCompileClasspath,testRuntimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ package datadog.trace.instrumentation.springsecurity6

import custom.CustomAuthenticationFilter
import custom.CustomAuthenticationProvider
import org.springframework.boot.jdbc.DataSourceBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.authentication.AuthenticationManager
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.configurers.AbstractHttpConfigurer
import org.springframework.security.provisioning.JdbcUserDetailsManager
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.security.provisioning.UserDetailsManager
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

import javax.sql.DataSource

@Configuration
@EnableWebSecurity
class SecurityConfig {
Expand All @@ -32,19 +30,17 @@ class SecurityConfig {
return http.build()
}

@Bean
DataSource getDataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create()
dataSourceBuilder.driverClassName("org.h2.Driver")
dataSourceBuilder.url("jdbc:h2:mem:authDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=RUNSCRIPT FROM 'classpath:schema.sql';")
dataSourceBuilder.username("SA")
dataSourceBuilder.password("")
return dataSourceBuilder.build()
}

@Bean
UserDetailsManager userDetailsService() {
return new JdbcUserDetailsManager(dataSource)
return new InMemoryUserDetailsManager() {
@Override
void createUser(UserDetails user) {
if (user.username == 'cant_create_me') {
throw new IllegalArgumentException('cannot create user')
}
super.createUser(user)
}
}
}

static class CustomDsl extends AbstractHttpConfigurer<CustomDsl, HttpSecurity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class SpringBootBasedTest extends AppSecHttpServerTest<ConfigurableApplicationCo
void 'test failed signup'() {
setup:
final formBody = new FormBody.Builder()
.add('username', randomString(1_000))
.add('username', 'cant_create_me')
.add('password', 'cant_create_me')
.build()

Expand Down Expand Up @@ -288,11 +288,4 @@ class SpringBootBasedTest extends AppSecHttpServerTest<ConfigurableApplicationCo
span.getTag("usr.id") == 'admin'
span.getTag("_dd.appsec.user.collection_mode") == 'ident'
}

@SuppressWarnings('GroovyAssignabilityCheck')
private static String randomString(int length) {
return new Random().with { random ->
(1..length).collect { Character.valueOf((char) (random.nextInt(26) + (char)'a')) }
}.join()
}
}

This file was deleted.

0 comments on commit d05d199

Please sign in to comment.