Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/main/java/com/cloud/api/ApiServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ protected boolean skip2FAcheckForAPIs(String command) {
protected boolean skip2FAcheckForUser(HttpSession session) {
boolean skip2FAcheck = false;
Long userId = (Long) session.getAttribute("userid");
boolean is2FAverified = (boolean) session.getAttribute(ApiConstants.IS_2FA_VERIFIED);
boolean is2FAverified = Boolean.TRUE.equals(session.getAttribute(ApiConstants.IS_2FA_VERIFIED));
if (is2FAverified) {
LOGGER.debug(String.format("Two factor authentication is already verified for the user %d, so skipping", userId));
skip2FAcheck = true;
Expand Down
17 changes: 17 additions & 0 deletions server/src/test/java/com/cloud/api/ApiServletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,23 @@
Assert.assertEquals(true, result);
}

@Test
public void testSkip2FAcheckForUserWhenVerifiedAttributeIsAbsent() {
servlet.accountMgr = accountMgr;
Mockito.when(session.getAttribute("userid")).thenReturn(1L);

Check warning on line 339 in server/src/test/java/com/cloud/api/ApiServletTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ_6-d1yyvrdxWit8HOk&open=AZ_6-d1yyvrdxWit8HOk&pullRequest=13871
Mockito.when(session.getAttribute(ApiConstants.IS_2FA_VERIFIED)).thenReturn(null);

Check warning on line 340 in server/src/test/java/com/cloud/api/ApiServletTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ_6-d1yyvrdxWit8HOl&open=AZ_6-d1yyvrdxWit8HOl&pullRequest=13871
Mockito.when(accountMgr.getUserAccountById(1L)).thenReturn(userAccount);

Check warning on line 341 in server/src/test/java/com/cloud/api/ApiServletTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ_6-d1yyvrdxWit8HOm&open=AZ_6-d1yyvrdxWit8HOm&pullRequest=13871
Mockito.when(userAccount.getDomainId()).thenReturn(1L);

Check warning on line 342 in server/src/test/java/com/cloud/api/ApiServletTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ_6-d1yyvrdxWit8HOn&open=AZ_6-d1yyvrdxWit8HOn&pullRequest=13871
Mockito.when(userAccount.isUser2faEnabled()).thenReturn(false);

Check warning on line 343 in server/src/test/java/com/cloud/api/ApiServletTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ_6-d1yyvrdxWit8HOo&open=AZ_6-d1yyvrdxWit8HOo&pullRequest=13871

ConfigKey<Boolean> enableUserTwoFactorAuthentication = Mockito.mock(ConfigKey.class);

Check warning on line 345 in server/src/test/java/com/cloud/api/ApiServletTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "mock".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ_6-d1yyvrdxWit8HOp&open=AZ_6-d1yyvrdxWit8HOp&pullRequest=13871
AccountManagerImpl.enableUserTwoFactorAuthentication = enableUserTwoFactorAuthentication;
Mockito.when(enableUserTwoFactorAuthentication.valueIn(1L)).thenReturn(false);

Check warning on line 347 in server/src/test/java/com/cloud/api/ApiServletTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "when".

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AZ_6-d1yyvrdxWit8HOq&open=AZ_6-d1yyvrdxWit8HOq&pullRequest=13871

boolean result = servlet.skip2FAcheckForUser(session);
Assert.assertEquals(true, result);
}

@Test
public void testDoNotSkip2FAcheckForUserWhen2FAEnabled() {
servlet.accountMgr = accountMgr;
Expand Down
Loading