fix: open threads in MR and keycloak test container
This commit is contained in:
parent
a6faea516b
commit
b18bc36511
|
@ -6,9 +6,9 @@ import {NbEvaIconsModule} from '@nebular/eva-icons';
|
|||
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
|
||||
import {HttpLoaderFactory} from './common-app.module';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {ThemeModule} from '../assets/@theme/theme.module';
|
||||
import {ThemeModule} from '@assets/@theme/theme.module';
|
||||
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
||||
import {SessionState} from '../shared/stores/session-state/session-state';
|
||||
import {SessionState} from '@shared/stores/session-state/session-state';
|
||||
import {NgxsModule} from '@ngxs/store';
|
||||
import {HeaderModule} from './header/header.module';
|
||||
import {KeycloakService} from 'keycloak-angular';
|
||||
|
|
|
@ -17,46 +17,46 @@ import {FaConfig, FaIconLibrary, FontAwesomeModule} from '@fortawesome/angular-f
|
|||
import {fas} from '@fortawesome/free-solid-svg-icons';
|
||||
import {far} from '@fortawesome/free-regular-svg-icons';
|
||||
import {NgxsModule} from '@ngxs/store';
|
||||
import {SessionState} from '../shared/stores/session-state/session-state';
|
||||
import {SessionState} from '@shared/stores/session-state/session-state';
|
||||
import {environment} from '../environments/environment';
|
||||
import {NotificationService} from '../shared/services/notification.service';
|
||||
import {NotificationService} from '@shared/services/notification.service';
|
||||
import {ThemeModule} from '@assets/@theme/theme.module';
|
||||
import {HeaderModule} from './header/header.module';
|
||||
import {HomeModule} from './home/home.module';
|
||||
import {KeycloakService} from 'keycloak-angular';
|
||||
import {httpInterceptorProviders} from '../shared/interceptors';
|
||||
import {httpInterceptorProviders} from '@shared/interceptors';
|
||||
import {FlexLayoutModule} from '@angular/flex-layout';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppRoutingModule,
|
||||
RouterModule,
|
||||
FontAwesomeModule,
|
||||
NbToastrModule.forRoot(), // used for notification service
|
||||
BrowserAnimationsModule,
|
||||
ThemeModule.forRoot(),
|
||||
NbLayoutModule,
|
||||
NbCardModule,
|
||||
NbIconModule,
|
||||
NbButtonModule,
|
||||
NbEvaIconsModule,
|
||||
NgxsModule.forRoot([SessionState], {developmentMode: !environment.production}),
|
||||
HttpClientModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useFactory: HttpLoaderFactory,
|
||||
deps: [HttpClient]
|
||||
}
|
||||
}),
|
||||
HeaderModule,
|
||||
HomeModule,
|
||||
FlexLayoutModule
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppRoutingModule,
|
||||
RouterModule,
|
||||
FontAwesomeModule,
|
||||
NbToastrModule.forRoot(), // used for notification service
|
||||
BrowserAnimationsModule,
|
||||
ThemeModule.forRoot(),
|
||||
NbLayoutModule,
|
||||
NbCardModule,
|
||||
NbIconModule,
|
||||
NbButtonModule,
|
||||
NbEvaIconsModule,
|
||||
NgxsModule.forRoot([SessionState], {developmentMode: !environment.production}),
|
||||
HttpClientModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useFactory: HttpLoaderFactory,
|
||||
deps: [HttpClient]
|
||||
}
|
||||
}),
|
||||
HeaderModule,
|
||||
HomeModule,
|
||||
FlexLayoutModule
|
||||
],
|
||||
providers: [
|
||||
HttpClient,
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {HeaderComponent} from './header.component';
|
||||
import {NbActionsModule, NbButtonModule, NbCardModule} from '@nebular/theme';
|
||||
import {FontAwesomeModule} from '@fortawesome/angular-fontawesome';
|
||||
|
@ -12,13 +12,14 @@ import {FlexLayoutModule} from '@angular/flex-layout';
|
|||
exports: [
|
||||
HeaderComponent
|
||||
],
|
||||
imports: [
|
||||
CommonModule,
|
||||
NbButtonModule,
|
||||
FontAwesomeModule,
|
||||
NbCardModule,
|
||||
NbActionsModule,
|
||||
FlexLayoutModule
|
||||
]
|
||||
imports: [
|
||||
CommonModule,
|
||||
NbButtonModule,
|
||||
FontAwesomeModule,
|
||||
NbCardModule,
|
||||
NbActionsModule,
|
||||
FlexLayoutModule
|
||||
]
|
||||
})
|
||||
export class HeaderModule { }
|
||||
export class HeaderModule {
|
||||
}
|
||||
|
|
|
@ -74,7 +74,6 @@ dependencies {
|
|||
|
||||
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
|
||||
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
|
||||
implementation("com.auth0:java-jwt:3.18.1")
|
||||
implementation("org.modelmapper:modelmapper:2.3.2")
|
||||
|
||||
api("org.springframework.security:spring-security-jwt:1.1.1.RELEASE")
|
||||
|
|
|
@ -29,15 +29,15 @@ To get projects, call the GET request /projects
|
|||
|
||||
==== Request example
|
||||
|
||||
#include::{snippets}/getProjects/com.securityc4po.api.http-request.adoc[]
|
||||
include::{snippets}/getProjects/http-request.adoc[]
|
||||
|
||||
==== Response example
|
||||
|
||||
#include::{snippets}/getProjects/com.securityc4po.api.http-response.adoc[]
|
||||
include::{snippets}/getProjects/http-response.adoc[]
|
||||
|
||||
==== Response structure
|
||||
|
||||
#include::{snippets}/getProjects/response-fields.adoc[]
|
||||
include::{snippets}/getProjects/response-fields.adoc[]
|
||||
|
||||
== Change History
|
||||
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
package com.securityc4po.api
|
||||
|
||||
import com.securityc4po.api.configuration.MESSAGE_NOT_INITIALIZED_REDUNDANT_NULLCHECK
|
||||
import com.securityc4po.api.configuration.NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
|
||||
import com.securityc4po.api.configuration.RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
|
||||
import org.springframework.data.annotation.Id
|
||||
|
||||
@SuppressFBWarnings(
|
||||
NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR,
|
||||
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE,
|
||||
MESSAGE_NOT_INITIALIZED_REDUNDANT_NULLCHECK
|
||||
)
|
||||
abstract class BaseEntity<T>(
|
||||
var data: T
|
||||
) {
|
||||
@Id
|
||||
lateinit var id: String
|
||||
}
|
||||
|
|
|
@ -9,16 +9,14 @@ import org.springframework.security.core.GrantedAuthority
|
|||
import org.springframework.security.core.authority.SimpleGrantedAuthority
|
||||
import org.springframework.security.oauth2.jwt.Jwt
|
||||
import reactor.core.publisher.Mono
|
||||
import reactor.kotlin.core.publisher.toMono
|
||||
import java.util.stream.Collectors
|
||||
|
||||
/** JWT converter that takes the roles from 'groups' claim of JWT token. */
|
||||
class AppuserJwtAuthConverter(private val appuserDetailsService: UserAccountDetailsService) :
|
||||
Converter<Jwt, Mono<AbstractAuthenticationToken>> {
|
||||
|
||||
override fun convert(jwt: Jwt): Mono<AbstractAuthenticationToken> {
|
||||
val authorities = extractAuthorities(jwt)
|
||||
val sub = extractSub(jwt)
|
||||
// val sub = extractSub(jwt)
|
||||
val username = extractUserName(jwt)
|
||||
return appuserDetailsService
|
||||
.findByUsername(username)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.securityc4po.api.configuration.security
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity
|
||||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
|
||||
|
@ -10,9 +13,12 @@ import org.springframework.web.cors.CorsConfiguration
|
|||
|
||||
@EnableWebFluxSecurity
|
||||
@EnableReactiveMethodSecurity
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
class WebSecurityConfiguration(private val userAccountDetailsService: UserAccountDetailsService) {
|
||||
|
||||
@Bean
|
||||
fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
|
||||
fun setSecurityWebFilterChains(http: ServerHttpSecurity): SecurityWebFilterChain {
|
||||
http.cors().configurationSource {
|
||||
CorsConfiguration().apply {
|
||||
this.applyPermitDefaultValues()
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.securityc4po.api.project
|
||||
|
||||
import com.securityc4po.api.BaseEntity
|
||||
import com.securityc4po.api.configuration.BC_BAD_CAST_TO_ABSTRACT_COLLECTION
|
||||
import com.securityc4po.api.configuration.MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
|
||||
@Document(collection = "projects")
|
||||
|
@ -19,6 +22,7 @@ fun ProjectEntity.toProject() : Project {
|
|||
)
|
||||
}
|
||||
|
||||
@SuppressFBWarnings(BC_BAD_CAST_TO_ABSTRACT_COLLECTION, MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION)
|
||||
fun List<ProjectEntity>.toProjects(): List<Project> {
|
||||
return this.map {
|
||||
it.toProject()
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package com.securityc4po.api.project
|
||||
|
||||
import com.securityc4po.api.configuration.BC_BAD_CAST_TO_ABSTRACT_COLLECTION
|
||||
import com.securityc4po.api.configuration.MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION
|
||||
import com.securityc4po.api.extensions.getLoggerFor
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
|
||||
import org.springframework.stereotype.Service
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Service
|
||||
@SuppressFBWarnings(BC_BAD_CAST_TO_ABSTRACT_COLLECTION, MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION)
|
||||
class ProjectService(private val projectRepository: ProjectRepository) {
|
||||
|
||||
var logger = getLoggerFor<ProjectService>()
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
## IdentityProvider (Keycloak) ##
|
||||
# spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8888/auth/realms/c4po_realm_local
|
||||
# keycloakhost=localhost
|
||||
# keycloak.client.url=http://localhost:8888/
|
||||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8888/auth/realms/c4po_realm_local
|
||||
keycloakhost=localhost
|
||||
keycloak.client.url=http://localhost:8888
|
||||
keycloak.client.realm.path=auth/realms/c4po_realm_local/
|
||||
|
||||
## Database (MONGODB) Config ##
|
||||
spring.data.mongodb.host=c4po-db
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
## IdentityProvider (Keycloak) ##
|
||||
# spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8888/auth/realms/c4po_realm_local
|
||||
# keycloakhost=localhost
|
||||
# keycloak.client.url=http://localhost:8888/
|
||||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8888/auth/realms/c4po_realm_local
|
||||
keycloakhost=localhost
|
||||
keycloak.client.url=http://localhost:8888/
|
||||
|
||||
## Database (MONGODB) Config ##
|
||||
spring.data.mongodb.host=localhost
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
## IdentityProvider (Keycloak) ##
|
||||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8888/auth/realms/c4po_realm_local
|
||||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:9999/auth/realms/c4po_realm_local
|
||||
keycloakhost=localhost
|
||||
keycloak.client.url=http://localhost:8888/
|
||||
# keycloak.client.realm.path=auth/realms/c4po_realm_local/
|
||||
idp.jwt.claim.name.user=username
|
||||
keycloak.client.url=http://localhost:9999
|
||||
keycloak.client.realm.path=auth/realms/c4po_realm_local/
|
||||
|
||||
static-jwt.hmacsecret="secret"
|
||||
static-jwt.issuer="http://localhost:8888/auth/realms/c4po_realm_local"
|
||||
static-jwt.valid-token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzUzMDYxNzQsImlhdCI6MTYzNDMwNTg3NCwiYXV0aF90aW1lIjoxNjM0MzA1ODE0LCJqdGkiOiI2OTQ1MGJlYi03MzU2LTQ1ODUtYjg2My1hOTZmZjI3MzA2MWQiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODgvYXV0aC9yZWFsbXMvYzRwb19yZWFsbV9sb2NhbCIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiIxMGUwNmQ3YS04ZGQwLTRlY2QtODk2My0wNTZiNDUwNzljNGYiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJjNHBvX2xvY2FsIiwibm9uY2UiOiI3ZGI4YjJmOC03MTAyLTQxMTYtOWFhZC01YjgyZDA4OWJjN2IiLCJzZXNzaW9uX3N0YXRlIjoiODQ3ZGY4NmItZDI1MS00M2MzLWIxNzMtOGQ0ZjgxNzg0YmVkIiwiYWNyIjoiMCIsImFsbG93ZWQtb3JpZ2lucyI6WyIqIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJjNHBvX3VzZXIiLCJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYzRwb19sb2NhbCI6eyJyb2xlcyI6WyJ1c2VyIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJuYW1lIjoidGVzdCB1c2VyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidHR0IiwiZ2l2ZW5fbmFtZSI6InRlc3QiLCJmYW1pbHlfbmFtZSI6InVzZXIifQ.R1HeCozwPAlmck8zV1CF86vKVLwdyFcNuQZZ7eOXqxU"
|
||||
## Database (MONGODB) Config ##
|
||||
spring.data.mongodb.host=localhost
|
||||
spring.data.mongodb.port=27021
|
|
@ -18,6 +18,5 @@ spring.data.mongodb.auto-index-creation=true
|
|||
## IdentityProvider (Keycloak) ##
|
||||
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8888/auth/realms/c4po_realm_local
|
||||
keycloakhost=localhost
|
||||
keycloak.client.url=http://localhost:8888/
|
||||
# keycloak.client.realm.path=auth/realms/c4po_realm_local/
|
||||
idp.jwt.claim.name.user=username
|
||||
keycloak.client.url=http://localhost:8888
|
||||
keycloak.client.realm.path=auth/realms/c4po_realm_local/
|
|
@ -22,11 +22,10 @@ import org.testcontainers.utility.DockerImageName
|
|||
import org.testcontainers.utility.MountableFile
|
||||
import java.nio.file.Paths
|
||||
|
||||
// @ActiveProfiles("TEST")
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@AutoConfigureWireMock(port = 0)
|
||||
@TestPropertySource(properties = [
|
||||
"spring.data.mongodb.port=10002",
|
||||
"spring.data.mongodb.port=27017",
|
||||
"spring.data.mongodb.authentication-database=admin",
|
||||
"spring.data.mongodb.password=test",
|
||||
"spring.data.mongodb.username=testuser",
|
||||
|
@ -48,12 +47,12 @@ abstract class BaseContainerizedTest {
|
|||
}.withFileFromPath("insert-mongodb-user.js", Paths.get(MountableFile.forClasspathResource("insert-mongodb-user.js", 700).resolvedPath))
|
||||
).apply {
|
||||
withCreateContainerCmdModifier {
|
||||
it.hostConfig?.withPortBindings(PortBinding(Ports.Binding.bindPort(10002), ExposedPort(27017)))
|
||||
it.hostConfig?.withPortBindings(PortBinding(Ports.Binding.bindPort(27017), ExposedPort(27017)))
|
||||
}
|
||||
start()
|
||||
}
|
||||
|
||||
val keycloakContainer = KGenericContainerFromImage(DockerImageName.parse("jboss/keycloak:6.0.1")).apply {
|
||||
val keycloakContainer = KGenericContainerFromImage(DockerImageName.parse("jboss/keycloak:11.0.3")).apply {
|
||||
withEnv("KEYCLOAK_USER", "admin")
|
||||
withEnv("KEYCLOAK_PASSWORD", "admin")
|
||||
withEnv("KEYCLOAK_IMPORT", "/tmp/realm.json")
|
||||
|
@ -62,8 +61,6 @@ abstract class BaseContainerizedTest {
|
|||
it.hostConfig?.withPortBindings(PortBinding(Ports.Binding.bindPort(8888), ExposedPort(8080)))
|
||||
}
|
||||
withCopyFileToContainer(MountableFile.forClasspathResource("realm-export.json", 700), "/tmp/realm.json")
|
||||
withCopyFileToContainer(MountableFile.forClasspathResource("create-keycloak-user.sh", 700),
|
||||
"/opt/jboss/create-keycloak-user.sh")
|
||||
start()
|
||||
println("== Inserting users must wait until Keycloak is started completely ==")
|
||||
execInContainer("sh", "/opt/jboss/create-keycloak-user.sh")
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package com.securityc4po.api
|
||||
|
||||
class KeycloakExtension {
|
||||
|
||||
}
|
|
@ -2,13 +2,15 @@ package com.securityc4po.api.project
|
|||
|
||||
import com.github.tomakehurst.wiremock.common.Json
|
||||
import com.securityc4po.api.BaseDocumentationIntTest
|
||||
import com.securityc4po.api.configuration.NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
|
||||
import com.securityc4po.api.configuration.RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
|
||||
import com.securityc4po.api.configuration.SIC_INNER_SHOULD_BE_STATIC
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
import org.springframework.data.mongodb.core.query.Query
|
||||
import org.springframework.restdocs.operation.preprocess.Preprocessors
|
||||
|
@ -16,8 +18,11 @@ import org.springframework.restdocs.payload.JsonFieldType
|
|||
import org.springframework.restdocs.payload.PayloadDocumentation
|
||||
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation
|
||||
|
||||
@AutoConfigureWireMock(port = 0)
|
||||
@SuppressFBWarnings(SIC_INNER_SHOULD_BE_STATIC)
|
||||
@SuppressFBWarnings(
|
||||
SIC_INNER_SHOULD_BE_STATIC,
|
||||
NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR,
|
||||
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
|
||||
)
|
||||
class ProjectControllerDocumentationTest : BaseDocumentationIntTest() {
|
||||
|
||||
@Autowired
|
||||
|
@ -25,18 +30,21 @@ class ProjectControllerDocumentationTest : BaseDocumentationIntTest() {
|
|||
|
||||
@BeforeEach
|
||||
fun init() {
|
||||
cleanUp()
|
||||
configureAdminToken()
|
||||
persistBasicTestScenario()
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun destroy() {
|
||||
cleanUp()
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class GetProjects {
|
||||
@Test
|
||||
fun getProjects() {
|
||||
/* Implement after the implementation of database */
|
||||
|
||||
/*webTestClient.get().uri("/v1/projects")
|
||||
.header("")
|
||||
webTestClient.get().uri("/projects")
|
||||
.header("Authorization", "Bearer $tokenAdmin")
|
||||
.exchange()
|
||||
.expectStatus().isOk
|
||||
.expectHeader().doesNotExist("")
|
||||
|
@ -49,14 +57,14 @@ class ProjectControllerDocumentationTest : BaseDocumentationIntTest() {
|
|||
Preprocessors.prettyPrint()
|
||||
),
|
||||
PayloadDocumentation.relaxedResponseFields(
|
||||
PayloadDocumentation.fieldWithPath("[].id").type(JsonFieldType.STRING).description("The id of the requested Project"),
|
||||
PayloadDocumentation.fieldWithPath("[].client").type(JsonFieldType.STRING).description("The name of the client of the requested Project"),
|
||||
PayloadDocumentation.fieldWithPath("[].title").type(JsonFieldType.STRING).description("The title of the requested Project"),
|
||||
PayloadDocumentation.fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("The date where the Project was created at"),
|
||||
PayloadDocumentation.fieldWithPath("[].tester").type(JsonFieldType.STRING).description("The user that is used as a tester in the Project"),
|
||||
PayloadDocumentation.fieldWithPath("[].logo").type(JsonFieldType.STRING).description("The sensors contained in the Project")
|
||||
PayloadDocumentation.fieldWithPath("[].id").type(JsonFieldType.STRING).description("The id of the requested project"),
|
||||
PayloadDocumentation.fieldWithPath("[].client").type(JsonFieldType.STRING).description("The name of the client of the requested project"),
|
||||
PayloadDocumentation.fieldWithPath("[].title").type(JsonFieldType.STRING).description("The title of the requested project"),
|
||||
PayloadDocumentation.fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("The date where the project was created at"),
|
||||
PayloadDocumentation.fieldWithPath("[].tester").type(JsonFieldType.STRING).description("The user that is assigned as a tester in the project"),
|
||||
PayloadDocumentation.fieldWithPath("[].createdBy").type(JsonFieldType.STRING).description("The id of the user that created the project")
|
||||
)
|
||||
))*/
|
||||
))
|
||||
}
|
||||
|
||||
val projectOne = Project(
|
||||
|
@ -82,30 +90,36 @@ class ProjectControllerDocumentationTest : BaseDocumentationIntTest() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun cleanUp() {
|
||||
mongoTemplate.findAllAndRemove(Query(), Project::class.java)
|
||||
}
|
||||
|
||||
private fun persistBasicTestScenario() {
|
||||
// setup test data
|
||||
val projectOne = Project(
|
||||
id = "260aa538-0873-43fc-84de-3a09b008646d",
|
||||
client = "",
|
||||
title = "",
|
||||
createdAt = "",
|
||||
tester = "",
|
||||
createdBy = ""
|
||||
id = "4f6567a8-76fd-487b-8602-f82d0ca4d1f9",
|
||||
client = "E Corp",
|
||||
title = "Some Mock API (v1.0) Scanning",
|
||||
createdAt = "2021-01-10T18:05:00Z",
|
||||
tester = "Novatester",
|
||||
createdBy = "f8aab31f-4925-4242-a6fa-f98135b4b032"
|
||||
)
|
||||
val projectTwo = Project(
|
||||
id = "260aa538-0873-43fc-84de-3a09b008646d",
|
||||
client = "",
|
||||
title = "",
|
||||
createdAt = "",
|
||||
tester = "",
|
||||
createdBy = ""
|
||||
id = "61360a47-796b-4b3f-abf9-c46c668596c5",
|
||||
client = "Allsafe",
|
||||
title = "CashMyData (iOS)",
|
||||
createdAt = "2021-01-10T18:05:00Z",
|
||||
tester = "Elliot",
|
||||
createdBy = "f8aab31f-4925-4242-a6fa-f98135b4b032"
|
||||
)
|
||||
cleanUp()
|
||||
// persist test data in database
|
||||
mongoTemplate.save(ProjectEntity(projectOne))
|
||||
mongoTemplate.save(ProjectEntity(projectTwo))
|
||||
}
|
||||
|
||||
private fun configureAdminToken() {
|
||||
tokenAdmin = getAccessToken("test_admin", "test", "c4po_local", "c4po_realm_local")
|
||||
}
|
||||
|
||||
private fun cleanUp() {
|
||||
mongoTemplate.findAllAndRemove(Query(), ProjectEntity::class.java)
|
||||
|
||||
tokenAdmin = "n/a"
|
||||
}
|
||||
}
|
|
@ -2,42 +2,35 @@ package com.securityc4po.api.project
|
|||
|
||||
import com.github.tomakehurst.wiremock.common.Json
|
||||
import com.securityc4po.api.BaseIntTest
|
||||
import com.securityc4po.api.configuration.NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
|
||||
import com.securityc4po.api.configuration.RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
|
||||
import com.securityc4po.api.configuration.SIC_INNER_SHOULD_BE_STATIC
|
||||
import com.securityc4po.api.configuration.URF_UNREAD_FIELD
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.web.server.LocalServerPort
|
||||
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
import org.springframework.data.mongodb.core.query.Query
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
import java.time.Duration
|
||||
|
||||
/*@TestPropertySource(
|
||||
properties = [
|
||||
"keycloak.client.url=http://localhost:${'$'}{wiremock.server.port}"
|
||||
]
|
||||
)*/
|
||||
@AutoConfigureWireMock(port = 0)
|
||||
@SuppressFBWarnings(
|
||||
SIC_INNER_SHOULD_BE_STATIC,
|
||||
URF_UNREAD_FIELD,
|
||||
"Unread field will become used after database implementation"
|
||||
NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR,
|
||||
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
|
||||
)
|
||||
class ProjectControllerIntTest : BaseIntTest() {
|
||||
|
||||
@LocalServerPort
|
||||
private var port = 0
|
||||
|
||||
// @Value("\${static-jwt.valid-token}")
|
||||
private var newToken: String = ""
|
||||
|
||||
@Autowired
|
||||
lateinit var mongoTemplate: MongoTemplate
|
||||
|
||||
@Autowired
|
||||
private lateinit var webTestClient: WebTestClient
|
||||
|
||||
@BeforeEach
|
||||
|
@ -50,21 +43,24 @@ class ProjectControllerIntTest : BaseIntTest() {
|
|||
|
||||
@BeforeEach
|
||||
fun init() {
|
||||
cleanUp()
|
||||
configureAdminToken()
|
||||
persistBasicTestScenario()
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun destroy() {
|
||||
cleanUp()
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class GetProjects {
|
||||
@Test
|
||||
fun `requesting projects successfully`() {
|
||||
println(newToken)
|
||||
webTestClient.get().uri("/v1/projects")
|
||||
.header("Authorization", "Bearer $newToken")
|
||||
webTestClient.get().uri("/projects")
|
||||
.header("Authorization", "Bearer $tokenAdmin")
|
||||
.exchange()
|
||||
.expectStatus().isOk
|
||||
.expectHeader().valueEquals("Application-Name", "security-c4po-api")
|
||||
.expectHeader().valueEquals("Application-Name", "SecurityC4PO")
|
||||
.expectBody().json(Json.write(getProjects()))
|
||||
}
|
||||
|
||||
|
@ -91,12 +87,6 @@ class ProjectControllerIntTest : BaseIntTest() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun cleanUp() {
|
||||
mongoTemplate.findAllAndRemove(Query(), Project::class.java)
|
||||
|
||||
token = "n/a"
|
||||
}
|
||||
|
||||
private fun persistBasicTestScenario() {
|
||||
// setup test data
|
||||
val projectOne = Project(
|
||||
|
@ -115,12 +105,18 @@ class ProjectControllerIntTest : BaseIntTest() {
|
|||
tester = "Elliot",
|
||||
createdBy = "f8aab31f-4925-4242-a6fa-f98135b4b032"
|
||||
)
|
||||
cleanUp()
|
||||
// persist test data in database
|
||||
mongoTemplate.save(ProjectEntity(projectOne))
|
||||
mongoTemplate.save(ProjectEntity(projectTwo))
|
||||
}
|
||||
|
||||
private fun configureAdminToken() {
|
||||
newToken = getAccessToken("test_admin", "test", "c4po_local", "c4po_realm_local")
|
||||
tokenAdmin = getAccessToken("test_admin", "test", "c4po_local", "c4po_realm_local")
|
||||
}
|
||||
|
||||
private fun cleanUp() {
|
||||
mongoTemplate.findAllAndRemove(Query(), ProjectEntity::class.java)
|
||||
|
||||
tokenAdmin = "n/a"
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzUzMDYxNzQsImlhdCI6MTYzNDMwNTg3NCwiYXV0aF90aW1lIjoxNjM0MzA1ODE0LCJqdGkiOiI2OTQ1MGJlYi03MzU2LTQ1ODUtYjg2My1hOTZmZjI3MzA2MWQiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODgvYXV0aC9yZWFsbXMvYzRwb19yZWFsbV9sb2NhbCIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiIxMGUwNmQ3YS04ZGQwLTRlY2QtODk2My0wNTZiNDUwNzljNGYiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJjNHBvX2xvY2FsIiwibm9uY2UiOiI3ZGI4YjJmOC03MTAyLTQxMTYtOWFhZC01YjgyZDA4OWJjN2IiLCJzZXNzaW9uX3N0YXRlIjoiODQ3ZGY4NmItZDI1MS00M2MzLWIxNzMtOGQ0ZjgxNzg0YmVkIiwiYWNyIjoiMCIsImFsbG93ZWQtb3JpZ2lucyI6WyIqIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJjNHBvX3VzZXIiLCJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYzRwb19sb2NhbCI6eyJyb2xlcyI6WyJ1c2VyIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJuYW1lIjoidGVzdCB1c2VyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidHR0IiwiZ2l2ZW5fbmFtZSI6InRlc3QiLCJmYW1pbHlfbmFtZSI6InVzZXIifQ.R1HeCozwPAlmck8zV1CF86vKVLwdyFcNuQZZ7eOXqxU
|
|
@ -1,28 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
cd keycloak/bin
|
||||
sleep 20
|
||||
./kcadm.sh config credentials --server http://localhost:8888/auth --realm master --user admin --password admin
|
||||
|
||||
USERID=$(./kcadm.sh create users -r c4po_realm_local -s username=test_admin \
|
||||
-s email=testadmin@test.de \
|
||||
-s firstName=test \
|
||||
-s lastName=admin \
|
||||
-s attributes.lang="de-DE" \
|
||||
-s attributes.datenumberformat="en-US" \
|
||||
-s enabled=true -o --fields id | jq '.id' | tr -d '"')
|
||||
|
||||
./kcadm.sh update users/$USERID/reset-password -r c4po_realm_test -s type=password -s value=test -s temporary=false -n
|
||||
./kcadm.sh add-roles --uusername test_admin --rolename c4po_admin -r c4po_realm_test
|
||||
./kcadm.sh add-roles -r c4po_realm_test --uusername test_admin --cclientid realm-management --rolename create-client --rolename view-users
|
||||
|
||||
USERID=$(./kcadm.sh create users -r c4po_realm_local -s username=test_user \
|
||||
-s email=testuser@test.de \
|
||||
-s firstName=test \
|
||||
-s lastName=user \
|
||||
-s attributes.lang="de-DE" \
|
||||
-s attributes.datenumberformat="en-US" \
|
||||
-s enabled=true -o --fields id | jq '.id' | tr -d '"')
|
||||
|
||||
./kcadm.sh update users/$USERID/reset-password -r c4po_realm_test -s type=password -s value=test -s temporary=false -n
|
||||
./kcadm.sh add-roles --uusername test_user --rolename c4po_user -r c4po_realm_test
|
||||
./kcadm.sh add-roles -r c4po_realm_test --uusername test_user --cclientid realm-management --rolename create-client --rolename view-users
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,8 @@ USERID=$(./kcadm.sh create users -r c4po_realm_local -s username=test_admin \
|
|||
-s lastName=admin \
|
||||
-s attributes.lang="de-DE" \
|
||||
-s attributes.datenumberformat="en-US" \
|
||||
-s enabled=true -o --fields id | jq '.id' | tr -d '"')
|
||||
-s enabled=true \
|
||||
-o --fields id | jq '.id' | tr -d '"')
|
||||
|
||||
./kcadm.sh update users/$USERID/reset-password -r c4po_realm_test -s type=password -s value=test -s temporary=false -n
|
||||
./kcadm.sh add-roles --uusername test_admin --rolename c4po_admin -r c4po_realm_test
|
||||
|
@ -21,7 +22,8 @@ USERID=$(./kcadm.sh create users -r c4po_realm_local -s username=test_user \
|
|||
-s lastName=user \
|
||||
-s attributes.lang="de-DE" \
|
||||
-s attributes.datenumberformat="en-US" \
|
||||
-s enabled=true -o --fields id | jq '.id' | tr -d '"')
|
||||
-s enabled=true \
|
||||
-o --fields id | jq '.id' | tr -d '"')
|
||||
|
||||
./kcadm.sh update users/$USERID/reset-password -r c4po_realm_test -s type=password -s value=test -s temporary=false -n
|
||||
./kcadm.sh add-roles --uusername test_user --rolename c4po_user -r c4po_realm_test
|
||||
|
|
Loading…
Reference in New Issue