Skip to content

Commit bb9685f

Browse files
akshaysonvaneMarkLogic Builder
authored andcommitted
DHFPROD-6962: Only enable hubDhs for aws/azure spring profile
1 parent a0f1216 commit bb9685f

File tree

10 files changed

+93
-71
lines changed

10 files changed

+93
-71
lines changed

Jenkinsfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def dhfCypressE2ETests(String mlVersion, String type){
5353
cd marklogic-data-hub-central/ui/e2e;
5454
chmod +x setup.sh;
5555
./setup.sh dhs=false mlHost=localhost;
56-
nohup java -jar $WORKSPACE/$WAR_NAME --hubUseLocalDefaults=true >> nohup.out &
56+
nohup java -jar $WORKSPACE/$WAR_NAME >> nohup.out &
5757
sleep 10s;
5858
mkdir -p output;
5959
docker build . -t cypresstest;
@@ -191,7 +191,6 @@ def runCypressE2e(){
191191
export JAVA_HOME=`eval echo "$JAVA_HOME_DIR"`;
192192
sudo mladmin install-hubcentral $WORKSPACE/*central*.rpm;
193193
sudo mladmin add-javahome-hubcentral $JAVA_HOME
194-
sudo mladmin add-hubcentral-property hubUseLocalDefaults=true
195194
sudo mladmin start-hubcentral
196195
''')
197196
sh(script:'''#!/bin/bash

marklogic-data-hub-central/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ bootWar {
5454
// To pass Gradle properties for HubCentral to Spring Boot, copy them into the JVM environment
5555
bootRun.doFirst {
5656
environment "mlHost", mlHost
57-
environment "hubUseLocalDefaults", hubUseLocalDefaults
58-
environment "hubSsl", hubSsl
5957
environment "spring.profiles.active", springProfiles
6058
}
6159

marklogic-data-hub-central/gradle.properties

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@ springSecurityVersion=5.3.8.RELEASE
1111
# Passed to bootRun as the value of spring.profiles.active
1212
# Defaults to "dev" since it's assumed that "./gradlew bootRun" is only used during development. For production, or any
1313
# non-development environment, it's assumed that bootWar is first used to construct the war file, which will default to
14-
# "production" as the profile, per the application.properties file.
14+
# "default" as the spring profile.
1515
springProfiles=dev
1616

1717
# For testing locally.
1818
# Each of these can be overridden via e.g. -PmlHost=somehost when running "./gradlew bootRun".
1919
# Can also override them via gradle-local.properties, which is a gitignored file.
2020
mlHost=localhost
21-
hubUseLocalDefaults=false
22-
23-
# This is being temporarily included so it's easy to turn SSL usage off, as it's not certain yet whether HC will need
24-
# SSL or not when talking to ML in a DHS environment.
25-
hubSsl=true

marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/HubCentral.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ public class HubCentral extends LoggingObject implements InitializingBean {
2424
@Value("${mlHost:localhost}")
2525
String host;
2626

27-
@Value("${hubUseLocalDefaults:false}")
28-
boolean useLocalDefaults;
29-
3027
/**
3128
* When the application starts up, initialize a project at the configured project path. This will go away before
3229
* 5.3.0, once Hub Central no longer depends on a HubProject. In the meantime, we need this as a bridge.
3330
*/
3431
@Override
3532
public void afterPropertiesSet() {
3633
logger.info("Will connect to MarkLogic host: " + host);
37-
38-
if (useLocalDefaults) {
39-
logger.info("Local defaults of digest authentication and no SSL will be used when connecting to MarkLogic");
40-
}
4134
logger.info("Hub Central is available at port: " + environment.getProperty("server.port"));
4235
}
4336

@@ -69,11 +62,6 @@ protected PropertySource buildPropertySource(String username, String password) {
6962
primaryProperties.setProperty("mlUsername", username);
7063
primaryProperties.setProperty("mlPassword", password);
7164

72-
if (useLocalDefaults) {
73-
primaryProperties.setProperty("hubDhs", "false");
74-
primaryProperties.setProperty("hubSsl", "false");
75-
}
76-
7765
return propertyName -> {
7866
String value = primaryProperties.getProperty(propertyName);
7967
if (value != null) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Data Hub connection properties. These default to the expected values for DHS on AWS.
2+
hubDhs=true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Data Hub connection properties. These default to the expected values for DHS on Azure.
2+
hubDhs=true

marklogic-data-hub-central/src/main/resources/application.properties

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Controls which Spring Profile values for enabled. This is a handy way to control which beans are active in a given
2-
# environment. See SwaggerConfig as an example.
3-
# This defaults to "production" to ensure that the "dev" profile is only used via an intentional decision.
4-
spring.profiles.active=production
5-
61
server.port=8080
72
spring.thymeleaf.prefix=classpath:/static/
83

@@ -12,11 +7,8 @@ spring.thymeleaf.prefix=classpath:/static/
127
server.tomcat.remote_ip_header=x-forwarded-for
138
server.tomcat.protocol_header=x-forwarded-proto
149

15-
# Data Hub connection properties. These default to the expected values for DHS. Both properties are defined in case HC
16-
# needs to run behind a load balancer at some point, in which case hubDhs=true and hubSsl=false would be used.
10+
# Data Hub connection properties. These default to the expected values for on-prem HC.
1711
mlHost=localhost
18-
hubDhs=true
19-
hubSsl=true
2012

2113
# No need for session persistence as we have no failover servers and we are using non-serializable objects in session scope
2214
server.servlet.session.persistent=false

marklogic-data-hub-central/src/test/java/com/marklogic/hub/central/HubCentralTest.java

Lines changed: 84 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import com.marklogic.hub.impl.HubConfigImpl;
66
import com.marklogic.mgmt.ManageConfig;
77
import com.marklogic.mgmt.util.PropertySource;
8-
import org.junit.jupiter.api.BeforeEach;
98
import org.junit.jupiter.api.Test;
109
import org.springframework.core.env.PropertiesPropertySource;
1110
import org.springframework.core.io.ClassPathResource;
1211
import org.springframework.mock.env.MockEnvironment;
1312

13+
import java.io.IOException;
1414
import java.util.Properties;
1515

1616
import static org.junit.jupiter.api.Assertions.*;
@@ -20,44 +20,68 @@ public class HubCentralTest {
2020
HubCentral hubCentral;
2121
MockEnvironment mockEnvironment;
2222

23-
@BeforeEach
24-
void beforeEach() throws Exception {
25-
Properties defaultProps = new Properties();
26-
defaultProps.load(new ClassPathResource("application.properties").getInputStream());
27-
mockEnvironment = new MockEnvironment();
28-
mockEnvironment.getPropertySources().addFirst(new PropertiesPropertySource("default", defaultProps));
29-
30-
hubCentral = new HubCentral();
31-
hubCentral.environment = mockEnvironment;
23+
@Test
24+
void testNewDefaultHubConfig() throws IOException {
25+
setupEnvironment("application.properties");
26+
verifyDefaultPropertiesForSslAndAuthentication();
27+
newDefaultHubConfig();
3228
}
3329

3430
@Test
35-
void verifyDefaultPropertiesForSslAndAuthentication() {
36-
PropertySource props = hubCentral.buildPropertySource("anyone", "anyword");
37-
assertEquals("anyone", props.getProperty("mlUsername"));
38-
assertEquals("anyword", props.getProperty("mlPassword"));
39-
assertEquals("localhost", props.getProperty("mlHost"),
40-
"For convenience while doing local development, mlHost still defaults to localhost");
41-
assertEquals("true", props.getProperty("hubDhs"));
42-
assertEquals("true", props.getProperty("hubSsl"));
31+
void testNewHubConfigForDhsOnAWS() throws IOException {
32+
setupEnvironment("application-aws.properties");
33+
verifyPropertiesForSslAndAuthenticationOnDhs();
34+
newHubConfigForDhs();
4335
}
4436

45-
/**
46-
* This is essentially tested via every HC test as well, which is using local defaults.
47-
*/
4837
@Test
49-
void verifyLocalDefaults() {
50-
hubCentral.useLocalDefaults = true;
51-
PropertySource props = hubCentral.buildPropertySource("anyone", "anyword");
52-
assertEquals("anyone", props.getProperty("mlUsername"));
53-
assertEquals("anyword", props.getProperty("mlPassword"));
54-
assertEquals("localhost", props.getProperty("mlHost"));
55-
assertEquals("false", props.getProperty("hubDhs"));
56-
assertEquals("false", props.getProperty("hubSsl"));
38+
void testNewHubConfigForDhsOnAzure() throws IOException {
39+
setupEnvironment("application-azure.properties");
40+
verifyPropertiesForSslAndAuthenticationOnDhs();
41+
newHubConfigForDhs();
5742
}
5843

59-
@Test
60-
void newHubConfig() {
44+
void newDefaultHubConfig() {
45+
Properties customProps = new Properties();
46+
customProps.setProperty("mlHost", "somehost");
47+
mockEnvironment.getPropertySources().addFirst(new PropertiesPropertySource("custom", customProps));
48+
49+
HubConfigImpl hubConfig = hubCentral.newHubConfig("anyone", "anyword");
50+
51+
assertEquals("somehost", hubConfig.getAppConfig().getHost());
52+
assertEquals((Integer) 8000, hubConfig.getAppConfig().getAppServicesPort());
53+
assertEquals("anyone", hubConfig.getAppConfig().getAppServicesUsername(),
54+
"The Versions class used appConfig.getAppServicesDatabaseClient to get the ML version");
55+
assertEquals("anyword", hubConfig.getAppConfig().getAppServicesPassword());
56+
assertEquals(SecurityContextType.DIGEST, hubConfig.getAppConfig().getAppServicesSecurityContextType());
57+
assertNull(hubConfig.getAppConfig().getAppServicesSslContext());
58+
59+
assertEquals("somehost", hubConfig.getHost());
60+
assertEquals("anyone", hubConfig.getMlUsername());
61+
assertEquals("anyword", hubConfig.getMlPassword());
62+
63+
assertEquals("digest", hubConfig.getAuthMethod(DatabaseKind.STAGING));
64+
assertEquals("digest", hubConfig.getAuthMethod(DatabaseKind.FINAL));
65+
assertEquals("digest", hubConfig.getAuthMethod(DatabaseKind.JOB));
66+
67+
assertNull(hubConfig.getSslContext(DatabaseKind.STAGING));
68+
assertNull(hubConfig.getSslContext(DatabaseKind.FINAL));
69+
assertNull(hubConfig.getSslContext(DatabaseKind.JOB));
70+
71+
assertFalse(hubConfig.getIsHostLoadBalancer());
72+
assertFalse(hubConfig.getIsProvisionedEnvironment());
73+
74+
ManageConfig manageConfig = hubConfig.getManageConfig();
75+
assertEquals("anyone", manageConfig.getUsername());
76+
assertEquals("anyone", manageConfig.getSecurityUsername());
77+
assertEquals("somehost", manageConfig.getHost());
78+
assertEquals("anyword", manageConfig.getPassword());
79+
assertEquals("anyword", manageConfig.getSecurityPassword());
80+
assertFalse(manageConfig.isConfigureSimpleSsl());
81+
assertEquals("http", manageConfig.getScheme());
82+
}
83+
84+
void newHubConfigForDhs() {
6185
Properties customProps = new Properties();
6286
customProps.setProperty("mlHost", "somehost");
6387
mockEnvironment.getPropertySources().addFirst(new PropertiesPropertySource("custom", customProps));
@@ -66,9 +90,9 @@ void newHubConfig() {
6690

6791
assertEquals("somehost", hubConfig.getAppConfig().getHost());
6892
assertEquals((Integer) 8010, hubConfig.getAppConfig().getAppServicesPort(),
69-
"8010 is needed by DHS, as 8000 is locked down; this should be defined in application.properties");
93+
"8010 is needed by DHS, as 8000 is locked down; this should be defined in application.properties");
7094
assertEquals("anyone", hubConfig.getAppConfig().getAppServicesUsername(),
71-
"The Versions class used appConfig.getAppServicesDatabaseClient to get the ML version");
95+
"The Versions class used appConfig.getAppServicesDatabaseClient to get the ML version");
7296
assertEquals("anyword", hubConfig.getAppConfig().getAppServicesPassword());
7397
assertEquals(SecurityContextType.BASIC, hubConfig.getAppConfig().getAppServicesSecurityContextType());
7498
assertNotNull(hubConfig.getAppConfig().getAppServicesSslContext());
@@ -97,4 +121,31 @@ void newHubConfig() {
97121
assertTrue(manageConfig.isConfigureSimpleSsl());
98122
assertEquals("https", manageConfig.getScheme());
99123
}
124+
125+
void verifyDefaultPropertiesForSslAndAuthentication() {
126+
PropertySource props = hubCentral.buildPropertySource("anyone", "anyword");
127+
assertEquals("anyone", props.getProperty("mlUsername"));
128+
assertEquals("anyword", props.getProperty("mlPassword"));
129+
assertEquals("localhost", props.getProperty("mlHost"),
130+
"For convenience while doing local development, mlHost still defaults to localhost");
131+
assertNull(props.getProperty("hubDhs"));
132+
assertNull(props.getProperty("hubSsl"));
133+
}
134+
135+
void verifyPropertiesForSslAndAuthenticationOnDhs() {
136+
PropertySource props = hubCentral.buildPropertySource("anyone", "anyword");
137+
assertEquals("anyone", props.getProperty("mlUsername"));
138+
assertEquals("anyword", props.getProperty("mlPassword"));
139+
assertEquals("true", props.getProperty("hubDhs"));
140+
}
141+
142+
private void setupEnvironment(String propertyFileName) throws IOException {
143+
Properties defaultProps = new Properties();
144+
defaultProps.load(new ClassPathResource(propertyFileName).getInputStream());
145+
mockEnvironment = new MockEnvironment();
146+
mockEnvironment.getPropertySources().addFirst(new PropertiesPropertySource("default", defaultProps));
147+
148+
hubCentral = new HubCentral();
149+
hubCentral.environment = mockEnvironment;
150+
}
100151
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
# Define any properties in here that are likely to change between environments where tests are run.
22
# The TestConfig class should then be used to access these properties.
3-
4-
# It's assumed that when running tests, it'll be against a non-DHS ML instance, and thus digest auth should be used
5-
# with no SSL.
6-
7-
hubUseLocalDefaults=true

marklogic-data-hub-central/ui/e2e/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Boot up HC application from `marklogic-data-hub-central` directory either via bo
2020
* java -jar </path/to/HC.war> --mlHost=<curationEndpoint> --spring.profiles.active=dev
2121
2222
For local -
23-
* ./gradlew bootRun -PhubUseLocalDefaults=true
24-
* java -jar </path/to/HC.war> --hubUseLocalDefaults=true --spring.profiles.active=dev
23+
* ./gradlew bootRun
24+
* java -jar </path/to/HC.war> --spring.profiles.active=dev
2525

2626

2727
Then run the Cypress tests. Use appropriate run scripts defined in package.json to run on different browsers:

0 commit comments

Comments
 (0)