예제 #1
0
    def test_create_notifyslack_handler_error_json_data(self):
        test_user = user_id.format(str(3))
        path_parameters = {"organization_id": organization_id}

        # body_request is not json format
        body_request = ''
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user,
            body=json.dumps(body_request))

        response = notifymail.create_notifyslack_handler(event_mock, {})
        # Check data
        message_202 = MsgConst.ERR_REQUEST_202
        response_body = json.loads(response['body'])
        self.assertEqual(response['statusCode'], HTTPStatus.BAD_REQUEST)
        self.assertEqual(response_body['code'], message_202['code'])
        self.assertEqual(response_body['message'], message_202['message'])

        # body_request is not exist key notifyCode
        body_request = {'webhookUrl': webhook_url, 'mentions': mentions}
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user,
            body=json.dumps(body_request))

        response = notifymail.create_notifyslack_handler(event_mock, {})
        # Check data
        message_202 = MsgConst.ERR_REQUEST_202
        response_body = json.loads(response['body'])
        self.assertEqual(response['statusCode'], HTTPStatus.BAD_REQUEST)
        self.assertEqual(response_body['code'], message_202['code'])
        self.assertEqual(response_body['message'], message_202['message'])

        # body_request is not exist key webhookUrl
        body_request = {'notifyCode': notify_code, 'mentions': mentions}
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user,
            body=json.dumps(body_request))

        response = notifymail.create_notifyslack_handler(event_mock, {})
        # Check data
        message_202 = MsgConst.ERR_REQUEST_202
        response_body = json.loads(response['body'])
        self.assertEqual(response['statusCode'], HTTPStatus.BAD_REQUEST)
        self.assertEqual(response_body['code'], message_202['code'])
        self.assertEqual(response_body['message'], message_202['message'])
예제 #2
0
    def test_export_report_error_validate_required(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))
        test_report_id = report_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id,
            "report_id": test_report_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            query_string_parameters={"fileType": ""})
        response = reports.request_output_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_201['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_201['message'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body['errors']
        # レポート出力するファイル形式
        self.assertEqual(response_error[0]['code'],
                         MsgConst.ERR_VAL_101['code'])
        self.assertEqual(response_error[0]['field'], "fileType")
        self.assertEqual(response_error[0]['value'], "")
        self.assertEqual(response_error[0]['message'],
                         MsgConst.ERR_VAL_101['message'])
예제 #3
0
    def test_update_project_error_parse_json(self):
        test_project_id = template_project_id.format(str(1))
        test_organization_id = template_organization_id.format(str(1))
        test_user_id = affiliation_template_user_id.format(str(1))

        # handler
        path_parameters = {
            "project_id": test_project_id,
            "organization_id": test_organization_id
        }
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=project_update)
        response = projects.update_project_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_202['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_202['message'])
        self.assertEqual(response_body['description'],
                         MsgConst.ERR_REQUEST_202['description'])
        self.assertEqual(response['statusCode'], HTTPStatus.BAD_REQUEST.value)
예제 #4
0
    def test_update_user_success_case_create_record_data_body_contain_callerservicename(
            self):
        data_body_contain_callerservicename = {
            'userName': data_insert['UserName'],
            'companyName': data_insert['CompanyName'],
            'departmentName': data_insert['DepartmentName'],
            'companyFlg': data_insert['CompanyFlg'],
            'countryCode': data_insert['CountryCode'],
            'callerServiceName': "opswitch"
        }
        event_mock = event_create.get_event_object(
            trace_id=DataCommon.USER_ID_TEST.format(str(0)),
            body=json.dumps(data_body_contain_callerservicename))

        # Call function test
        response = user.update_user_attributes_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['id'], data_insert['UserID'])
        self.assertEqual(response_body['userName'],
                         data_body_contain_callerservicename['userName'])
        self.assertEqual(response_body['mailStatus'],
                         data_insert['MailStatus'])
        self.assertEqual(response_body['companyName'],
                         data_body_contain_callerservicename['companyName'])
        self.assertEqual(response_body['depertmentName'],
                         data_body_contain_callerservicename['departmentName'])
        self.assertEqual(response_body['companyFlg'],
                         data_body_contain_callerservicename['companyFlg'])
        self.assertEqual(response_body['countryCode'],
                         data_body_contain_callerservicename['countryCode'])
        self.assertEqual(
            response_body['callerServiceName'],
            data_body_contain_callerservicename['callerServiceName'])
예제 #5
0
 def test_count_myorganizations_ok(self):
     event_mock = event_create.get_event_object(
         trace_id=affiliation_template_user_id.format(str(5)),
         query_string_parameters={"inviteStatus": "1"}
     )
     response = myorganizations.count_myorganizations_handler(event_mock, {})
     self.assertEqual(response['statusCode'], HTTPStatus.OK.value)
예제 #6
0
    def test_update_project_error_validate_required(self):
        test_project_id = template_project_id.format(str(1))
        test_organization_id = template_organization_id.format(str(1))
        test_user_id = affiliation_template_user_id.format(str(1))

        # handler
        path_parameters = {
            "project_id": test_project_id,
            "organization_id": test_organization_id
        }
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(project_update_empty))
        response = projects.update_project_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_201['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_201['message'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body['errors']
        # 組織名
        self.assertEqual(response_error[0]['code'],
                         MsgConst.ERR_VAL_101['code'])
        self.assertEqual(response_error[0]['field'], "name")
        self.assertEqual(response_error[0]['value'], "")
        self.assertEqual(response_error[0]['message'],
                         MsgConst.ERR_VAL_101['message'])
예제 #7
0
    def test_get_user_success_case_not_caller_service_name(self):
        # perpare data test
        data_insert = DataPmUserAttribute.DATA_NOT_CALLERSERVICENAME
        mock_pm_userAttribute.create(data_insert)
        event_mock = event_create.get_event_object(
            trace_id=data_insert['UserID'])

        # Call function test
        result = user.get_user_attributes_handler(event_mock, {})

        # Check data
        status_code = result['statusCode']
        response_body = json.loads(result['body'])

        self.assertEqual(status_code, HTTPStatus.OK.value)
        self.assertEqual(response_body['id'], data_insert['UserID'])
        self.assertEqual(response_body['userName'], data_insert['UserName'])
        self.assertEqual(response_body['mailStatus'],
                         data_insert['MailStatus'])
        self.assertEqual(response_body['companyName'],
                         data_insert['CompanyName'])
        self.assertEqual(response_body['depertmentName'],
                         data_insert['DepartmentName'])
        self.assertEqual(response_body['companyFlg'],
                         data_insert['CompanyFlg'])
        self.assertEqual(response_body['countryCode'],
                         data_insert['CountryCode'])

        self.assertFalse("callerServiceName" in response_body.keys())
예제 #8
0
    def test_create_notifymail_error_validate_data_users(self):
        test_user_id = user_id.format(str(3))
        # handler
        path_parameters = {"organization_id": organization_id}
        notifymail_create['notifyCode'] = "CHECK_CIS"
        notifymail_create['users'] = ['NOT_EXISTS']
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(notifymail_create))
        response = notifymail.create_notifymail_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_201['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_201['message'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body['errors']
        # 宛先ユーザ
        self.assertEqual(response_error[0]['code'],
                         MsgConst.ERR_VAL_999['code'])
        self.assertEqual(response_error[0]['field'], "users")
        self.assertEqual(response_error[0]['value'], ['NOT_EXISTS'])
        self.assertEqual(response_error[0]['message'],
                         MsgConst.ERR_VAL_999['message'])
예제 #9
0
    def test_apply_change_email_handler_error_create_record(self):
        # mock object
        patch_create = patch('premembers.repository.pm_emailChangeApply.create')
        patch_get_cognito_user_pools = patch('premembers.common.aws_common.get_cognito_user_pools')
        # start mock object
        mock_create = patch_create.start()
        mock_get_cognito_user_pools = patch_get_cognito_user_pools.start()

        # mock data
        mock_create.side_effect = PmError()
        mock_get_cognito_user_pools.return_value = []

        # addCleanup stop mock object
        self.addCleanup(patch_create.stop)
        self.addCleanup(patch_get_cognito_user_pools.stop)
        # Call function test
        body = {
            "mailAddress": mail_after,
            "callerServiceName": "opswitch",
            "mailLang": language_mail_test
        }
        event_mock = event_create.get_event_object(
            trace_id=trace_id,
            email=mail_before,
            body=json.dumps(body))
        result = user.apply_change_email_handler(event_mock, {})

        # Check data
        response_body = json.loads(result['body'])
        err_403 = MsgConst.ERR_DB_403
        self.assertEqual(err_403['code'], response_body['code'])
        self.assertEqual(err_403['message'], response_body['message'])
        self.assertEqual(err_403['description'], response_body['description'])
        self.assertEqual(result['statusCode'],
                         HTTPStatus.INTERNAL_SERVER_ERROR.value)
예제 #10
0
    def test_create_project_error_validate_string_number(self):
        test_user_id = affiliation_template_user_id.format(str(1))
        test_organization_id = project_organization_id_template.format(str(1))

        project_create_tmp = copy.copy(project_create)
        project_create_tmp['name'] = 123

        # handler
        path_parameters = {"organization_id": test_organization_id}
        project_create[
            "organization_id"] = project_organization_id_template.format(
                str(1))
        event = event_create.get_event_object(
            trace_id=test_user_id,
            path_parameters=path_parameters,
            body=json.dumps(project_create_tmp))
        response = projects.create_project_handler(event, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_201['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_201['message'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body['errors']
        # 組織名
        self.assertEqual(response_error[0]['code'],
                         MsgConst.ERR_VAL_202['code'])
        self.assertEqual(response_error[0]['field'], "name")
        self.assertEqual(response_error[0]['value'], 123)
        self.assertEqual(response_error[0]['message'],
                         MsgConst.ERR_VAL_202['message'])
예제 #11
0
    def test_export_report_error_access_authority(self):
        # Authority = 2
        tmp_mail_address = mail_address.format(str(1))
        test_user_id = user_id.format(str(1))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id,
            "report_id": report_id.format(str(1)),
        }
        event_mock = event_create.get_event_object(
            email=tmp_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            query_string_parameters={"fileType": "EXCEL"},
            body=json.dumps(report_create))
        response = reports.request_output_report_handler(event_mock, {})

        # Check data
        message_101 = MsgConst.ERR_101
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'], message_101['code'])
        self.assertEqual(response_body['message'], message_101['message'])
        self.assertEqual(response['statusCode'], HTTPStatus.FORBIDDEN.value)
예제 #12
0
    def test_create_notifymail_success(self):
        notifymail_create['notifyCode'] = "CHECK_CIS"
        pm_orgNotifyMailDestinations.delete(trace_id, organization_id,
                                            notifymail_create['notifyCode'])
        test_user_id = user_id.format(str(3))
        # handler
        path_parameters = {"organization_id": organization_id}
        notifymail_create['users'] = [user_id.format(str(3))]
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(notifymail_create))
        response = notifymail.create_notifymail_handler(event_mock, {})

        # Get data response
        status_code = response['statusCode']
        response_body = json.loads(response['body'])
        organizationId = response_body["organizationId"]
        notify_code = response_body['notifyCode']
        destinations = response_body['destinations']
        createdAt = response_body['createdAt']
        updatedAt = response_body['updatedAt']

        # Get data in database
        result_database = pm_orgNotifyMailDestinations.query_key(
            trace_id, organization_id, notifymail_create['notifyCode'], True)

        # Check data
        self.assertEqual(organizationId, result_database['organizationId'])
        self.assertEqual(notify_code, result_database['notifyCode'])
        self.assertEqual(destinations, result_database['destinations'])
        self.assertEqual(createdAt, result_database['createdAt'])
        self.assertEqual(updatedAt, result_database['updatedAt'])
        self.assertEqual(status_code, HTTPStatus.CREATED.value)
예제 #13
0
    def test_create_report_error_record_zero_report_job_defs_excel(self):
        pm_batchJobDefs.delete_report_job_def(trace_id, code_excel)
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create))
        response = reports.create_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'], MsgConst.ERR_402['code'])
        self.assertEqual(response_body['message'], MsgConst.ERR_402['message'])
        self.assertEqual(response_body['description'],
                         MsgConst.ERR_402['description'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.INTERNAL_SERVER_ERROR.value)

        # Create ReportJobDefs
        report_job_def_aws['Code'] = code_excel
        report_job_def_aws['JobDefinition'] = job_definition_excel
        pm_batchJobDefs.create_report_job_def(
            trace_id, report_job_def_aws['Code'],
            report_job_def_aws['JobDefinition'],
            report_job_def_aws['JobQueue'], report_job_def_aws['MaxRetry'],
            report_job_def_aws['Environment'])
예제 #14
0
    def test_update_user_attribute_success_case_exists_record_contain_callerservicename_and_data_body_contain_callerservicename(
            self):
        # perpare data test
        data_update = DataPmUserAttribute.DATA_UPDATE_SIMPLE
        data_body = {
            "userName": data_update['UserName'],
            "companyName": data_update['CompanyName'],
            "departmentName": data_update['DepartmentName'],
            "countryCode": data_update['CountryCode'],
            "companyFlg": data_update['CompanyFlg'],
            "callerServiceName": "opswitch"
        }
        mock_pm_userAttribute.create(data_insert)
        event_mock = event_create.get_event_object(
            trace_id=data_insert['UserID'], body=json.dumps(data_body))

        # Call function test
        response = user.update_user_attributes_handler(event_mock, {})

        # Check data
        status_code = response['statusCode']
        response_body = json.loads(response['body'])

        self.assertEqual(status_code, HTTPStatus.OK.value)
        self.assertEqual(response_body['id'], data_insert['UserID'])
        self.assertEqual(response_body['userName'], data_body['userName'])
        self.assertEqual(response_body['companyName'],
                         data_body['companyName'])
        self.assertEqual(response_body['depertmentName'],
                         data_body['departmentName'])
        self.assertEqual(response_body['countryCode'],
                         data_body['countryCode'])
        self.assertEqual(response_body['companyFlg'], data_body['companyFlg'])
        self.assertEqual(response_body['callerServiceName'],
                         data_insert['CallerServiceName'])
예제 #15
0
    def test_create_report_error_parse_json(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=report_create)
        response = reports.create_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_202['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_202['message'])
        self.assertEqual(response_body['description'],
                         MsgConst.ERR_REQUEST_202['description'])
        self.assertEqual(response['statusCode'], HTTPStatus.BAD_REQUEST.value)
예제 #16
0
    def test_update_user_success_case_not_company_flg_and_country_code(self):
        # perpare data test
        data_body = {
            'userName': data_insert['UserName'],
            'companyName': data_insert['CompanyName'],
            'departmentName': data_insert['DepartmentName']
        }

        event_mock = event_create.get_event_object(
            trace_id=DataCommon.USER_ID_TEST.format(str(0)),
            body=json.dumps(data_body))

        # Call function test
        response = user.update_user_attributes_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['id'], data_insert['UserID'])
        self.assertEqual(response_body['userName'], data_body['userName'])
        self.assertEqual(response_body['mailStatus'],
                         data_insert['MailStatus'])
        self.assertEqual(response_body['companyName'],
                         data_body['companyName'])
        self.assertEqual(response_body['depertmentName'],
                         data_body['departmentName'])

        self.assertFalse("companyFlg" in response_body.keys())
        self.assertFalse("countryCode" in response_body.keys())
예제 #17
0
    def test_execute_security_check_handler_success(self):
        # mock object
        patch_aws_sns = patch("premembers.common.aws_common.aws_sns")
        patch_get_uuid4 = patch("premembers.common.common_utils.get_uuid4")

        # start mock object
        mock_aws_sns = patch_aws_sns.start()
        mock_get_uuid4 = patch_get_uuid4.start()

        # mock data
        mock_aws_sns.side_effect = None
        mock_get_uuid4.return_value = check_history_id

        # addCleanup stop mock object
        self.addCleanup(patch_aws_sns.stop)
        self.addCleanup(patch_get_uuid4.stop)

        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=user_id_test,
            email=email)

        # Call function test
        actual_response = awschecks.execute_security_check_handler(
            event_mock, {})

        # assert call aws_sns
        topic_arn = common_utils.get_environ(
            CommonConst.SECURITYCHECK_EXECUTE_TOPIC)
        subject = "USER : {0}".format(execute_user_id)
        message = {'CheckHistoryId': check_history_id}
        mock_aws_sns.assert_called_once_with(user_id_test, subject,
                                             json.dumps(message), topic_arn)

        # Get data response
        actual_status_code = actual_response['statusCode']
        actual_response_bodys = json.loads(actual_response['body'])

        expect_response_pm_checkHistory = mock_pm_checkHistory.query_key(
            check_history_id)

        # Check data
        self.assertEqual(HTTPStatus.CREATED, actual_status_code)

        self.assertEqual(expect_response_pm_checkHistory['CheckCode'],
                         actual_response_bodys['checkCode'])
        self.assertEqual(expect_response_pm_checkHistory['CheckStatus'],
                         actual_response_bodys['checkStatus'])
        self.assertEqual('', actual_response_bodys['errorCode'])
        self.assertEqual(expect_response_pm_checkHistory['ExecutedDateTime'],
                         actual_response_bodys['executedDateTime'])
        self.assertEqual(expect_response_pm_checkHistory['ExecutedType'],
                         actual_response_bodys['executedType'])
        self.assertEqual(expect_response_pm_checkHistory['CheckHistoryID'],
                         actual_response_bodys['id'])
        self.assertEqual(expect_response_pm_checkHistory['OrganizationID'],
                         actual_response_bodys['organizationId'])
        self.assertEqual(expect_response_pm_checkHistory['ProjectID'],
                         actual_response_bodys['projectId'])
        self.assertEqual('', actual_response_bodys['reportFilePath'])
예제 #18
0
    def test_create_report_success(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create))
        response = reports.create_report_handler(event_mock, {})

        # Get data response
        status_code = response['statusCode']
        response_body = json.loads(response['body'])
        id = response_body["id"]
        name = response_body['name']
        generateUser = response_body['generateUser']
        awsAccounts = response_body['awsAccounts']
        status = response_body['status']
        jsonOutputTime = response_body['jsonOutputTime']
        excelOutputStatus = response_body['excelOutputStatus']
        excelOutputTime = response_body['excelOutputTime']
        schemaVersion = response_body['schemaVersion']
        projectId = response_body['projectId']
        organizationId = response_body['organizationId']
        createdAt = response_body['createdAt']
        updatedAt = response_body['updatedAt']

        # Get data in database
        report_database = pm_reports.query_report(trace_id,
                                                  id,
                                                  convert_response=True)

        # Check data
        self.assertEqual(id, report_database['id'])
        self.assertEqual(name, report_database['name'])
        self.assertEqual(generateUser, report_database['generateUser'])
        self.assertEqual(awsAccounts, report_database['awsAccounts'])
        self.assertEqual(status, report_database['status'])
        self.assertEqual(jsonOutputTime, report_database['jsonOutputTime'])
        self.assertEqual(excelOutputStatus,
                         report_database['excelOutputStatus'])
        self.assertEqual(excelOutputTime, report_database['excelOutputTime'])
        self.assertEqual(schemaVersion, report_database['schemaVersion'])
        self.assertEqual(projectId, report_database['projectId'])
        self.assertEqual(organizationId, report_database['organizationId'])
        self.assertEqual(createdAt, report_database['createdAt'])
        self.assertEqual(updatedAt, report_database['updatedAt'])
        self.assertEqual(status_code, HTTPStatus.CREATED.value)
        pm_reports.delete_reports(trace_id, id)
예제 #19
0
    def test_list_reports_susscess(self):
        test_user_id = user_id.format(str(1))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters, trace_id=test_user_id)
        response = reports.list_reports_handler(event_mock, {})
        self.assertEqual(response['statusCode'], HTTPStatus.OK)
        response_body = json.loads(response['body'])
        response_body = json.loads(response['body'])
        for item in response_body:
            id = item["id"]
            reportName = item['name']
            generateUser = item['generateUser']
            awsAccounts = item['awsAccounts']
            status = item['status']
            jsonOutputTime = item['jsonOutputTime']
            htmlOutputStatus = item['htmlOutputStatus']
            htmlOutputTime = item['htmlOutputTime']
            excelOutputStatus = item['excelOutputStatus']
            excelOutputTime = item['excelOutputTime']
            schemaVersion = item['schemaVersion']
            organizationID = item['organizationId']
            projectID = item['projectId']
            createdAt = item['createdAt']
            updatedAt = item['updatedAt']

            report_database = pm_reports.query_report(trace_id,
                                                      id,
                                                      convert_response=True)

            # Check data
            self.assertEqual(id, report_database['id'])
            self.assertEqual(reportName, report_database['name'])
            self.assertEqual(generateUser, report_database['generateUser'])
            self.assertEqual(awsAccounts, report_database['awsAccounts'])
            self.assertEqual(status, report_database['status'])
            self.assertEqual(jsonOutputTime, report_database['jsonOutputTime'])
            self.assertEqual(htmlOutputStatus,
                             report_database['htmlOutputStatus'])
            self.assertEqual(htmlOutputTime, report_database['htmlOutputTime'])
            self.assertEqual(excelOutputStatus,
                             report_database['excelOutputStatus'])
            self.assertEqual(excelOutputTime,
                             report_database['excelOutputTime'])
            self.assertEqual(schemaVersion, report_database['schemaVersion'])
            self.assertEqual(organizationID, report_database['organizationId'])
            self.assertEqual(projectID, report_database['projectId'])
            self.assertEqual(createdAt, report_database['createdAt'])
            self.assertEqual(updatedAt, report_database['updatedAt'])
예제 #20
0
    def test_list_awscoops_susscess_no_effective_2(self):
        test_user_id = user_id.format(str(1))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters, trace_id=test_user_id)
        response = awscoops.list_awscoops_handler(event_mock, {})
        self.assertEqual(response['statusCode'], HTTPStatus.OK)
예제 #21
0
    def test_create_report_error_validate_data(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create_error_data))
        response = reports.create_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_201['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_201['message'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body['errors']
        # レポート名
        self.assertEqual(response_error[0]['code'],
                         MsgConst.ERR_VAL_202['code'])
        self.assertEqual(response_error[0]['field'], "name")
        self.assertEqual(response_error[0]['value'],
                         report_create_error_data['name'])
        self.assertEqual(response_error[0]['message'],
                         MsgConst.ERR_VAL_202['message'])

        # AWSアカウントID
        self.assertEqual(response_error[1]['code'],
                         MsgConst.ERR_VAL_204['code'])
        self.assertEqual(response_error[1]['field'], "awsAccounts")
        self.assertEqual(response_error[1]['value'],
                         report_create_error_data['awsAccounts'])
        self.assertEqual(response_error[1]['message'],
                         MsgConst.ERR_VAL_204['message'])

        # レポート出力するファイル形式
        self.assertEqual(response_error[2]['code'],
                         MsgConst.ERR_VAL_302['code'])
        self.assertEqual(response_error[2]['field'], "outputFileType")
        self.assertEqual(response_error[2]['value'],
                         report_create_error_data['outputFileType'])
        self.assertEqual(response_error[2]['message'],
                         MsgConst.ERR_VAL_302['message'].format("EXCEL"))
    def test_execute_security_check_webhook_handler_success(self):
        # mock object
        patch_aws_sns = patch("premembers.common.aws_common.aws_sns")
        patch_get_uuid4 = patch("premembers.common.common_utils.get_uuid4")

        # start mock object
        mock_aws_sns = patch_aws_sns.start()
        mock_get_uuid4 = patch_get_uuid4.start()

        # mock data
        mock_aws_sns.side_effect = None
        mock_get_uuid4.return_value = check_history_id

        # addCleanup stop mock object
        self.addCleanup(patch_aws_sns.stop)
        self.addCleanup(patch_get_uuid4.stop)

        event_mock = event_create.get_event_object(
            path_parameters=path_parameters)

        # Call function test
        actual_response = awschecks.execute_security_check_webhook_handler(
            event_mock, {})

        # Get data response
        actual_status_code = actual_response['statusCode']
        actual_response_bodys = json.loads(actual_response['body'])

        expect_response_pm_checkHistory = mock_pm_checkHistory.query_key(
            check_history_id)

        # Check data
        self.assertEqual(HTTPStatus.CREATED, actual_status_code)

        self.assertEqual(expect_response_pm_checkHistory['CheckCode'],
                         actual_response_bodys['checkCode'])
        self.assertEqual(expect_response_pm_checkHistory['CheckStatus'],
                         actual_response_bodys['checkStatus'])
        self.assertEqual('', actual_response_bodys['errorCode'])
        self.assertEqual(expect_response_pm_checkHistory['ExecutedDateTime'],
                         actual_response_bodys['executedDateTime'])
        self.assertEqual(expect_response_pm_checkHistory['ExecutedType'],
                         actual_response_bodys['executedType'])
        self.assertEqual(expect_response_pm_checkHistory['CheckHistoryID'],
                         actual_response_bodys['id'])
        self.assertEqual(expect_response_pm_checkHistory['OrganizationID'],
                         actual_response_bodys['organizationId'])
        self.assertEqual(expect_response_pm_checkHistory['ProjectID'],
                         actual_response_bodys['projectId'])
        self.assertEqual('', actual_response_bodys['reportFilePath'])
예제 #23
0
    def test_get_user_attributes_record_zero(self):
        # perpare data test
        user_id = "not found"
        event_mock = event_create.get_event_object(trace_id=user_id)

        # Call function test
        result = user.get_user_attributes_handler(event_mock, {})

        # Check data
        status_code = result['statusCode']
        response_body = json.loads(result['body'])

        self.assertEqual(status_code, HTTPStatus.OK.value)
        self.assertEqual(response_body, {})
예제 #24
0
    def test_apply_change_email_handler_error_read_file_template(self):
        # mock object
        patch_get_cognito_user_pools = patch('premembers.common.aws_common.get_cognito_user_pools')
        patch_method_error = patch.object(PmLogAdapter, "error")
        patch_read_decode = patch("premembers.common.FileUtils.read_decode")
        patch_read_yaml = patch("premembers.common.FileUtils.read_yaml")
        # start mock object
        mock_get_cognito_user_pools = patch_get_cognito_user_pools.start()
        mock_method_error = patch_method_error.start()
        mock_read_yaml = patch_read_yaml.start()
        mock_read_decode = patch_read_decode.start()

        # mock data
        mock_get_cognito_user_pools.return_value = []
        mock_method_error.return_value = None
        mock_read_yaml.return_value = response_data_config
        mock_read_decode.side_effect = PmError()

        # addCleanup stop mock object
        self.addCleanup(patch_get_cognito_user_pools.stop)
        self.addCleanup(patch_method_error.stop)
        self.addCleanup(patch_read_yaml.stop)
        self.addCleanup(patch_read_decode.stop)

        # Call function test
        body = {
            "mailAddress": mail_after,
            "callerServiceName": "insightwatch",
            "mailLang": language_mail_test
        }
        event_mock = event_create.get_event_object(
            trace_id=trace_id,
            email=mail_before,
            body=json.dumps(body))
        result = user.apply_change_email_handler(event_mock, {})

        # Check data
        mock_method_error.assert_any_call(
            "メールアドレス変更通知メール本文テンプレートファイルの取得に失敗しました。:s3://%s/%s",
            common_utils.get_environ(CommonConst.S3_SETTING_BUCKET),
            "check/notify/mail/insightwatch_apply_change_mail_template_ja.tpl")

        response_body = json.loads(result['body'])
        err_s3_702 = MsgConst.ERR_S3_702
        self.assertEqual(err_s3_702['code'], response_body['code'])
        self.assertEqual(err_s3_702['message'], response_body['message'])
        self.assertEqual(err_s3_702['description'], response_body['description'])
        self.assertEqual(result['statusCode'],
                         HTTPStatus.INTERNAL_SERVER_ERROR.value)
예제 #25
0
    def test_update_awscoops_success_members_disable(self):
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id,
            "coop_id": coop_id.format(str(1))
        }
        tmp_awscoops_body = copy.copy(awscoops_body)
        tmp_awscoops_body['awsAccount'] = 'ERROR'
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(tmp_awscoops_body))
        response = awscoops.update_awscoop_handler(event_mock, {})

        # Get data response
        status_code = response['statusCode']
        response_body = json.loads(response['body'])
        id = response_body["id"]
        awsAccount = response_body['awsAccount']
        roleName = response_body['roleName']
        externalId = response_body['externalId']
        projectId = response_body['projectId']
        organizationId = response_body['organizationId']
        description = response_body['description']
        createdAt = response_body['createdAt']
        updatedAt = response_body['updatedAt']
        members = response_body['members']

        # Get data in database
        awscoops_database = pm_awsAccountCoops.query_awscoop_coop_key(
            trace_id, id, convert_response=True)

        # Check data
        self.assertEqual(id, awscoops_database['id'])
        self.assertEqual(awsAccount, awscoops_database['awsAccount'])
        self.assertEqual(roleName, awscoops_database['roleName'])
        self.assertEqual(externalId, awscoops_database['externalId'])
        self.assertEqual(projectId, awscoops_database['projectId'])
        self.assertEqual(organizationId, awscoops_database['organizationId'])
        self.assertEqual(description, awscoops_database['description'])
        self.assertEqual(createdAt, awscoops_database['createdAt'])
        self.assertEqual(updatedAt, awscoops_database['updatedAt'])
        self.assertEqual(members, awscoops_database['members'])
        self.assertEqual(members, 0)
        self.assertEqual(status_code, HTTPStatus.OK.value)
        pm_awsAccountCoops.delete_awscoops(trace_id, id)
예제 #26
0
    def test_get_notifyslack_record_zero(self):
        test_user_id = user_id.format(str(3))
        pm_orgNotifySlack.delete(trace_id, organization_id, notify_code)
        # handler
        path_parameters = {"organization_id": organization_id}
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            query_string_parameters={"notifyCode": notify_code},
            trace_id=test_user_id)

        response = notifymail.get_notifyslack_handler(event_mock, {})
        # check data
        self.assertEqual(response['statusCode'], HTTPStatus.OK.value)
        response_body = json.loads(response['body'])
        self.assertEqual(response_body, [])
예제 #27
0
 def test_delete_notifyslack_error_access_authority(self):
     test_user_id = user_id.format(str(1))
     # handler
     path_parameters = {"organization_id": organization_id}
     event_mock = event_create.get_event_object(
         path_parameters=path_parameters,
         trace_id=test_user_id,
         query_string_parameters={"notifyCode": notify_code})
     response = notifymail.delete_notifyslack_handler(event_mock, {})
     # Check data
     message_101 = MsgConst.ERR_101
     response_body = json.loads(response['body'])
     self.assertEqual(response_body['code'], message_101['code'])
     self.assertEqual(response_body['message'], message_101['message'])
     self.assertEqual(response['statusCode'], HTTPStatus.FORBIDDEN)
예제 #28
0
    def test_get_list_project_success_record_zero(self):
        test_organization_id = template_organization_id.format(str(2))
        test_user_id = affiliation_template_user_id.format(str(2))

        # handler
        path_parameters = {"organization_id": test_organization_id}
        event_mock = event_create.get_event_object(
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(organization_update_empty))
        response = projects.list_projects_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body, [])
예제 #29
0
    def test_apply_change_email_handler_error_send_mail(self):
        # mock object
        patch_get_cognito_user_pools = patch('premembers.common.aws_common.get_cognito_user_pools')
        patch_method_error = patch.object(PmLogAdapter, "error")
        patch_read_decode = patch("premembers.common.FileUtils.read_decode")
        patch_read_yaml = patch("premembers.common.FileUtils.read_yaml")
        patch_send_email = patch("premembers.common.aws_common.send_email")
        # start mock object
        mock_get_cognito_user_pools = patch_get_cognito_user_pools.start()
        mock_method_error = patch_method_error.start()
        mock_read_yaml = patch_read_yaml.start()
        mock_read_decode = patch_read_decode.start()
        mock_send_email = patch_send_email.start()

        # mock data
        mock_get_cognito_user_pools.return_value = []
        mock_method_error.return_value = None
        mock_read_yaml.return_value = response_data_config
        mock_send_email.side_effect = PmError()
        mock_read_decode.return_value = template_body_mail

        # addCleanup stop mock object
        self.addCleanup(patch_get_cognito_user_pools.stop)
        self.addCleanup(patch_method_error.stop)
        self.addCleanup(patch_read_yaml.stop)
        self.addCleanup(patch_read_decode.stop)
        self.addCleanup(patch_send_email.stop)

        # Call function test
        body = {
            "mailAddress": mail_after,
            "callerServiceName": "insightwatch",
            "mailLang": language_mail_test
        }
        event_mock = event_create.get_event_object(
            trace_id=trace_id, email=mail_before, body=json.dumps(body))
        result = user.apply_change_email_handler(event_mock, {})

        # Check data
        mock_method_error.assert_any_call("通知メール送信に失敗しました。")

        response_body = json.loads(result['body'])
        err_ses_801 = MsgConst.ERR_SES_801
        self.assertEqual(err_ses_801['code'], response_body['code'])
        self.assertEqual(err_ses_801['message'], response_body['message'])
        self.assertEqual(err_ses_801['description'], response_body['description'])
        self.assertEqual(result['statusCode'],
                         HTTPStatus.INTERNAL_SERVER_ERROR.value)
예제 #30
0
 def test_get_notifyslack_error_notifycode_empty(self):
     test_user_id = user_id.format(str(3))
     # handler
     path_parameters = {"organization_id": organization_id}
     event_mock = event_create.get_event_object(
         path_parameters=path_parameters,
         query_string_parameters={"notifyCode": ""},
         trace_id=test_user_id)
     response = notifymail.get_notifyslack_handler(event_mock, {})
     # check data
     message_201 = MsgConst.ERR_REQUEST_201
     response_body = json.loads(response['body'])
     self.assertEqual(response_body['code'], message_201['code'])
     self.assertEqual(response_body['message'], message_201['message'])
     self.assertEqual(response['statusCode'],
                      HTTPStatus.UNPROCESSABLE_ENTITY.value)