Skip to content

Commit

Permalink
Merge pull request #351 from reliatec-gmbh/lc-develop
Browse files Browse the repository at this point in the history
Merge changes just before release
  • Loading branch information
oba-reliatec authored Aug 17, 2022
2 parents 909c672 + 5993bae commit 277fe59
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
7 changes: 7 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<!-- LOGBACK needs Janino when conditional statements are used (e.g. in logback.xml) -->
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
Expand Down Expand Up @@ -265,6 +270,8 @@
<ignoredUnusedDeclaredDependencies>
<!-- Needed by LibreClinica-web when HttpComponentsClientHttpRequestFactory is used-->
<ignoredUnusedDeclaredDependency>org.apache.httpcomponents:httpclient</ignoredUnusedDeclaredDependency>
<!-- Needed by LOGBACK when conditional statements are used (e.g. in logback.xml) -->
<ignoredUnusedDeclaredDependency>org.codehaus.janino</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.google.common.base.Splitter.fixedLength;
import static dev.samstevens.totp.code.HashingAlgorithm.SHA1;
import static java.lang.Enum.valueOf;
import static java.lang.String.format;
import static java.time.LocalDate.now;
import static java.time.LocalDate.parse;
import static org.akaza.openclinica.domain.admin.TwoFactorType.APPLICATION;
Expand Down Expand Up @@ -43,6 +44,7 @@
public class TwoFactorService {
private static final String FAR_FUTURE_ACTIVATION_DUE_DATE_AS_FALLBACK = "2050-01-01";
private static final String FALSE_STRING = "false";
private static final String SYS_URL = "sysURL";
@VisibleForTesting
static final String TWO_FACTOR_ACTIVATED_VERIFICATION_TYPE = "2fa.type";
@VisibleForTesting
Expand Down Expand Up @@ -228,11 +230,16 @@ String extractedVerificationTypeSetting() {
return coreResources.getDATAINFO().getProperty(TWO_FACTOR_ACTIVATED_VERIFICATION_TYPE, APPLICATION.name());
}

@VisibleForTesting
String extractSystemInfo(String systemSettings) {
return systemSettings.replaceAll("http(|s)://|/MainMenu", "");
}

private byte[] generateImageData(String secret) throws QrGenerationException {
// @formatter:off
QrData data = new QrData.Builder().
issuer("LibreClinica").
label("LibreClinica").
label(format("LibreClinica (%1$s)", extractSystemInfo(coreResources.getDATAINFO().getProperty(SYS_URL)))).
algorithm(SHA1).
secret(secret).
digits(6).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public class TwoFactorServiceTest {
@Mock
private CoreResources coreResources;
private String settingDueDateString;
private TwoFactorService service;
private Properties properties;

Expand All @@ -42,11 +41,6 @@ public void setUp() throws Exception {
String extractedVerificationTypeSetting() {
return LETTER.name();
}

@Override
String extractedDueDateSetting() {
return settingDueDateString;
}
};
service.coreResources = coreResources;

Expand All @@ -56,21 +50,21 @@ String extractedDueDateSetting() {

@Test
public void testIsTwoFactorOutdated_CurrentDate() {
settingDueDateString = LocalDate.now().format(ISO_DATE);
properties.put(TWO_FACTOR_ACTIVATION_DUE_DATE, LocalDate.now().format(ISO_DATE));

assertThat(service.isTwoFactorOutdated(), is(false));
}

@Test
public void testIsTwoFactorOutdated_FutureDate() {
settingDueDateString = LocalDate.now().plus(1, DAYS).format(ISO_DATE);
properties.put(TWO_FACTOR_ACTIVATION_DUE_DATE, LocalDate.now().plus(1, DAYS).format(ISO_DATE));

assertThat(service.isTwoFactorOutdated(), is(false));
}

@Test
public void testIsTwoFactorOutdated_Yesterday() {
settingDueDateString = LocalDate.now().minus(1, DAYS).format(ISO_DATE);
properties.put(TWO_FACTOR_ACTIVATION_DUE_DATE, LocalDate.now().minus(1, DAYS).format(ISO_DATE));

assertThat(service.isTwoFactorOutdated(), is(true));
}
Expand Down Expand Up @@ -118,33 +112,43 @@ public void testIsTwoFactorActivatedLetterAndOutDated_NoDueDateProvided() {

@Test
public void testIsTwoFactorActivatedLetterAndOutDated_OutdatedDueDateProvided() {
properties.put(TwoFactorService.TWO_FACTOR_ACTIVATED_VERIFICATION_TYPE, "letter");
properties.put(TwoFactorService.TWO_FACTOR_ACTIVATED_VERIFICATION_TYPE, "LETTER");
properties.put(TWO_FACTOR_ACTIVATED_SETTING, "true");
properties.put(TWO_FACTOR_ACTIVATION_DUE_DATE, "2020-01-01");

boolean outdated = service.isTwoFactorActivatedLetterAndOutDated();

assertThat("test", outdated, is(Boolean.TRUE));
assertThat(service.isTwoFactorActivatedLetterAndOutDated(), is(TRUE));
}

@Test
public void testIsTwoFactorOutdated_EmptySettingString() {
settingDueDateString = "";
properties.put(TWO_FACTOR_ACTIVATION_DUE_DATE, "");

assertThat(service.isTwoFactorOutdated(), is(false));
}

@Test
public void testIsTwoFactorOutdated_NullSettingString() {
settingDueDateString = null;

assertThat(service.isTwoFactorOutdated(), is(false));
}

@Test
public void testIsTwoFactorOutdated_InValidSettingWrongFormat() {
settingDueDateString = "01.01.2000";
properties.put(TWO_FACTOR_ACTIVATION_DUE_DATE, "01.01.2000");

assertThat(service.isTwoFactorOutdated(), is(false));
}

@Test
public void testExtractSystemInfo_UsingHttp() {
String systemSetting = "http://some-system.elsewhere.com:8080/HolyStudy/MainMenu";

assertThat(service.extractSystemInfo(systemSetting), is("some-system.elsewhere.com:8080/HolyStudy"));
}

@Test
public void testExtractSystemInfo_UsingHttps() {
String systemSetting = "https://some-system.elsewhere.com:8080/HolyStudy/MainMenu";

assertThat(service.extractSystemInfo(systemSetting), is("some-system.elsewhere.com:8080/HolyStudy"));
}
}
2 changes: 1 addition & 1 deletion docs/tests/t001.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ This test focuses on checking that a login is no longer possible after the due d

**prerequisites:**
- The system wide setting for 2-FA(2-Factor Authentication) usage has to be activated.
- The system wide setting for 2-FA type is set to 'APPLICATION' or 'LETTER'.
- The system wide setting for 2-FA type is set to 'LETTER'.
- The authentication type **Marked for 2-Factor Authentication** is set within the user's profile.
- The due to for 2-FA activation has been exceeded.

Expand Down
2 changes: 1 addition & 1 deletion docs/tests/t003.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ This test focuses on availability of 2-factor (type application) authentication
**expected results:**
1. The **Authentication Type** radio group is visible and the **Standard** option is checked by default.
1. When the **2-Factor Authentication** option is selected the **QR-Code** button is getting visible.
1. When the **QR-Code** button is getting clicked a QR-code is getting displayed and displayed.
1. When the **QR-Code** button is getting clicked a QR-code is getting displayed.
1. The **Confirm User Profile Updates** page displays the new authentication type **2-Factor Authentication**.
1. The **Alerts & Messages** panel (on the left) displays **Your profile has been updated successfully.**.
1. When accessing the user's profile again the option **2-Factor Authentication** option is checked.
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- LOGBACK needs Janino when conditional statements are used (e.g. in logback.xml) -->
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand Down Expand Up @@ -679,7 +685,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
</dependency>
<!--
<dependency>
Expand Down

0 comments on commit 277fe59

Please sign in to comment.