Skip to content
Snippets Groups Projects
Commit 1b17297c authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

Merge branch 'tests' into 'master'

Tests



See merge request !16
parents d1f5bca4 62ceae14
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
This is the MIP backend.
## Usage
## Usage in development environment
* Build and run the project (including clean target): `./go.sh`
* Build the project (including clean target): `./build.sh`
......@@ -11,6 +11,15 @@ This is the MIP backend.
* Stop and remove the running container: `./halt.sh`
* Clean Maven cache, etc: `./clean.sh`
## Usage for deployments
* Build a versioned image: `./captain_build.sh` or `captain build`
* Build and test an image: `./captain_test.sh` or `captain test`
## Deployment
* See here: https://hub.docker.com/r/hbpmip/portal-backend/
## Generate PDF API documentation on build
Uncomment the following line in src/docker/build/build-in-docker.sh :
......
......@@ -7,7 +7,7 @@ portal-backend-build:
- docker run --rm -v $(pwd):/opt/portal/ -v $(pwd)/.m2:/root/.m2/ hbpmip/portal-backend-build
- echo 'Finished building portal-backend-build'
test:
- tests.sh
- ./tests/test-build.sh
portal-backend:
build: ./src/docker/run/Dockerfile
......@@ -21,4 +21,6 @@ portal-backend:
- rm -rf $(pwd)/src/docker/run/config/
- echo 'Finished building portal-backend'
test:
- tests.sh
\ No newline at end of file
- ./tests/pre-test-run.sh
- ./tests/test-run.sh
- ./tests/post-test-run.sh
\ No newline at end of file
#!/usr/bin/env bash
captain build
#!/usr/bin/env bash
captain test
\ No newline at end of file
......@@ -48,3 +48,6 @@ workflow:
frontend:
redirect:
url: {{ .Env.FRONTEND_REDIRECT_URL }}
authentication:
enabled: {{ .Env.AUTHENTICATION }}
......@@ -48,3 +48,6 @@ workflow:
frontend:
redirect:
url: http://frontend/home
authentication:
enabled: 0
......@@ -32,6 +32,7 @@ services:
ML_URL: http://172.22.0.1:8087/mining
EXAREME_URL: http://hbps2.chuv.ch:9090/mining/query
FRONTEND_REDIRECT_URL: http://frontend/home
AUTHENTICATION: 0
portal-db:
container_name: portal-db
......
......@@ -82,20 +82,32 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Value("#{'${frontend.redirect.url:http://frontend/home}'}")
String frontendRedirect;
@Value("#{'${authentication.enabled:1}'}")
boolean authentication;
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.addFilterBefore(new CORSFilter(), ChannelProcessingFilter.class);
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/frontend/**", "/webjars/**", "/v2/api-docs").permitAll()
.anyRequest().authenticated()
.and().exceptionHandling().authenticationEntryPoint(new CustomLoginUrlAuthenticationEntryPoint(loginUrl))
.and().logout().logoutSuccessUrl(loginUrl).permitAll()
.and().logout().logoutUrl(logoutUrl).permitAll()
.and().csrf().ignoringAntMatchers(logoutUrl).csrfTokenRepository(csrfTokenRepository())
.and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
if(authentication) {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/frontend/**", "/webjars/**", "/v2/api-docs").permitAll()
.anyRequest().authenticated()
.and().exceptionHandling().authenticationEntryPoint(new CustomLoginUrlAuthenticationEntryPoint(loginUrl))
.and().logout().logoutSuccessUrl(loginUrl).permitAll()
.and().logout().logoutUrl(logoutUrl).permitAll()
.and().csrf().ignoringAntMatchers(logoutUrl).csrfTokenRepository(csrfTokenRepository())
.and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
}
else {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/**").permitAll();
getUser();
}
}
private Filter ssoFilter() {
......@@ -173,11 +185,18 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
* @return
*/
public synchronized User getUser() {
User user = new User(getUserInfos());
User foundUser = userRepository.findOne(user.getUsername());
if(foundUser != null)
User user;
if(!authentication)
{
user.setAgreeNDA(foundUser.getAgreeNDA());
user = new User();
user.setUsername("TestUser");
}
else {
user = new User(getUserInfos());
User foundUser = userRepository.findOne(user.getUsername());
if (foundUser != null) {
user.setAgreeNDA(foundUser.getAgreeNDA());
}
}
userRepository.save(user);
return user;
......
#!/usr/bin/env bash
docker kill portal-db-test
docker rm -f portal-db-test
docker kill portal-backend-test
docker rm -f portal-backend-test
#!/usr/bin/env bash
if [ $(docker ps | grep portal-db-test | wc -l) -gt 0 ]; then
docker kill portal-db-test
fi
if [ $(docker ps -a | grep portal-db-test | wc -l) -gt 0 ]; then
docker rm -f portal-db-test
fi
if [ $(docker ps | grep portal-backend-test | wc -l) -gt 0 ]; then
docker kill portal-backend-test
fi
if [ $(docker ps -a | grep portal-backend-test | wc -l) -gt 0 ]; then
docker rm -f portal-backend-test
fi
docker run --name portal-db-test -e POSTGRES_USER=postgres -d postgres
docker run --name portal-backend-test -p 8000:8000 \
-e "DB_URL=jdbc:postgresql://172.22.0.1:5432/postgres" \
-e "DB_USER=postgres" \
-e "CONTEXT_PATH=/services" \
-e "PORT=8080" \
-d hbpmip/portal-backend
#!/usr/bin/env bash
if [ ! -f ./target/backend-services-DOCKER_BUILD.jar ]; then
exit 1
fi
exit 0
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment