Skip to content
Snippets Groups Projects
Commit 4b4d396f authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4321 OZG-5039 extend environment

parent ce50b034
No related branches found
No related tags found
No related merge requests found
......@@ -8,4 +8,7 @@ import lombok.Getter;
public class FrontendEnvironment {
private boolean production;
private String remoteHost;
private String authServer;
private String clientId;
private String realm;
}
......@@ -18,11 +18,16 @@ public class FrontendEnvironmentController {
private final ProductionProperties environmentProperties;
private final OAuth2Properties oAuthProperties;
@GetMapping
public FrontendEnvironment getEnvironment() {
return FrontendEnvironment.builder()
.production(environmentProperties.isProduction())
.remoteHost(linkTo(RootController.class).toUri().toString())
.authServer(oAuthProperties.getAuthServerUrl())
.realm(oAuthProperties.getRealm())
.clientId(oAuthProperties.getResource())
.build();
}
}
package de.ozgcloud.admin.environment;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = OAuth2Properties.PREFIX)
public class OAuth2Properties {
static final String PREFIX = "ozgcloud.oauth2";
/**
* OAuth2 auth server url
*/
private String authServerUrl;
/**
* OAuth2 realm
*/
private String realm;
/**
* OAuth2 resource
*/
private String resource;
}
\ No newline at end of file
ozgcloud:
oauth2:
auth-server-url: https://sso.dev.by.ozg-cloud.de
realm: by-kiel-dev
resource: admin
......@@ -30,6 +30,8 @@ class FrontendEnvironmentControllerTest {
@Mock
private ProductionProperties environmentProperties;
@Mock
private OAuth2Properties oAuth2Properties;
private MockMvc mockMvc;
......@@ -83,6 +85,39 @@ class FrontendEnvironmentControllerTest {
response.andExpect(jsonPath("$.remoteHost").value("http://localhost" + RootController.PATH));
}
@SneakyThrows
@Test
void shouldContainAuthServerUrl() {
var oAuthServerUrl = "dummyOAuthUrl";
when(oAuth2Properties.getAuthServerUrl()).thenReturn(oAuthServerUrl);
var response = doRequest();
response.andExpect(jsonPath("$.authServer").value(oAuthServerUrl));
}
@SneakyThrows
@Test
void shouldContainRealm() {
var realm = "dummyRealm";
when(oAuth2Properties.getRealm()).thenReturn(realm);
var response = doRequest();
response.andExpect(jsonPath("$.realm").value(realm));
}
@SneakyThrows
@Test
void shouldContainClientId() {
var clientId = "dummdyClientId";
when(oAuth2Properties.getResource()).thenReturn(clientId);
var response = doRequest();
response.andExpect(jsonPath("$.clientId").value(clientId));
}
@SneakyThrows
private ResultActions doRequest() {
return mockMvc.perform(get(FrontendEnvironmentController.PATH));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment