summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-07-09 17:45:13 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-09 17:45:13 +0000
commitc4d310468216798ac9e11f690f90426ffca62964 (patch)
treee7de374a4413f10f40f28bfdaba15047ccc0a95c /ms/blueprintsprocessor/modules
parent630053dd9a2bc73a9ede63da0dc46f928cfdadc1 (diff)
parent2229d5048ecf5104024b51563a107f465d140f22 (diff)
Merge "Re-enabled RestClientServiceTest"
Diffstat (limited to 'ms/blueprintsprocessor/modules')
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml10
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt107
2 files changed, 59 insertions, 58 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml
index 0cae94690..011edae95 100644
--- a/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml
+++ b/ms/blueprintsprocessor/modules/commons/rest-lib/pom.xml
@@ -44,7 +44,15 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt
index 21d05e620..e6a66800b 100644
--- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt
+++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt
@@ -23,8 +23,8 @@ import com.fasterxml.jackson.databind.ObjectMapper
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
-import org.apache.catalina.connector.Connector
-import org.junit.Ignore
+import org.junit.After
+import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
@@ -34,18 +34,17 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
-import org.springframework.boot.web.servlet.server.ServletWebServerFactory
+import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
+import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory
+import org.springframework.boot.web.server.WebServer
import org.springframework.context.annotation.Bean
-import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
-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
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
-import org.springframework.security.crypto.password.PasswordEncoder
-import org.springframework.stereotype.Component
+import org.springframework.http.server.reactive.HttpHandler
+import org.springframework.security.config.web.server.ServerHttpSecurity
+import org.springframework.security.core.userdetails.MapReactiveUserDetailsService
+import org.springframework.security.core.userdetails.User
+import org.springframework.security.core.userdetails.UserDetails
+import org.springframework.security.web.server.SecurityWebFilterChain
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
@@ -63,10 +62,9 @@ import kotlin.test.assertNotNull
@RunWith(SpringRunner::class)
@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class])
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
-@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class,
- BlueprintPropertyConfiguration::class,
- SampleController::class, BluePrintProperties::class,
- BluePrintProperties::class])
+@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, SampleController::class,
+ SecurityConfiguration::class,
+ BlueprintPropertyConfiguration::class, BluePrintProperties::class])
@TestPropertySource(properties =
[
"server.port=8443",
@@ -76,7 +74,7 @@ import kotlin.test.assertNotNull
"server.ssl.keyStoreType=PKCS12",
"server.ssl.keyAlias=tomcat",
"blueprintsprocessor.restclient.sample.type=basic-auth",
- "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:8080",
+ "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:8081",
"blueprintsprocessor.restclient.sample.username=admin",
"blueprintsprocessor.restclient.sample.password=jans",
"blueprintsprocessor.restclient.test.type=ssl-basic-auth",
@@ -87,12 +85,31 @@ import kotlin.test.assertNotNull
"blueprintsprocessor.restclient.test.sslTrust=src/test/resources/keystore.p12",
"blueprintsprocessor.restclient.test.sslTrustPassword=changeit"
])
-@Ignore
class RestClientServiceTest {
@Autowired
lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
+ @Autowired
+ lateinit var httpHandler : HttpHandler
+
+ lateinit var http : WebServer
+
+ fun localPort() = http.port
+
+ @Before
+ fun start() {
+ // Second Http server required for non-SSL requests to be processed along with the https server.
+ val factory: ReactiveWebServerFactory = NettyReactiveWebServerFactory(8081)
+ this.http = factory.getWebServer(this.httpHandler)
+ this.http.start()
+ }
+
+ @After
+ fun stop() {
+ this.http.stop()
+ }
+
@Test
fun testPatch() {
val restClientService = bluePrintRestLibPropertyService
@@ -118,7 +135,7 @@ class RestClientServiceTest {
fun testSimpleBasicAuth() {
val json: String = "{\n" +
" \"type\" : \"basic-auth\",\n" +
- " \"url\" : \"http://localhost:8080\",\n" +
+ " \"url\" : \"http://localhost:8081\",\n" +
" \"username\" : \"admin\",\n" +
" \"password\" : \"jans\"\n" +
"}"
@@ -308,49 +325,25 @@ open class SampleController {
* Security configuration required for basic authentication with username and
* password for any request in the server.
*/
-@Configuration
-@EnableWebSecurity
-open class SecurityConfig : WebSecurityConfigurerAdapter() {
-
- @Throws(Exception::class)
- override fun configure(http: HttpSecurity) {
- http
- .csrf().disable()
- .authorizeRequests().anyRequest().authenticated()
- .and()
- .httpBasic()
- }
+open class SecurityConfiguration {
- @Autowired
- @Throws(Exception::class)
- open fun configureGlobal(auth: AuthenticationManagerBuilder) {
- auth.inMemoryAuthentication()
- .withUser("admin")
- .password(passwordEncoder().encode("jans"))
+ @Bean
+ open fun userDetailsService(): MapReactiveUserDetailsService {
+ val user: UserDetails = User.withDefaultPasswordEncoder()
+ .username("admin")
+ .password("jans")
.roles("USER")
+ .build()
+ return MapReactiveUserDetailsService(user)
}
@Bean
- open fun passwordEncoder(): PasswordEncoder {
- return BCryptPasswordEncoder()
- }
-}
-
-/**
- * Http server required for http request to be processed along with the https
- * server.
- */
-@Component
-class HttpServer {
- @Bean
- fun servletContainer(): ServletWebServerFactory {
-
- val connector = Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL)
- connector.port = 8080
-
- val tomcat = TomcatServletWebServerFactory()
- tomcat.addAdditionalTomcatConnectors(connector)
- return tomcat
+ open fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
+ return http
+ .csrf().disable()
+ .authorizeExchange().anyExchange().authenticated()
+ .and().httpBasic()
+ .and().build()
}
}