Skip to content

Commit

Permalink
Merge pull request #62 from italiangrid/VOMS-883
Browse files Browse the repository at this point in the history
Fix hr.properties parsing
  • Loading branch information
andreaceccanti authored Mar 22, 2021
2 parents 884e70a + 5fa1ad5 commit 7260586
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public static final HrDbProperties fromProperties(Properties properties) {
}

if (properties.containsKey(MEMBERSHIP_CHECK_ENABLED_KEY)) {
config.getMembershipCheck().setEnabled(Boolean.parseBoolean(MEMBERSHIP_CHECK_ENABLED_KEY));
config.getMembershipCheck()
.setEnabled(Boolean.parseBoolean(properties.getProperty(MEMBERSHIP_CHECK_ENABLED_KEY)));
}

config.getApi().setEndpoint(properties.getProperty(API_ENDPOINT_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,37 @@ public void setup() {
configurator.setUserDao(dao);
configurator.setClock(CLOCK);

when(vomsConfig.getConfigurationDirectoryPath()).thenReturn("src/test/resources/cern/config");
when(vomsConfig.getExternalValidatorProperty(eq("orgdb"), anyString(), anyString()))
.thenReturn("src/test/resources/cern/config/orgdb.properties");
when(vomsConfig.getConfigurationDirectoryPath())
.thenReturn("src/test/resources/cern/disabled-task");
when(vomsConfig.getExternalValidatorProperty(eq("orgdb"), eq("configFile"), anyString()))
.thenReturn("src/test/resources/cern/disabled-task/hr.properties");
when(apiFactory.newHrDbApiService(any())).thenReturn(api);
when(validatorFactory.newHrDbRequestValidator(any(), any())).thenReturn(validator);
when(syncTaskFactory.buildSyncTask(any(), any(), any(), any())).thenReturn(syncTask);
}

@Test
public void testConfigurationFileIsFoundAndParsed() throws VOMSPluginConfigurationException {
public void testDisabledConfigurationFileIsFoundAndParsed()
throws VOMSPluginConfigurationException {
configurator.configure();
verifyZeroInteractions(executorService);// no interactions as periodic sync is disabled
verifyZeroInteractions(syncTaskFactory);// no interactions as periodic sync is disabled
verify(manager).setRequestValidationContext(Mockito.eq(validator));
}

@Test
public void testEnabledConfigurationFileIsFoundAndParsed()
throws VOMSPluginConfigurationException {
when(vomsConfig.getConfigurationDirectoryPath())
.thenReturn("src/test/resources/cern/enabled-task");
when(vomsConfig.getExternalValidatorProperty(eq("orgdb"), eq("configFile"), anyString()))
.thenReturn("src/test/resources/cern/enabled-task/hr.properties");
configurator.configure();
verifyZeroInteractions(executorService);
verifyZeroInteractions(syncTaskFactory);

verify(executorService).scheduleAtFixedRate(isA(DatabaseTransactionTaskWrapper.class),
Mockito.anyLong(), Mockito.eq(TimeUnit.HOURS.toSeconds(12)),
Mockito.eq(TimeUnit.SECONDS));

verify(manager).setRequestValidationContext(Mockito.eq(validator));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.glite.security.voms.admin.integration.cern.HrDbError;
Expand Down Expand Up @@ -71,6 +75,29 @@ public void testValueParsing() {
assertThat(hrConfig.getMembershipCheck().getPeriodInSeconds(), is(86400L));
}


@Test
public void testFileParsing() throws FileNotFoundException, IOException {

Properties props = new Properties();
props
.load(new FileInputStream(new File("src/test/resources/cern/enabled-task/hr.properties")));

HrDbProperties hrDbProps = HrDbProperties.fromProperties(props);

assertThat(hrDbProps.getExperimentName(), is("cms"));
assertThat(hrDbProps.getMembershipCheck().isEnabled(), is(true));
assertThat(hrDbProps.getMembershipCheck().getStartHour(), is(4));
assertThat(hrDbProps.getMembershipCheck().isRunAtStartup(), is(false));
assertThat(hrDbProps.getApi().getEndpoint(), is("http://localhost:8080"));
assertThat(hrDbProps.getApi().getUsername(), is("user"));
assertThat(hrDbProps.getApi().getPassword(), is("password"));
assertThat(hrDbProps.getApi().getTimeoutInSeconds(), is(2L));



}

@Test
public void testApiTimeoutChecks() {
Properties props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
experiment=cms
membership_check.enabled=true
membership_check.start_hour=4
membership_check.run_at_startup=false
api.endpoint=http://localhost:8080
api.username=user
api.password=password
api.timeout_secs=2

0 comments on commit 7260586

Please sign in to comment.