BryanMLima commented on code in PR #6924:
URL: https://github.com/apache/cloudstack/pull/6924#discussion_r1101416929
##########
server/src/main/java/com/cloud/api/ApiServlet.java:
##########
@@ -293,17 +299,27 @@ void processRequestInContext(final HttpServletRequest
req, final HttpServletResp
// Initialize an empty context and we will update it after we have
verified the request below,
// we no longer rely on web-session here, verifyRequest will
populate user/account information
// if a API key exists
- Long userId = null;
if (isNew && s_logger.isTraceEnabled()) {
s_logger.trace(String.format("new session: %s", session));
}
+
+ if (!isNew &&
(command.equalsIgnoreCase(ValidateUserTwoFactorAuthenticationCodeCmd.APINAME)
|| (!skip2FAcheckForAPIs(command) && !skip2FAcheckForUser(session)))) {
Review Comment:
~~~
!isNew &&
(command.equalsIgnoreCase(ValidateUserTwoFactorAuthenticationCodeCmd.APINAME)
|| (!skip2FAcheckForAPIs(command) && !skip2FAcheckForUser(session)))
~~~
Could be a method called `shouldCheck2faPermission` or something like that.
It would improve code legibility.
##########
server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java:
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.api.auth;
+
+import com.cloud.user.AccountManager;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiCommandResourceType;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.UserResponse;
+import
org.apache.cloudstack.api.response.UserTwoFactorAuthenticationSetupResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+@APICommand(name = SetupUserTwoFactorAuthenticationCmd.APINAME, description =
"Setup the 2fa for the user.", authorized = {RoleType.Admin,
RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User},
requestHasSensitiveInfo = false,
+ responseObject = UserTwoFactorAuthenticationSetupResponse.class,
entityType = {}, since = "4.18.0")
+public class SetupUserTwoFactorAuthenticationCmd extends BaseCmd {
+
+ public static final String APINAME = "setupUserTwoFactorAuthentication";
+ public static final Logger s_logger =
Logger.getLogger(SetupUserTwoFactorAuthenticationCmd.class.getName());
+
+ @Inject
+ private AccountManager accountManager;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING,
description = "two factor authentication code")
Review Comment:
```suggestion
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING,
description = "Two factor authentication provider")
```
Should it not be the provider here?
##########
test/integration/smoke/test_2fa.py:
##########
@@ -0,0 +1,294 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+""" P1 tests for Account
+"""
+# Import Local Modules
+from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.lib.utils import (random_gen,
+ cleanup_resources,
+ validateList)
+from marvin.cloudstackAPI import *
+from marvin.lib.base import (Domain,
+ Account,
+ ServiceOffering,
+ VirtualMachine,
+ Network,
+ User,
+ Template,
+ Role)
+from marvin.lib.common import (get_domain,
+ get_zone,
+ get_test_template,
+ list_accounts,
+ list_virtual_machines,
+ list_service_offering,
+ list_templates,
+ list_users,
+ wait_for_cleanup)
+from nose.plugins.attrib import attr
+from marvin.cloudstackException import CloudstackAPIException
+from marvin.codes import PASS
+import time
+
+from pyVmomi.VmomiSupport import GetVersionFromVersionUri
+
+class Services:
+
+ """Test Account Services
+ """
+
+ def __init__(self):
+ self.services = {
+ "domain": {
+ "name": "Domain",
+ },
+ "account": {
+ "email": "[email protected]",
+ "firstname": "Test",
+ "lastname": "User",
+ "username": "test",
+ # Random characters are appended for unique
+ # username
+ "password": "fr3sca",
+ },
+ "role": {
+ "name": "User Role",
+ "type": "User",
+ "description": "User Role created by Marvin test"
+ },
+ "user": {
+ "email": "[email protected]",
+ "firstname": "User",
+ "lastname": "User",
+ "username": "User",
+ # Random characters are appended for unique
+ # username
+ "password": "fr3sca",
+ },
+ "service_offering": {
+ "name": "Tiny Instance",
+ "displaytext": "Tiny Instance",
+ "cpunumber": 1,
+ "cpuspeed": 100,
+ # in MHz
+ "memory": 128,
+ # In MBs
+ },
+ "virtual_machine": {
+ "displayname": "Test VM",
+ "username": "root",
+ "password": "password",
+ "ssh_port": 22,
+ "hypervisor": 'XenServer',
+ # Hypervisor type should be same as
+ # hypervisor type of cluster
+ "privateport": 22,
+ "publicport": 22,
+ "protocol": 'TCP',
+ },
+ "template": {
+ "displaytext": "Public Template",
+ "name": "Public template",
+ "ostype": 'CentOS 5.6 (64-bit)',
+ "url": "",
+ "hypervisor": '',
+ "format": '',
+ "isfeatured": True,
+ "ispublic": True,
+ "isextractable": True,
+ "templatefilter": "self"
+ },
+ "ostype": 'CentOS 5.6 (64-bit)',
+ "sleep": 60,
+ "timeout": 10,
+ }
+
+class TestUserLogin(cloudstackTestCase):
Review Comment:
Could change this to 2FA, as this is the same name as the `test_accounts.py`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]