How to use validate_request method in localstack

Best Python code snippet using localstack_python

api.py

Source:api.py Github

copy

Full Screen

...6api_bp = Blueprint(7 'api',8 __name__9)10def validate_request(request):11 auth_header = request.headers.get('soc-faker')12 if auth_header:13 existing_registration = TokenModel.objects(token=auth_header).first()14 if existing_registration:15 return True16 abort(401)17@api_bp.errorhandler(401)18def unauthorized(error):19 return Response('Unauthorized to access this resource', 401, {'Content-Type': 'application/json'})20@api_bp.route("/agent", methods=['GET'])21def socfaker_socfaker_agent():22 """23 Access generated data related to an endpoint agent24 Returns:25 Agent: Returns an object with properties related to an endpoint agent26 27 """28 if validate_request(request):29 return jsonify(str(socfaker.agent))30@api_bp.route("/agent/ephermeral_id", methods=['GET'])31def socfaker_agent_ephermeral_id():32 """33 A unique and random ephermal ID that changes34 Returns:35 str: A unique 8 character length hex ID36 37 """38 if validate_request(request):39 return { 'value': socfaker.agent.ephermeral_id }40@api_bp.route("/agent/id", methods=['GET'])41def socfaker_agent_id():42 """43 A agent ID which is typically static across the lifetime of the 44 agent (per instance of this class)45 Returns:46 str: A static but unique 8 character length ID representing the agent ID47 48 """49 if validate_request(request):50 return { 'value': socfaker.agent.id }51@api_bp.route("/agent/name", methods=['GET'])52def socfaker_agent_name():53 """54 A custom name of the agent55 Returns:56 str: A custom name of the agent57 58 """59 if validate_request(request):60 return { 'value': socfaker.agent.name }61@api_bp.route("/agent/type", methods=['GET'])62def socfaker_agent_type():63 """64 The type of agent.65 Options are: 'filebeat', 'auditbeat', 'functionbeat', 66 'heartbeat', 'winlogbeat', 'packetbeat'67 Returns:68 str: A agent type69 70 """71 if validate_request(request):72 return { 'value': socfaker.agent.type }73@api_bp.route("/agent/version", methods=['GET'])74def socfaker_agent_version():75 """76 The agent version77 Returns:78 str: Currently set to a static value of 7.8.079 80 """81 if validate_request(request):82 return { 'value': socfaker.agent.version }83### AGENT ROUTES ###84### ALERT ROUTES ###85@api_bp.route("/alert", methods=['GET'])86def socfaker_socfaker_alert():87 """88 Alert or Detection properties89 Returns:90 Alert: Returns an object with properties about a alert or detection91 92 """93 if validate_request(request):94 return jsonify(str(socfaker.alert))95@api_bp.route("/alert/action", methods=['GET'])96def socfaker_alert_action():97 """98 An action taken based on the alert99 Returns:100 str: Returns a random action based on the alert101 102 """103 if validate_request(request):104 return { 'value': socfaker.alert.action }105@api_bp.route("/alert/direction", methods=['GET'])106def socfaker_alert_direction():107 """108 The direction of the alert (network based)109 Returns:110 str: Random direction of from or to111 112 """113 if validate_request(request):114 return { 'value': socfaker.alert.direction }115@api_bp.route("/alert/location", methods=['GET'])116def socfaker_alert_location():117 """118 The country the alert originated from119 Returns:120 str: A random country an alert was generated from121 122 """123 if validate_request(request):124 return { 'value': socfaker.alert.location }125@api_bp.route("/alert/signature_name", methods=['GET'])126def socfaker_alert_signature_name():127 """128 Returns the name of a signature that the Alert triggered upon129 Returns:130 Str: returns a random alert signature name131 132 """133 if validate_request(request):134 return { 'value': socfaker.alert.signature_name }135@api_bp.route("/alert/status", methods=['GET'])136def socfaker_alert_status():137 """138 The current alert status139 Returns:140 str: Returns whether the alert was successful 141 or unsuccessful142 143 """144 if validate_request(request):145 return { 'value': socfaker.alert.status }146@api_bp.route("/alert/summary", methods=['GET'])147def socfaker_alert_summary():148 """149 Returns the summary of an alert150 Returns:151 str: Returns a string of this instance of an alert. 152 Contains a status, action, type, direction, and location.153 154 """155 if validate_request(request):156 return { 'value': socfaker.alert.summary }157@api_bp.route("/alert/type", methods=['GET'])158def socfaker_alert_type():159 """160 Returns an alert type161 Returns:162 str: Returns a random alert type163 164 """165 if validate_request(request):166 return { 'value': socfaker.alert.type }167### ALERT ROUTES ###168### APPLICATION ROUTES ###169@api_bp.route("/application", methods=['GET'])170def socfaker_socfaker_application():171 """172 Generated data related to a application173 Returns:174 Application: Returns an object with properties about an application175 176 """177 if validate_request(request):178 return jsonify(str(socfaker.application))179@api_bp.route("/application/account_status", methods=['GET'])180def socfaker_application_account_status():181 """182 A random account status for the application183 Returns:184 str: Returns whether an account is enabled or 185 disabled for an application186 187 """188 if validate_request(request):189 return { 'value': socfaker.application.account_status }190@api_bp.route("/application/logon_timestamp", methods=['GET'])191def socfaker_application_logon_timestamp():192 """193 Logon timestamp of a user/service for an applicaiton194 Returns:195 str: Returns an ISO 8601 timestamp in the past196 197 """198 if validate_request(request):199 return { 'value': socfaker.application.logon_timestamp }200@api_bp.route("/application/name", methods=['GET'])201def socfaker_application_name():202 """203 The name of an application204 Returns:205 str: Returns a random application name based on common 206 applications used in enterprises207 208 """209 if validate_request(request):210 return { 'value': socfaker.application.name }211@api_bp.route("/application/status", methods=['GET'])212def socfaker_application_status():213 """214 Returns the application status215 Returns:216 str: Returns the application status of 217 Active, Inactive, or Legacy218 219 """220 if validate_request(request):221 return { 'value': socfaker.application.status }222### APPLICATION ROUTES ###223### CLOUD ROUTES ###224@api_bp.route("/cloud", methods=['GET'])225def socfaker_socfaker_cloud():226 """227 Generated data related to cloud infrastructure228 Returns:229 Cloud: Returns an object with properties about cloud infrastructure230 231 """232 if validate_request(request):233 return jsonify(str(socfaker.cloud))234@api_bp.route("/cloud/id", methods=['GET'])235def socfaker_cloud_id():236 """237 A cloud instance ID238 Returns:239 str: A random GUID for a cloud instance ID240 241 """242 if validate_request(request):243 return { 'value': socfaker.cloud.id }244@api_bp.route("/cloud/instance_id", methods=['GET'])245def socfaker_cloud_instance_id():246 """247 A random hex instance ID248 Returns:249 str: A random HEX character instance ID250 251 """252 if validate_request(request):253 return { 'value': socfaker.cloud.instance_id }254@api_bp.route("/cloud/name", methods=['GET'])255def socfaker_cloud_name():256 """257 The name of a cloud VM/container instance258 Returns:259 str: A random generated name of a cloud VM or container instance260 261 """262 if validate_request(request):263 return { 'value': socfaker.cloud.name }264@api_bp.route("/cloud/provider", methods=['GET'])265def socfaker_cloud_provider():266 """267 The cloud provider268 Returns:269 str: A random cloud provider of either aws, azure, gcp, or digitalocean270 271 """272 if validate_request(request):273 return { 'value': socfaker.cloud.provider }274@api_bp.route("/cloud/region", methods=['GET'])275def socfaker_cloud_region():276 """277 The region of a cloud instance278 Returns:279 str: The region of a cloud instance280 281 """282 if validate_request(request):283 return { 'value': socfaker.cloud.region }284@api_bp.route("/cloud/size", methods=['GET'])285def socfaker_cloud_size():286 """287 The size of a instance (based on AWS naming convention)288 Returns:289 str: A random size of an instance based on AWS naming convention290 291 """292 if validate_request(request):293 return { 'value': socfaker.cloud.size }294@api_bp.route("/cloud/zone", methods=['GET'])295def socfaker_cloud_zone():296 """297 A random generated availability zone in common cloud platforms like AWS & Azure298 Returns:299 str: A string representing a cloud availability zone300 301 """302 if validate_request(request):303 return { 'value': socfaker.cloud.zone }304### CLOUD ROUTES ###305### COMPUTER ROUTES ###306@api_bp.route("/computer", methods=['GET'])307def socfaker_socfaker_computer():308 """309 Generated data about a computer system310 Returns:311 Computer: Returns an object with properties about a computer system312 313 """314 if validate_request(request):315 return {'value': socfaker.computer}316@api_bp.route("/computer/architecture", methods=['GET'])317def socfaker_computer_architecture():318 """319 Architecture of a computer instance320 Returns:321 str: Architecture of computer system of either x86_64 or x86322 323 """324 if validate_request(request):325 return { 'value': socfaker.computer.architecture }326@api_bp.route("/computer/disk", methods=['GET'])327def socfaker_computer_disk():328 """329 The disk size of a computer instance330 Returns:331 list: Returns a list of B,KB,MB,GB, and TB size of a computers disk332 333 """334 if validate_request(request):335 return { 'value': socfaker.computer.disk }336@api_bp.route("/computer/ipv4", methods=['GET'])337def socfaker_computer_ipv4():338 """339 The operating system ipv4 address340 Returns:341 str: A random operating system ipv4 address342 343 """344 if validate_request(request):345 return { 'value': socfaker.computer.ipv4 }346@api_bp.route("/computer/mac_address", methods=['GET'])347def socfaker_computer_mac_address():348 """349 A generated MAC address for a computer instance350 Returns:351 str: A random MAC Address352 353 """354 if validate_request(request):355 return { 'value': socfaker.computer.mac_address }356@api_bp.route("/computer/memory", methods=['GET'])357def socfaker_computer_memory():358 """359 The memory size of a computer instance360 Returns:361 list: Returns a list of B,KB,MB,GB, and TB size of a computers memory size362 363 """364 if validate_request(request):365 return { 'value': socfaker.computer.memory }366@api_bp.route("/computer/name", methods=['GET'])367def socfaker_computer_name():368 """369 The name of a comptuer370 Returns:371 str: A random name of a computer 372 373 """374 if validate_request(request):375 return { 'value': socfaker.computer.name }376@api_bp.route("/computer/os", methods=['GET'])377def socfaker_computer_os():378 """379 The operating system full name of the computer instance380 Returns:381 str: A random operating system version382 383 """384 if validate_request(request):385 return { 'value': socfaker.computer.os }386@api_bp.route("/computer/platform", methods=['GET'])387def socfaker_computer_platform():388 """389 A random name of the computers platform390 Returns:391 str: Random name of a computers platform (e.g. worksation, server, etc.)392 393 """394 if validate_request(request):395 return { 'value': socfaker.computer.platform }396### COMPUTER ROUTES ###397### CONTAINER ROUTES ###398@api_bp.route("/container", methods=['GET'])399def socfaker_socfaker_container():400 """401 Generated data about a container402 Returns:403 Container: Returns an object with properties about a container404 405 """406 if validate_request(request):407 return jsonify(str(socfaker.container))408@api_bp.route("/container/id", methods=['GET'])409def socfaker_container_id():410 """411 A container ID412 Returns:413 str: A hex container ID414 415 """416 if validate_request(request):417 return { 'value': socfaker.container.id }418@api_bp.route("/container/name", methods=['GET'])419def socfaker_container_name():420 """421 A random generated container name422 Returns:423 str: A randomly generated container name424 425 """426 if validate_request(request):427 return { 'value': socfaker.container.name }428@api_bp.route("/container/runtime", methods=['GET'])429def socfaker_container_runtime():430 """431 A container runtime432 Returns:433 str: Returns either docker or kubernetes434 435 """436 if validate_request(request):437 return { 'value': socfaker.container.runtime }438@api_bp.route("/container/tags", methods=['GET'])439def socfaker_container_tags():440 """441 Container tags442 Returns:443 list: A random list of container tags444 445 """446 if validate_request(request):447 return { 'value': socfaker.container.tags }448### CONTAINER ROUTES ###449### DNS ROUTES ###450@api_bp.route("/dns", methods=['GET'])451def socfaker_socfaker_dns():452 """453 DNS Information454 Returns:455 DNS: Returns an object with properties about DNS request, response, etc.456 457 """458 if validate_request(request):459 return jsonify(str(socfaker.dns))460@api_bp.route("/dns/answers", methods=['GET'])461def socfaker_dns_answers():462 """463 A list of DNS answers during a DNS request464 Returns:465 list: A random list (count) of random DNS answers during a DNS request466 467 """468 if validate_request(request):469 return jsonify(str(socfaker.dns.answers))470@api_bp.route("/dns/direction", methods=['GET'])471def socfaker_dns_direction():472 """473 The direction of a DNS request474 Returns:475 str: Returns a direction for a DNS request or response476 477 """478 if validate_request(request):479 return { 'value': socfaker.dns.direction }480@api_bp.route("/dns/header_flags", methods=['GET'])481def socfaker_dns_header_flags():482 """483 DNS Header flags484 Returns:485 str: A randomly selected DNS Header Flag486 487 """488 if validate_request(request):489 return { 'value': socfaker.dns.header_flags }490@api_bp.route("/dns/id", methods=['GET'])491def socfaker_dns_id():492 """493 A random DNS ID value from 10000,100000494 Returns:495 int: A random DNS ID value496 497 """498 if validate_request(request):499 return { 'value': socfaker.dns.id }500@api_bp.route("/dns/name", methods=['GET'])501def socfaker_dns_name():502 """503 Returns a randomly generated DNS name504 Returns:505 str: A random DNS Name506 507 """508 if validate_request(request):509 return { 'value': socfaker.dns.name }510@api_bp.route("/dns/op_code", methods=['GET'])511def socfaker_dns_op_code():512 """513 A DNS OP COde514 Returns:515 str: A random DNS OP Code for a DNS request516 517 """518 if validate_request(request):519 return { 'value': socfaker.dns.op_code }520@api_bp.route("/dns/question", methods=['GET'])521def socfaker_dns_question():522 """523 A DNS question during a DNS request524 Returns:525 dict: A random DNS question during a DNS request526 527 """528 if validate_request(request):529 return jsonify(str(socfaker.dns.question))530@api_bp.route("/dns/record", methods=['GET'])531def socfaker_dns_record():532 """533 A randomly selected record type534 Returns:535 str: A random DNS record (e.g. A, CNAME, PTR, etc.)536 537 """538 if validate_request(request):539 return { 'value': socfaker.dns.record }540@api_bp.route("/dns/response_code", methods=['GET'])541def socfaker_dns_response_code():542 """543 A DNS Response Code544 Returns:545 str: A DNS response code as part of a response made during a DNS request546 547 """548 if validate_request(request):549 return { 'value': socfaker.dns.response_code }550### DNS ROUTES ###551### EMPLOYEE ROUTES ###552@api_bp.route("/employee", methods=['GET'])553def socfaker_socfaker_employee():554 """555 An employee object556 Returns:557 Employee: Returns an object with properties about a fake employee558 559 """560 if validate_request(request):561 return jsonify(str(socfaker.employee))562@api_bp.route("/employee/account_status", methods=['GET'])563def socfaker_employee_account_status():564 """565 Account status of an employee566 Returns:567 str: Returns an employee's account status. This is weighted towards enabled.568 569 """570 if validate_request(request):571 return { 'value': socfaker.employee.account_status }572@api_bp.route("/employee/department", methods=['GET'])573def socfaker_employee_department():574 """575 Employee department576 Returns:577 str: Returns a random employee department578 579 """580 if validate_request(request):581 return { 'value': socfaker.employee.department }582@api_bp.route("/employee/dob", methods=['GET'])583def socfaker_employee_dob():584 """585 Date of Birth of an employee586 Returns:587 str: Returns the date of birth (DOB) of an employee588 589 """590 if validate_request(request):591 return { 'value': socfaker.employee.dob }592@api_bp.route("/employee/email", methods=['GET'])593def socfaker_employee_email():594 """595 Email of an employee596 Returns:597 str: Returns the email address of an employee598 599 """600 if validate_request(request):601 return { 'value': socfaker.employee.email }602@api_bp.route("/employee/first_name", methods=['GET'])603def socfaker_employee_first_name():604 """605 First name of an employee606 Returns:607 str: Returns the first name of an employee608 609 """610 if validate_request(request):611 return { 'value': socfaker.employee.first_name }612@api_bp.route("/employee/gender", methods=['GET'])613def socfaker_employee_gender():614 """615 Gender of an employee616 Returns:617 str: Returns the gender of an employee618 619 """620 if validate_request(request):621 return { 'value': socfaker.employee.gender }622@api_bp.route("/employee/language", methods=['GET'])623def socfaker_employee_language():624 """625 The preferred employee language626 Returns:627 str: Returns a random language of an employee628 629 """630 if validate_request(request):631 return { 'value': socfaker.employee.language }632@api_bp.route("/employee/last_name", methods=['GET'])633def socfaker_employee_last_name():634 """635 Last name of an employee636 Returns:637 str: Returns the last name of an employee638 639 """640 if validate_request(request):641 return { 'value': socfaker.employee.last_name }642@api_bp.route("/employee/logon_timestamp", methods=['GET'])643def socfaker_employee_logon_timestamp():644 """645 Last logon timestamp of an employee646 Returns:647 str: Returns a random ISO 8601 timestamp of an employee in the past648 649 """650 if validate_request(request):651 return { 'value': socfaker.employee.logon_timestamp }652@api_bp.route("/employee/name", methods=['GET'])653def socfaker_employee_name():654 """655 Returns First and Last name of an employee656 Returns:657 str: Returns a random First and Last name of an employee658 659 """660 if validate_request(request):661 return { 'value': socfaker.employee.name }662@api_bp.route("/employee/phone_number", methods=['GET'])663def socfaker_employee_phone_number():664 """665 Phone number of an employee666 Returns:667 str: Returns a random phone number of an employee668 669 """670 if validate_request(request):671 return { 'value': socfaker.employee.phone_number }672@set_renderers(HTMLRenderer)673@api_bp.route("/employee/photo", methods=['GET'])674def socfaker_employee_photo():675 """676 Photo URL of an employee677 Returns:678 str: Returns a URL of a random photo for the employee679 680 """681 if validate_request(request):682 return f'<html><body><h1><img src="{socfaker.employee.photo}</h1></body></html>'683@api_bp.route("/employee/ssn", methods=['GET'])684def socfaker_employee_ssn():685 """686 SSN of an employee687 Returns:688 str: Returns the SSN of an employee689 690 """691 if validate_request(request):692 return { 'value': socfaker.employee.ssn }693@api_bp.route("/employee/title", methods=['GET'])694def socfaker_employee_title():695 """696 Employee title697 Returns:698 str: Returns a random employee title699 700 """701 if validate_request(request):702 return { 'value': socfaker.employee.title }703@api_bp.route("/employee/user_id", methods=['GET'])704def socfaker_employee_user_id():705 """706 User ID of an employee707 Returns:708 str: Returns a random user ID of an employee709 710 """711 if validate_request(request):712 return { 'value': socfaker.employee.user_id }713@api_bp.route("/employee/username", methods=['GET'])714def socfaker_employee_username():715 """716 Username of an employee717 Returns:718 str: Returns the username of an employee719 720 """721 if validate_request(request):722 return { 'value': socfaker.employee.username }723### EMPLOYEE ROUTES ###724### FILE ROUTES ###725@api_bp.route("/file", methods=['GET'])726def socfaker_socfaker_file():727 """728 A file object729 Returns:730 File: Returns an object with properties about a fake file object731 732 """733 if validate_request(request):734 return jsonify(str(socfaker.file))735@api_bp.route("/file/accessed_timestamp", methods=['GET'])736def socfaker_file_accessed_timestamp():737 """738 The last accessed timestamp of a file in the past739 Returns:740 str: A randomly generated accessed timestamp is ISO 8601 format741 742 """743 if validate_request(request):744 return { 'value': socfaker.file.accessed_timestamp }745@api_bp.route("/file/attributes", methods=['GET'])746def socfaker_file_attributes():747 """748 Attributes of the file 749 Returns:750 list: A randomly selected list of file attributes751 752 """753 if validate_request(request):754 return jsonify(str(socfaker.file.attributes))755@api_bp.route("/file/build_version", methods=['GET'])756def socfaker_file_build_version():757 """758 A build version of a file759 Returns:760 str: Returns the last digit in the version string761 762 """763 if validate_request(request):764 return { 'value': socfaker.file.build_version }765@api_bp.route("/file/checksum", methods=['GET'])766def socfaker_file_checksum():767 """768 A MD5 checksum of a file769 Returns:770 str: Returns a MD5 of the file771 772 """773 if validate_request(request):774 return { 'value': socfaker.file.checksum }775@api_bp.route("/file/directory", methods=['GET'])776def socfaker_file_directory():777 """778 The directory of a file779 Returns:780 str: The directory of a file781 782 """783 if validate_request(request):784 return { 'value': socfaker.file.directory }785@api_bp.route("/file/drive_letter", methods=['GET'])786def socfaker_file_drive_letter():787 """788 The drive letter of a file789 Returns:790 str: A randomly selected drive letter of a file791 792 """793 if validate_request(request):794 return { 'value': socfaker.file.drive_letter }795@api_bp.route("/file/extension", methods=['GET'])796def socfaker_file_extension():797 """798 The extension of a file799 Returns:800 str: The extension of a file801 802 """803 if validate_request(request):804 return { 'value': socfaker.file.extension }805@api_bp.route("/file/full_path", methods=['GET'])806def socfaker_file_full_path():807 """808 The full path of a file809 Returns:810 str: A randomly selected file name path811 812 """813 if validate_request(request):814 return { 'value': socfaker.file.full_path }815@api_bp.route("/file/gid", methods=['GET'])816def socfaker_file_gid():817 """818 The GID of a file819 Returns:820 str: A randomly generated GID of a file821 822 """823 if validate_request(request):824 return { 'value': socfaker.file.gid }825@api_bp.route("/file/hashes", methods=['GET'])826def socfaker_file_hashes():827 """828 A dict containing MD5, SHA1, and SHA256 hashes829 Returns:830 str: A randomly generated dict containing MD5, SHA1, and SHA256 hashes831 832 """833 if validate_request(request):834 return { 'value': socfaker.file.hashes }835@api_bp.route("/file/install_scope", methods=['GET'])836def socfaker_file_install_scope():837 """838 The install scope of a file839 Returns:840 str: Returns a random install scope of user-local or global for a file841 842 """843 if validate_request(request):844 return { 'value': socfaker.file.install_scope }845@api_bp.route("/file/md5", methods=['GET'])846def socfaker_file_md5():847 """848 A random generated MD5 hash849 Returns:850 str: A randomly generated MD5 file hash851 852 """853 if validate_request(request):854 return { 'value': socfaker.file.md5 }855@api_bp.route("/file/mime_type", methods=['GET'])856def socfaker_file_mime_type():857 """858 The mime type of a file859 Returns:860 str: A randomly selected file mime type861 862 """863 if validate_request(request):864 return { 'value': socfaker.file.mime_type }865@api_bp.route("/file/name", methods=['GET'])866def socfaker_file_name():867 """868 The name of a file869 Returns:870 str: A randomly selected file name871 872 """873 if validate_request(request):874 return { 'value': socfaker.file.name }875@api_bp.route("/file/sha1", methods=['GET'])876def socfaker_file_sha1():877 """878 A random generated SHA1 hash879 Returns:880 str: A randomly generated SHA1 file hash881 882 """883 if validate_request(request):884 return { 'value': socfaker.file.sha1 }885@api_bp.route("/file/sha256", methods=['GET'])886def socfaker_file_sha256():887 """888 A random generated SHA256 hash889 Returns:890 str: A randomly generated SHA256 file hash891 892 """893 if validate_request(request):894 return { 'value': socfaker.file.sha256 }895@api_bp.route("/file/signature", methods=['GET'])896def socfaker_file_signature():897 """898 The file signature899 Returns:900 str: Returns the signature name of Microsoft Windows901 902 """903 if validate_request(request):904 return { 'value': socfaker.file.signature }905@api_bp.route("/file/signature_status", methods=['GET'])906def socfaker_file_signature_status():907 """908 The signature status of a file909 Returns:910 str: A randomly selected signature status of Verified, Unknown, or Counterfit911 912 """913 if validate_request(request):914 return { 'value': socfaker.file.signature_status }915@api_bp.route("/file/signed", methods=['GET'])916def socfaker_file_signed():917 """918 Whether the file is signed or not919 Returns:920 str: Returns whether a file is signed or not921 922 """923 if validate_request(request):924 return { 'value': socfaker.file.signed }925@api_bp.route("/file/size", methods=['GET'])926def socfaker_file_size():927 """928 The file size929 Returns:930 str: A randomly generated file size931 932 """933 if validate_request(request):934 return { 'value': socfaker.file.size }935@api_bp.route("/file/timestamp", methods=['GET'])936def socfaker_file_timestamp():937 """938 The timestamp of a file in the past939 Returns:940 str: A randomly generated file timestamp is ISO 8601 format941 942 """943 if validate_request(request):944 return { 'value': socfaker.file.timestamp }945@api_bp.route("/file/type", methods=['GET'])946def socfaker_file_type():947 """948 The type of a file949 Returns:950 str: A randomly selected file type951 952 """953 if validate_request(request):954 return { 'value': socfaker.file.type }955@api_bp.route("/file/version", methods=['GET'])956def socfaker_file_version():957 """958 A random generated file version string959 Returns:960 str: A randomly generated file version string961 962 """963 if validate_request(request):964 return { 'value': socfaker.file.version }965### FILE ROUTES ###966@api_bp.route("/http", methods=['GET'])967def socfaker_socfaker_http():968 """969 Data related to HTTP requests and responses970 Returns:971 HTTP: Returns an object with properties about HTTP requests and responses972 973 """974 if validate_request(request):975 return jsonify(str(socfaker.http))976@api_bp.route("/http/bytes", methods=['GET'])977def socfaker_http_bytes():978 """979 Random bytes for an HTTP request980 Returns:981 int: Random bytes for an HTTP request982 983 """984 if validate_request(request):985 return { 'value': socfaker.http.bytes }986@api_bp.route("/http/method", methods=['GET'])987def socfaker_http_method():988 """989 A randomly selected method for an HTTP request or response990 Returns:991 str: A randomly selected method for an HTTP request or response992 993 """994 if validate_request(request):995 return { 'value': socfaker.http.method }996@api_bp.route("/http/request", methods=['GET'])997def socfaker_http_request():998 """999 A randomly generated request dictionary based on Elastic ECS format1000 Returns:1001 dict: A random request dictionary containing body, bytes, method and referrer information 1002 1003 """1004 if validate_request(request):1005 return { 'value': socfaker.http.request }1006@api_bp.route("/http/response", methods=['GET'])1007def socfaker_http_response():1008 """1009 A randomly generated response dictionary based on Elastic ECS format1010 Returns:1011 dict: A random response dictionary containing body, bytes, and status code information 1012 1013 """1014 if validate_request(request):1015 return { 'value': socfaker.http.response }1016@api_bp.route("/http/status_code", methods=['GET'])1017def socfaker_http_status_code():1018 """1019 A randomly selected status_code for an HTTP request or response1020 Returns:1021 str: A randomly selected status code for an HTTP request or response1022 1023 """1024 if validate_request(request):1025 return { 'value': socfaker.http.status_code }1026### FILE ROUTES ###1027### LOCATION ROUTES ###1028@api_bp.route("/location", methods=['GET'])1029def socfaker_socfaker_location():1030 """1031 Fake location data1032 Returns:1033 Location: Returns an object with properties containing location information1034 1035 """1036 if validate_request(request):1037 return jsonify(str(socfaker.location))1038@api_bp.route("/location/city", methods=['GET'])1039def socfaker_location_city():1040 """1041 A random city1042 Returns:1043 str: Returns a random city name1044 1045 """1046 if validate_request(request):1047 return { 'value': socfaker.location.city }1048@api_bp.route("/location/continent", methods=['GET'])1049def socfaker_location_continent():1050 """1051 A random continent1052 Returns:1053 str: Returns a random continent1054 1055 """1056 if validate_request(request):1057 return { 'value': socfaker.location.continent }1058@api_bp.route("/location/country", methods=['GET'])1059def socfaker_location_country():1060 """1061 A random country1062 Returns:1063 str: Returns a random country1064 1065 """1066 if validate_request(request):1067 return { 'value': socfaker.location.country }1068@api_bp.route("/location/country_code", methods=['GET'])1069def socfaker_location_country_code():1070 """1071 A random country code1072 Returns:1073 str: Returns a random country code1074 1075 """1076 if validate_request(request):1077 return { 'value': socfaker.location.country_code }1078@api_bp.route("/location/latitude", methods=['GET'])1079def socfaker_location_latitude():1080 """1081 Random Latitude coordinates1082 Returns:1083 str: Returns a random latitude coordinates1084 1085 """1086 if validate_request(request):1087 return { 'value': socfaker.location.latitude }1088@api_bp.route("/location/longitude", methods=['GET'])1089def socfaker_location_longitude():1090 """1091 Random Longitude coordinates1092 Returns:1093 str: Returns a random longitude coordinates1094 1095 """1096 if validate_request(request):1097 return { 'value': socfaker.location.longitude }1098### LOCATION ROUTES ###1099### LOGS ROUTES ###1100@api_bp.route("/logs/syslog", methods=['POST'])1101def socfaker_logs_syslog(type='ransomware', count=1):1102 """1103 The syslog method generates random syslog messages based on the type and count requested1104 Args:1105 type (str, optional): Generates random syslog files with ransomware traffic added randomly. Defaults to 'ransomware'.1106 count (int, optional): The number of logs to generate. Defaults to 10.1107 Returns:1108 list: Returns a list of generated syslogs1109 1110 """1111 if validate_request(request):1112 return jsonify(str(socfaker.logs.syslog(type=type, count=count)))1113@api_bp.route("/logs/windows/eventlog", methods=['POST'])1114def socfaker_windows_eventlog(count=1, computer_name=None, os_version='Windows', json=False):1115 """1116 Generate fake event logs based on the provided inputs1117 Args:1118 count (int, optional): The number of logs to generate. Defaults to 1.1119 computer_name (str, optional): A computer name to use when generating logs. Defaults to None.1120 os_version (str, optional): The Operating System version to use when generating logs. Defaults to 'Windows'.1121 json (bool, optional): Whether or not to if validate_request(request):1122 return data as JSON or XML. Defaults to False.1123 Returns:1124 list: Returns a list of generated Windows Event Logs1125 1126 """1127 if validate_request(request):1128 return jsonify(str(socfaker.logs.windows.eventlog(count=count, computer_name=computer_name, os_version=os_version, json=json)))1129@api_bp.route("/logs/windows/sysmon", methods=['POST'])1130def socfaker_sysmon_get(count=1):1131 """1132 Returns a list of generated sysmon logs1133 Args:1134 count (int, optional): The number of sysmon logs to return. Defaults to 21.1135 Returns:1136 list: A list of generated sysmon logs1137 1138 """1139 if validate_request(request):1140 return jsonify(str(socfaker.logs.windows.sysmon(count=count)))1141### LOGS ROUTES ###1142### NETWORK ROUTES ###1143@api_bp.route("/network", methods=['GET'])1144def socfaker_socfaker_network():1145 """1146 Access common generated network information1147 Returns:1148 Network: Returns an object with properties containing general1149 or common network information1150 1151 """1152 if validate_request(request):1153 return jsonify(str(socfaker.network))1154@api_bp.route("/network/get_cidr_range", methods=['POST'])1155def socfaker_network_get_cidr_range(cidr):1156 """1157 Returns an IPv4 range1158 Returns:1159 str: Returns CIDR range for an IPv4 address.1160 1161 """1162 if validate_request(request):1163 return jsonify(str(socfaker.network.get_cidr_range(cidr=cidr)))1164@api_bp.route("/network/ipv4", methods=['GET'])1165def socfaker_network_ipv4():1166 """1167 Returns an IPv4 IP Address1168 Returns:1169 str: Returns an IPv4 Address. If private the address will be 10.x.x.x or 172.x.x.x or 192.168.x.x.1170 1171 """1172 if validate_request(request):1173 return { 'value': socfaker.network.ipv4 }1174@api_bp.route("/network/ipv6", methods=['GET'])1175def socfaker_network_ipv6():1176 """1177 Returns an IPv6 IP Address1178 Returns:1179 dict: Returns a compressed and exploded IPv6 Address.1180 1181 """1182 if validate_request(request):1183 return { 'value': socfaker.network.ipv6 }1184@api_bp.route("/network/netbios", methods=['GET'])1185def socfaker_network_netbios():1186 """1187 Returns a netbios name1188 Returns:1189 str: Returns a random netbios name1190 1191 """1192 if validate_request(request):1193 return { 'value': socfaker.network.netbios }1194@api_bp.route("/network/port", methods=['GET'])1195def socfaker_network_port():1196 """1197 Returns a dictionary map of a port and it's common name1198 Returns:1199 dict: A random port and it's common name1200 1201 """1202 if validate_request(request):1203 return jsonify(str(socfaker.network.port))1204@api_bp.route("/network/protocol", methods=['GET'])1205def socfaker_network_protocol():1206 """1207 Random network protocol1208 Returns:1209 dict: Returns a random network protocol and protocol number1210 1211 """1212 if validate_request(request):1213 return jsonify(str(socfaker.network.protocol))1214### NETWORK ROUTES ###1215### OPERATING_SYSTEM ROUTES ###1216@api_bp.route("/operating_system", methods=['GET'])1217def socfaker_socfaker_operating_system():1218 """1219 Fake operating system information1220 Returns:1221 OperatingSystem: Returns an object with properties containing1222 Operating System information1223 1224 """1225 if validate_request(request):1226 return jsonify(str(socfaker.operating_system))1227@api_bp.route("/operating_system/family", methods=['GET'])1228def socfaker_operatingsystem_family():1229 """1230 The operating system family1231 Returns:1232 str: Returns a random operating system family1233 1234 """1235 if validate_request(request):1236 return { 'value': socfaker.operating_system.family }1237@api_bp.route("/operating_system/fullname", methods=['GET'])1238def socfaker_operatingsystem_fullname():1239 """1240 The operating system full name1241 Returns:1242 str: Returns a random operating system full name including name, type and version1243 1244 """1245 if validate_request(request):1246 return { 'value': socfaker.operating_system.fullname }1247@api_bp.route("/operating_system/name", methods=['GET'])1248def socfaker_operatingsystem_name():1249 """1250 The operating system name1251 Returns:1252 str: Returns a random operating system name1253 1254 """1255 if validate_request(request):1256 return { 'value': socfaker.operating_system.name }1257@api_bp.route("/operating_system/version", methods=['GET'])1258def socfaker_operatingsystem_version():1259 """1260 The operating system version1261 Returns:1262 str: Returns a random operating system version1263 1264 """1265 if validate_request(request):1266 return { 'value': socfaker.operating_system.version }1267### OPERATING_SYSTEM ROUTES ###1268### ORGANIZATION ROUTES ###1269@api_bp.route("/organization", methods=['GET'])1270def socfaker_socfaker_organization():1271 """1272 Fake organization information1273 Returns:1274 Organization: Returns an object with properties containing common1275 organization information1276 1277 """1278 if validate_request(request):1279 return jsonify(str(socfaker.organization))1280@api_bp.route("/organization/division", methods=['GET'])1281def socfaker_organization_division():1282 """1283 Returns a division within an organization1284 Returns:1285 str: Returns a division within an organization1286 1287 """1288 if validate_request(request):1289 return { 'value': socfaker.organization.division }1290@api_bp.route("/organization/domain", methods=['GET'])1291def socfaker_organization_domain():1292 """1293 Returns a domain name based on the organization name1294 Returns:1295 str: Returns a domain name based on the organizational name1296 1297 """1298 if validate_request(request):1299 return { 'value': socfaker.organization.domain }1300@api_bp.route("/organization/name", methods=['GET'])1301def socfaker_organization_name():1302 """1303 A randomly generated organization name1304 Returns:1305 str: A randomly generated organization name1306 1307 """1308 if validate_request(request):1309 return { 'value': socfaker.organization.name }1310@api_bp.route("/organization/title", methods=['GET'])1311def socfaker_organization_title():1312 """1313 Returns a title within an organization1314 Returns:1315 str: Returns a title within an organization1316 1317 """1318 if validate_request(request):1319 return { 'value': socfaker.organization.title }1320### ORGANIZATION ROUTES ###1321### PCAP ROUTES ###1322@api_bp.route("/pcap", methods=['POST'])1323def socfaker_pcap_generate(count=1, port=9600):1324 """1325 None1326 """1327 if validate_request(request):1328 return jsonify(str(socfaker.pcap(count=count)))1329### PCAP ROUTES ###1330### REGISTRY ROUTES ###1331@api_bp.route("/registry", methods=['GET'])1332def socfaker_socfaker_registry():1333 """1334 Fake registry information1335 Returns:1336 Registry: Returns an object with properties containing1337 common Windows registry information1338 1339 """1340 if validate_request(request):1341 return jsonify(str(socfaker.registry))1342@api_bp.route("/registry/hive", methods=['GET'])1343def socfaker_registry_hive():1344 """1345 A random registry hive1346 Returns:1347 str: Returns a random registry hive1348 1349 """1350 if validate_request(request):1351 return { 'value': socfaker.registry.hive }1352@api_bp.route("/registry/key", methods=['GET'])1353def socfaker_registry_key():1354 """1355 A random registry key1356 Returns:1357 str: Returns a random registry key1358 1359 """1360 if validate_request(request):1361 return { 'value': socfaker.registry.key }1362@api_bp.route("/registry/path", methods=['GET'])1363def socfaker_registry_path():1364 """1365 A full registry path1366 1367 Returns:1368 str: Returns a random full registry path1369 1370 """1371 if validate_request(request):1372 return { 'value': socfaker.registry.path }1373@api_bp.route("/registry/root", methods=['GET'])1374def socfaker_registry_root():1375 """1376 A random registry root path string1377 Returns:1378 str: Returns a random registry root path string1379 1380 """1381 if validate_request(request):1382 return { 'value': socfaker.registry.root }1383@api_bp.route("/registry/type", methods=['GET'])1384def socfaker_registry_type():1385 """1386 A random registry key type1387 Returns:1388 str: A random registry key type1389 1390 """1391 if validate_request(request):1392 return { 'value': socfaker.registry.type }1393@api_bp.route("/registry/value", methods=['GET'])1394def socfaker_registry_value():1395 """1396 A random registry key value1397 Returns:1398 str: A random registry key value1399 1400 """1401 if validate_request(request):1402 return { 'value': socfaker.registry.value }1403### REGISTRY ROUTES ###1404### TIMESTAMP ROUTES ###1405@api_bp.route("/timestamp", methods=['GET'])1406def socfaker_socfaker_timestamp():1407 """1408 Fake timestamp information1409 Returns:1410 Timestamp: Returns an object with methods to generate fake1411 timestamps1412 1413 """1414 if validate_request(request):1415 return jsonify(str(socfaker.timestamp))1416@api_bp.route("/timestamp/date_string", methods=['POST'])1417def socfaker_timestamp_date_string(years=81, months=5, days=162):1418 """1419 Returns a date string1420 Args:1421 years ([type], optional): The number of years subtracted from the current time. Defaults to random.randint(18,85).1422 months ([type], optional): The number of months subtracted from the current time. Defaults to random.randint(1,12).1423 days ([type], optional): The number of days subtracted from the current time. Defaults to random.randint(1,365).1424 Returns:1425 str: An date string for the generated timestamp1426 1427 """1428 if validate_request(request):1429 return {'value': socfaker.timestamp.date_string(years=years, months=months, days=days)}1430@api_bp.route("/timestamp/in_the_future", methods=['POST'])1431def socfaker_timestamp_in_the_future(years=0, months=0, days=4, hours=13, minutes=25, seconds=3):1432 """1433 Generates a timestamp in the future1434 Args:1435 years (int, optional): The number of years to add from the current time. Defaults to 0.1436 months ([type], optional): The number of months to add from the current time. Defaults to random.randint(0,3).1437 days ([type], optional): The number of days to add from the current time. Defaults to random.randint(1,15).1438 hours ([type], optional): The number of hours to add from the current time. Defaults to random.randint(1,24).1439 minutes ([type], optional): The number of minutes to add from the current time. Defaults to random.randint(1,60).1440 seconds ([type], optional): The number of seconds to add from the current time. Defaults to random.randint(1,60).1441 Returns:1442 str: Returns an ISO 8601 timestamp string1443 1444 """1445 if validate_request(request):1446 return {'value': socfaker.timestamp.in_the_future(years=years, months=months, days=days, hours=hours, minutes=minutes, seconds=seconds)}1447@api_bp.route("/timestamp/in_the_past", methods=['POST'])1448def socfaker_timestamp_in_the_past(years=0, months=2, days=6, hours=19, minutes=37, seconds=5):1449 """1450 Generates a timestamp in the past1451 Args:1452 years (int, optional): The number of years to subtract from the current time. Defaults to 0.1453 months ([type], optional): The number of months to subtract from the current time. Defaults to random.randint(0,3).1454 days ([type], optional): The number of days to subtract from the current time. Defaults to random.randint(1,15).1455 hours ([type], optional): The number of hours to subtract from the current time. Defaults to random.randint(1,24).1456 minutes ([type], optional): The number of minutes to subtract from the current time. Defaults to random.randint(1,60).1457 seconds ([type], optional): The number of seconds to subtract from the current time. Defaults to random.randint(1,60).1458 Returns:1459 str: Returns an ISO 8601 timestamp string1460 1461 """1462 if validate_request(request):1463 return {'value': socfaker.timestamp.in_the_past(years=years, months=months, days=days, hours=hours, minutes=minutes, seconds=seconds)}1464@api_bp.route("/timestamp/current", methods=['GET'])1465def socfaker_timestamp_current():1466 """1467 The current timestamp1468 Returns:1469 str: Returns the current timestamp in ISO 8601 format1470 1471 """1472 if validate_request(request):1473 return { 'value': socfaker.timestamp.current }1474### TIMESTAMP ROUTES ###1475### USER_AGENT ROUTES ###1476@api_bp.route("/user_agent", methods=['GET'])1477def socfaker_socfaker_user_agent():1478 """1479 Fake user agent information1480 Returns:1481 UserAgent: Returns an object with methods to generate fake1482 user agent strings1483 1484 """1485 if validate_request(request):1486 return jsonify(str(socfaker.user_agent))1487### USER_AGENT ROUTES ###1488### VULNERABILITY ROUTES ###1489@api_bp.route("/vulnerability/critical", methods=['GET'])1490def socfaker_vulnerability_critical():1491 """1492 Returns a list of critical vulnerabilities based on counts provided when instantiating the class1493 Returns:1494 list: Returns a list of critical vulnerabilities1495 1496 """1497 if validate_request(request):1498 return jsonify(str(socfaker.vulnerability().critical))1499@api_bp.route("/vulnerability/data", methods=['GET'])1500def socfaker_vulnerability_data():1501 """1502 Returns all vulnerability data1503 Returns:1504 json: Returns json of all vulnerability data1505 1506 """1507 if validate_request(request):1508 return jsonify(str(socfaker.vulnerability().data))1509@api_bp.route("/vulnerability/high", methods=['GET'])1510def socfaker_vulnerability_high():1511 """1512 Returns a list of high vulnerabilities based on counts provided when instantiating the class1513 Returns:1514 list: Returns a list of high vulnerabilities1515 1516 """1517 if validate_request(request):1518 return jsonify(str(socfaker.vulnerability().high))1519@api_bp.route("/vulnerability/informational", methods=['GET'])1520def socfaker_vulnerability_informational():1521 """1522 Returns a list of informational vulnerabilities based on counts provided when instantiating the class1523 Returns:1524 list: Returns a list of informational vulnerabilities1525 1526 """1527 if validate_request(request):1528 return jsonify(str(socfaker.vulnerability().informational))1529@api_bp.route("/vulnerability/low", methods=['GET'])1530def socfaker_vulnerability_low():1531 """1532 Returns a list of low vulnerabilities based on counts provided when instantiating the class1533 Returns:1534 list: Returns a list of low vulnerabilities1535 1536 """1537 if validate_request(request):1538 return jsonify(str(socfaker.vulnerability().low))1539@api_bp.route("/vulnerability/medium", methods=['GET'])1540def socfaker_vulnerability_medium():1541 """1542 Returns a list of medium vulnerabilities based on counts provided when instantiating the class1543 Returns:1544 list: Returns a list of medium vulnerabilities1545 1546 """1547 if validate_request(request):1548 return jsonify(str(socfaker.vulnerability().medium))1549@api_bp.route("/vulnerability/host", methods=['GET'])1550def socfaker_vulnerability_host():1551 """1552 Retrieve information about hosts found in a vulnerability scan1553 Returns:1554 VulnerabilityHost: Returns an object with properties for a vulnerable host1555 1556 """1557 if validate_request(request):1558 return jsonify(str(socfaker.vulnerability().host))1559@api_bp.route("/vulnerability/host/checks_considered", methods=['GET'])1560def socfaker_vulnerabilityhost_checks_considered():1561 """1562 A count of how many vulnerability checks were considered for a host1563 Returns:1564 int: Returns a randomly integer for checks considered during a vulnerability scan1565 1566 """1567 if validate_request(request):1568 return { 'value': socfaker.vulnerability().host.checks_considered }1569@api_bp.route("/vulnerability/host/critical", methods=['GET'])1570def socfaker_vulnerabilityhost_critical():1571 """1572 Returns a list of critical vulnerabilities based on counts provided when instantiating the class1573 Returns:1574 list: Returns a list of critical vulnerabilities1575 1576 """1577 if validate_request(request):1578 return jsonify(str(socfaker.vulnerability().host.critical))1579@api_bp.route("/vulnerability/host/data", methods=['GET'])1580def socfaker_vulnerabilityhost_data():1581 """1582 Returns all vulnerability data1583 Returns:1584 json: Returns json of all vulnerability data1585 1586 """1587 if validate_request(request):1588 return jsonify(str(socfaker.vulnerability().host.data))1589@api_bp.route("/vulnerability/host/fqdn", methods=['GET'])1590def socfaker_vulnerabilityhost_fqdn():1591 """1592 A host FQDN1593 Returns:1594 str: Returns a randomly generated DNS name1595 1596 """1597 if validate_request(request):1598 return { 'value': socfaker.vulnerability().host.fqdn }1599@api_bp.route("/vulnerability/host/high", methods=['GET'])1600def socfaker_vulnerabilityhost_high():1601 """1602 Returns a list of high vulnerabilities based on counts provided when instantiating the class1603 Returns:1604 list: Returns a list of high vulnerabilities1605 1606 """1607 if validate_request(request):1608 return jsonify(str(socfaker.vulnerability().host.high))1609@api_bp.route("/vulnerability/host/host", methods=['GET'])1610def socfaker_vulnerabilityhost_host():1611 """1612 Retrieve information about hosts found in a vulnerability scan1613 Returns:1614 VulnerabilityHost: Returns an object with properties for a vulnerable host1615 1616 """1617 if validate_request(request):1618 return jsonify(str(socfaker.vulnerability().host.host))1619@api_bp.route("/vulnerability/host/host_id", methods=['GET'])1620def socfaker_vulnerabilityhost_host_id():1621 """1622 Returns a random host ID1623 Returns:1624 int: Returns a random host ID1625 1626 """1627 if validate_request(request):1628 return { 'value': socfaker.vulnerability().host.host_id }1629@api_bp.route("/vulnerability/host/informational", methods=['GET'])1630def socfaker_vulnerabilityhost_informational():1631 """1632 Returns a list of informational vulnerabilities based on counts provided when instantiating the class1633 Returns:1634 list: Returns a list of informational vulnerabilities1635 1636 """1637 if validate_request(request):1638 return jsonify(str(socfaker.vulnerability().host.informational))1639@api_bp.route("/vulnerability/host/low", methods=['GET'])1640def socfaker_vulnerabilityhost_low():1641 """1642 Returns a list of low vulnerabilities based on counts provided when instantiating the class1643 Returns:1644 list: Returns a list of low vulnerabilities1645 1646 """1647 if validate_request(request):1648 return jsonify(str(socfaker.vulnerability().host.low))1649@api_bp.route("/vulnerability/host/mac_address", methods=['GET'])1650def socfaker_vulnerabilityhost_mac_address():1651 """1652 A host MAC Address1653 Returns:1654 str: Returns a randomly generated MAC Address1655 1656 """1657 if validate_request(request):1658 return {'value': socfaker.vulnerability().host.mac_address}1659@api_bp.route("/vulnerability/host/medium", methods=['GET'])1660def socfaker_vulnerabilityhost_medium():1661 """1662 Returns a list of medium vulnerabilities based on counts provided when instantiating the class1663 Returns:1664 list: Returns a list of medium vulnerabilities1665 1666 """1667 if validate_request(request):1668 return jsonify(str(socfaker.vulnerability().host.medium))1669@api_bp.route("/vulnerability/host/name", methods=['GET'])1670def socfaker_vulnerabilityhost_name():1671 """1672 Returns a computer name1673 Returns:1674 str: Returns a randomly generated computer name1675 1676 """1677 if validate_request(request):1678 return { 'value': socfaker.vulnerability().host.name }1679@api_bp.route("/vulnerability/host/percentage", methods=['GET'])1680def socfaker_vulnerabilityhost_percentage():1681 """1682 Returns a percentage of vulnerabilities found on a host1683 Returns:1684 dict: Returns a percentage of vulnerabilities found on a host1685 1686 """1687 if validate_request(request):1688 return {'value': socfaker.vulnerability().host.percentage}1689@api_bp.route("/vulnerability/host/scan", methods=['GET'])1690def socfaker_vulnerabilityhost_scan():1691 """1692 A vulnerability scan1693 Returns:1694 VulnerabilityScan: Returns a vulnerability scan object with properties related a vulnerability scan1695 1696 """1697 if validate_request(request):1698 return jsonify(str(socfaker.vulnerability().host.scan))1699@api_bp.route("/vulnerability/host/total_score", methods=['GET'])1700def socfaker_vulnerabilityhost_total_score():1701 """1702 The total score of a host during a vulnerability scan1703 Returns:1704 int: The total score for a host during a vulnerability scan1705 1706 """1707 if validate_request(request):1708 return { 'value': socfaker.vulnerability().host.total_score }1709@api_bp.route("/vulnerability/scan", methods=['POST'])1710def socfaker_vulnerability_scan(host_count=1, critical=1, high=1, medium=1, low=1, informational=1):1711 if validate_request(request):1712 return jsonify(str(socfaker.vulnerability(host_count=host_count, critical=critical, high=high, medium=medium, low=low, informational=informational).scan))1713@api_bp.route("/vulnerability/scan/end_time", methods=['GET'])1714def socfaker_vulnerabilityscan_end_time():1715 """1716 End time of a vulnerability scan1717 Returns:1718 str: The end time of a vulnerability scan in the future1719 1720 """1721 if validate_request(request):1722 return { 'value': socfaker.vulnerability().scan.end_time }1723@api_bp.route("/vulnerability/scan/host_count", methods=['GET'])1724def socfaker_vulnerabilityscan_host_count():1725 """1726 A vulnerability scan host count1727 Returns:1728 int: The provided vulnerability scan host count1729 1730 """1731 if validate_request(request):1732 return { 'value': socfaker.vulnerability().scan.host_count }1733@api_bp.route("/vulnerability/scan/id", methods=['GET'])1734def socfaker_vulnerabilityscan_id():1735 """1736 A vulnerability scan ID1737 Returns:1738 int: Returns a random vulnerability scan ID1739 1740 """1741 if validate_request(request):1742 return { 'value': socfaker.vulnerability().scan.id }1743@api_bp.route("/vulnerability/scan/ip_list", methods=['GET'])1744def socfaker_vulnerabilityscan_ip_list():1745 """1746 A list of host IPs during a Vulnerability scan1747 Returns:1748 list: A randomly generated list of host IPs during a vulnerability scan1749 1750 """1751 if validate_request(request):1752 return { 'value': socfaker.vulnerability().scan.ip_list }1753@api_bp.route("/vulnerability/scan/name", methods=['GET'])1754def socfaker_vulnerabilityscan_name():1755 """1756 A vulnerability scan name1757 Returns:1758 str: A randomly selected vulnerability scan name1759 1760 """1761 if validate_request(request):1762 return { 'value': socfaker.vulnerability().scan.name }1763@api_bp.route("/vulnerability/scan/scan_uuid", methods=['GET'])1764def socfaker_vulnerabilityscan_scan_uuid():1765 """1766 A vulnerability scan UUID1767 Returns:1768 str: A random UUID for a vulnerability scan1769 1770 """1771 if validate_request(request):1772 return { 'value': socfaker.vulnerability().scan.scan_uuid }1773@api_bp.route("/vulnerability/scan/scanner_name", methods=['GET'])1774def socfaker_vulnerabilityscan_scanner_name():1775 """1776 A vulnerability scaner name1777 Returns:1778 str: Returns a random vulnerability scanner name1779 1780 """1781 if validate_request(request):1782 return { 'value': socfaker.vulnerability().scan.scanner_name }1783@api_bp.route("/vulnerability/scan/scanner_uuid", methods=['GET'])1784def socfaker_vulnerabilityscan_scanner_uuid():1785 """1786 A vulnerability scanner UUID1787 Returns:1788 str: A random UUID for a scanner1789 1790 """1791 if validate_request(request):1792 return { 'value': socfaker.vulnerability().scan.scanner_uuid }1793@api_bp.route("/vulnerability/scan/start_time", methods=['GET'])1794def socfaker_vulnerabilityscan_start_time():1795 """1796 Start time of a vulnerability scan1797 Returns:1798 str: The start time of a vulnerability scan in the past1799 1800 """1801 if validate_request(request):1802 return { 'value': socfaker.vulnerability().scan.start_time }1803@api_bp.route("/vulnerability/scan/status", methods=['GET'])1804def socfaker_vulnerabilityscan_status():1805 """1806 Vulnerability scan status1807 Returns:1808 str: A randomly selected scan status1809 1810 """1811 if validate_request(request):1812 return { 'value': socfaker.vulnerability().scan.status }1813@api_bp.route("/vulnerability/scan/type", methods=['GET'])1814def socfaker_vulnerabilityscan_type():1815 """1816 The vulnerability scan type1817 Returns:1818 str: A randomly selected vulnerability scan type1819 1820 """1821 if validate_request(request):1822 return { 'value': socfaker.vulnerability().scan.type }1823### VULNERABILITY ROUTES ###1824### WORDS ROUTES ###1825@api_bp.route("/words", methods=['GET'])1826def socfaker_socfaker_words():1827 """1828 Used to create fake words or strings1829 Returns:1830 Words: Returns an object with methods to generate fake words and strings1831 1832 """1833 if validate_request(request):1834 return {'value': socfaker.words }1835### WORDS ROUTES ###1836### PRODUCT ROUTES ###1837### PRODUCTS - AZURE - VM - DETAILS ###1838@api_bp.route("/products/azure/details", methods=['GET'])1839def socfaker_products_azure():1840 """1841 Azure class contains properties related to Azure products1842 Returns:1843 Azure: Microsoft Azure object containing properties and methods for generating data about Microsoft Azure products and services1844 1845 """1846 if validate_request(request):1847 return jsonify(str(socfaker.products.azure.vm.details))1848@api_bp.route("/products/azure/vm/details/location", methods=['GET'])1849def socfaker_azureproperties_location():1850 """1851 A location based on Microsoft Azure available locations1852 Returns:1853 str: Returns a Azure location1854 1855 """1856 if validate_request(request):1857 return { 'value': socfaker.products.azure.vm.details.location }1858@api_bp.route("/products/azure/vm/details/network_zone", methods=['GET'])1859def socfaker_azureproperties_network_zone():1860 """1861 Network zone type in Microsoft Azure1862 Returns:1863 str: Returns a random type for a network zone in Azure1864 1865 """1866 if validate_request(request):1867 return { 'value': socfaker.products.azure.vm.details.network_zone }1868@api_bp.route("/products/azure/vm/details/resource_group_id", methods=['GET'])1869def socfaker_azureproperties_resource_group_id():1870 """1871 Resource Group ID1872 Returns:1873 str: Returns a random resource group ID (GUID)1874 1875 """1876 if validate_request(request):1877 return { 'value': socfaker.products.azure.vm.details.resource_group_id }1878@api_bp.route("/products/azure/vm/details/resource_group_name", methods=['GET'])1879def socfaker_azureproperties_resource_group_name():1880 """1881 Resource Group Name in Azure1882 Returns:1883 str: Returns a three-word Resource Group name for Microsoft Azure1884 1885 """1886 if validate_request(request):1887 return { 'value': socfaker.products.azure.vm.details.resource_group_name }1888@api_bp.route("/products/azure/vm/details/score", methods=['GET'])1889def socfaker_azureproperties_score():1890 """1891 None1892 """1893 if validate_request(request):1894 return { 'value': socfaker.products.azure.vm.details.score }1895@api_bp.route("/products/azure/vm/details/vm_name", methods=['GET'])1896def socfaker_azureproperties_vm_name():1897 """1898 A Azure VM Name1899 Returns:1900 str: Returns a random Azure VM name1901 1902 """1903 if validate_request(request):1904 return { 'value': socfaker.products.azure.vm.details.vm_name }1905### PRODUCTS - AZURE - VM - DETAILS ###1906### PRODUCTS - AZURE - VM - METRICS ###1907@api_bp.route("/products/azure/vm/metrics", methods=['POST'])1908def socfaker_azurevmmetrics_generate():1909 """1910 Returns a list of dicts containing Azure VM Metrics1911 Returns:1912 list: A list of dicts containing metrics for an Azure VM1913 1914 """1915 if validate_request(request):1916 return jsonify(str(socfaker.products.azure.vm.metrics.generate()))1917@api_bp.route("/products/azure/vm/metrics/average", methods=['GET'])1918def socfaker_azurevmmetrics_average():1919 """1920 None1921 """1922 if validate_request(request):1923 return { 'value': socfaker.products.azure.vm.metrics.average }1924@api_bp.route("/products/azure/vm/metrics/graphs", methods=['GET'])1925def socfaker_azurevmmetrics_graphs():1926 """1927 None1928 """1929 if validate_request(request):1930 return { 'value': socfaker.products.azure.vm.metrics.graphs }1931### PRODUCTS - AZURE - VM - METRICS ###1932### PRODUCTS - AZURE - VM - TOPOLOGY ###1933@api_bp.route("/products/azure/vm/topology", methods=['GET'])1934def socfaker_azurevmtopology_get():1935 """1936 None1937 """1938 if validate_request(request):1939 return jsonify(str(socfaker.products.azure.vm.topology))1940### PRODUCTS - AZURE - VM - TOPOLOGY ###1941### PRODUCTS - ELASTIC ###1942@api_bp.route("/products/elastic", methods=['GET'])1943def socfaker_products_elastic():1944 """1945 Elastic class contains properties related to Elastic products1946 Returns:1947 Elastic: Elastic object containing properties and methods for generating data about Elastic products and services1948 1949 """1950 if validate_request(request):1951 return { 'value': socfaker.products.elastic }1952@api_bp.route("/products/elastic/document", methods=['POST'])1953def socfaker_elasticecs_get(count=1):1954 """1955 Generates one or more Elastic Common Schema documents1956 Args:1957 count (int, optional): The number of documents you want 1958 generated. Defaults to 1.1959 Returns:1960 list: A list of ECS Document dictionaries1961 1962 """1963 if validate_request(request):1964 return jsonify(str(socfaker.products.elastic.document.get(count=count)))1965@api_bp.route("/products/elastic/document/fields", methods=['GET'])1966def socfaker_elasticecs_fields():1967 """1968 None1969 """1970 if validate_request(request):1971 return jsonify(str(socfaker.products.elastic.document.fields))1972@api_bp.route("/products/elastic/document/fields/agent", methods=['GET'])1973def socfaker_elasticecsfields_agent():1974 """1975 Returns an ECS agent dictionary1976 Returns:1977 dict: Returns a dictionary of agent1978 fields/properties1979 1980 """1981 if validate_request(request):1982 return jsonify(str(socfaker.products.elastic.document.fields.agent))1983@api_bp.route("/products/elastic/document/fields/base", methods=['GET'])1984def socfaker_elasticecsfields_base():1985 """1986 Returns an ECS base fields dictionary1987 Returns:1988 dict: Returns a dictionary of ECS base1989 fields/properties1990 1991 """1992 if validate_request(request):1993 return jsonify(str(socfaker.products.elastic.document.fields.base))1994@api_bp.route("/products/elastic/document/fields/client", methods=['GET'])1995def socfaker_elasticecsfields_client():1996 """1997 Returns an ECS Client dictionary1998 Returns:1999 dict: Returns a dictionary of ECS 2000 client fields/properties2001 2002 """2003 if validate_request(request):2004 return jsonify(str(socfaker.products.elastic.document.fields.client))2005@api_bp.route("/products/elastic/document/fields/cloud", methods=['GET'])2006def socfaker_elasticecsfields_cloud():2007 """2008 Returns an ECS Cloud dictionary2009 Returns:2010 dict: Returns a dictionary of ECS 2011 Cloud fields/properties2012 2013 """2014 if validate_request(request):2015 return jsonify(str(socfaker.products.elastic.document.fields.cloud))2016@api_bp.route("/products/elastic/document/fields/code_signature", methods=['GET'])2017def socfaker_elasticecsfields_code_signature():2018 """2019 Returns an ECS Code Signature dictionary2020 Returns:2021 dict: Returns a dictionary of ECS 2022 Code Signature fields/properties2023 2024 """2025 if validate_request(request):2026 return jsonify(str(socfaker.products.elastic.document.fields.code_signature))2027@api_bp.route("/products/elastic/document/fields/container", methods=['GET'])2028def socfaker_elasticecsfields_container():2029 """2030 Returns an ECS container dictionary2031 Returns:2032 dict: Returns a dictionary of ECS 2033 container fields/properties2034 2035 """2036 if validate_request(request):2037 return jsonify(str(socfaker.products.elastic.document.fields.container))2038@api_bp.route("/products/elastic/document/fields/destination", methods=['GET'])2039def socfaker_elasticecsfields_destination():2040 """2041 Returns an ECS destination dictionary2042 Returns:2043 dict: Returns a dictionary of ECS 2044 destination fields/properties2045 2046 """2047 if validate_request(request):2048 return jsonify(str(socfaker.products.elastic.document.fields.destination))2049@api_bp.route("/products/elastic/document/fields/dll", methods=['GET'])2050def socfaker_elasticecsfields_dll():2051 """2052 Returns an ECS DLL dictionary2053 Returns:2054 dict: Returns a dictionary of ECS 2055 DLL fields/properties2056 2057 """2058 if validate_request(request):2059 return jsonify(str(socfaker.products.elastic.document.fields.dll))2060@api_bp.route("/products/elastic/document/fields/dns", methods=['GET'])2061def socfaker_elasticecsfields_dns():2062 """2063 Returns an ECS DNS dictionary2064 Returns:2065 dict: Returns a dictionary of ECS 2066 DNS fields/properties2067 2068 """2069 if validate_request(request):2070 return jsonify(str(socfaker.products.elastic.document.fields.dns))2071@api_bp.route("/products/elastic/document/fields/event", methods=['GET'])2072def socfaker_elasticecsfields_event():2073 """2074 Returns an ECS Event dictionary2075 Returns:2076 dict: Returns a dictionary of ECS 2077 Event fields/properties2078 2079 """2080 if validate_request(request):2081 return jsonify(str(socfaker.products.elastic.document.fields.event))2082@api_bp.route("/products/elastic/document/fields/file", methods=['GET'])2083def socfaker_elasticecsfields_file():2084 """2085 Returns an ECS file dictionary2086 Returns:2087 dict: Returns a dictionary of ECS 2088 file fields/properties2089 2090 """2091 if validate_request(request):2092 return jsonify(str(socfaker.products.elastic.document.fields.file))2093@api_bp.route("/products/elastic/document/fields/host", methods=['GET'])2094def socfaker_elasticecsfields_host():2095 """2096 Returns an ECS host dictionary2097 Returns:2098 dict: Returns a dictionary of ECS 2099 host fields/properties2100 2101 """2102 if validate_request(request):2103 return jsonify(str(socfaker.products.elastic.document.fields.host))2104@api_bp.route("/products/elastic/document/fields/http", methods=['GET'])2105def socfaker_elasticecsfields_http():2106 """2107 Returns an ECS HTTP dictionary2108 Returns:2109 dict: Returns a dictionary of ECS 2110 HTTP fields/properties2111 2112 """2113 if validate_request(request):2114 return jsonify(str(socfaker.products.elastic.document.fields.http))2115@api_bp.route("/products/elastic/document/fields/network", methods=['GET'])2116def socfaker_elasticecsfields_network():2117 """2118 Returns an ECS network dictionary2119 Returns:2120 dict: Returns a dictionary of ECS 2121 network fields/properties2122 2123 """2124 if validate_request(request):2125 return jsonify(str(socfaker.products.elastic.document.fields.network))2126@api_bp.route("/products/elastic/document/fields/organization", methods=['GET'])2127def socfaker_elasticecsfields_organization():2128 """2129 Returns an ECS Organization dictionary2130 Returns:2131 dict: Returns a dictionary of ECS 2132 organization fields/properties2133 2134 """2135 if validate_request(request):2136 return jsonify(str(socfaker.products.elastic.document.fields.organization))2137@api_bp.route("/products/elastic/document/fields/package", methods=['GET'])2138def socfaker_elasticecsfields_package():2139 """2140 Returns an ECS package dictionary2141 Returns:2142 dict: Returns a dictionary of ECS 2143 package fields/properties2144 2145 """2146 if validate_request(request):2147 return jsonify(str(socfaker.products.elastic.document.fields.package))2148@api_bp.route("/products/elastic/document/fields/registry", methods=['GET'])2149def socfaker_elasticecsfields_registry():2150 """2151 Returns an ECS Windows Registry dictionary2152 Returns:2153 dict: Returns a dictionary of ECS 2154 Windows Registry fields/properties2155 2156 """2157 if validate_request(request):2158 return jsonify(str(socfaker.products.elastic.document.fields.registry))2159@api_bp.route("/products/elastic/document/fields/server", methods=['GET'])2160def socfaker_elasticecsfields_server():2161 """2162 Returns an ECS server dictionary2163 Returns:2164 dict: Returns a dictionary of ECS 2165 server fields/properties2166 2167 """2168 if validate_request(request):2169 return jsonify(str(socfaker.products.elastic.document.fields.server))2170@api_bp.route("/products/elastic/document/fields/source", methods=['GET'])2171def socfaker_elasticecsfields_source():2172 """2173 Returns an ECS source dictionary2174 Returns:2175 dict: Returns a dictionary of ECS 2176 source fields/properties2177 2178 """2179 if validate_request(request):2180 return jsonify(str(socfaker.products.elastic.document.fields.source))2181@api_bp.route("/products/elastic/hits", methods=['POST'])2182def socfaker_elastic_hits(count=10):2183 """2184 Returns a provided count of generated / fake Elasticsearch query hits. Default is 10.2185 Args:2186 count (int, optional): The number of Elasticsearch query hits returned in a list. Defaults to 10.2187 Returns:2188 list: A list of Elasticsearch query hits2189 2190 """2191 if validate_request(request):2192 return jsonify(str(socfaker.products.elastic.hits(count=count)))2193### PRODUCTS - ELASTIC ###2194### PRODUCTS - QUALYSGUARD ###2195@api_bp.route("/products/qualysguard/scan", methods=['POST'])2196def socfaker_qualysguard_scan(count=1, host_count=1):2197 """2198 Retrieve 1 or more QualysGuard VM scans for 1 or more hosts2199 Args:2200 count (int, optional): The number of scans to return. Defaults to 1.2201 host_count (int, optional): The number of hosts within a scan. Defaults to 1.2202 Returns:2203 list: Returns a list of scans based on the provided inputs2204 2205 """2206 if validate_request(request):2207 return jsonify(str(socfaker.products.qualysguard.scan(count=count, host_count=host_count)))2208### PRODUCTS - QUALYSGUARD ###2209### PRODUCTS - SERVICENOW ###2210@api_bp.route("/products/servicenow/search", methods=['POST'])2211def socfaker_servicenow_search(random_keyword=None):2212 """2213 Generates a fake response from a ServiceNow Incident Search2214 Args:2215 random_keyword (str, optional): Adds a random keyword string you provide to fields within the generated response object. Defaults to None.2216 Returns:2217 dict: A ServiceNow Incident Search response object2218 2219 """2220 if validate_request(request):...

Full Screen

Full Screen

test_protocol.py

Source:test_protocol.py Github

copy

Full Screen

...10class ProtocolTestCase(RootTestCase, ProtocolTester):11 api = Api(protocol)12 def test_login(self):13 a_name = 'login'14 self.api.validate_request(a_name, {'login': 'l', 'password': 'p',15 'environment_name': 'e', 'custom_actor_info': 'i'})16 self.api.validate_request(a_name, {'login': 'l', 'password': 'p',17 'environment_name': 'n'})18 self.api.validate_response(a_name, {'status': 'ok', 'session_id': 'i',19 'user_id': 5, 'environment_id': 7})20 self.validate_error_response(a_name)21 def test_logout(self):22 a_name = 'logout'23 self.api.validate_request(a_name, {'session_id': 'i'})24 self.validate_status_response(a_name)25 def test_add_tariffication_object(self):26 a_name = 'add_tariffication_object'27 self.api.validate_request(a_name, {'session_id': 's', 'name': 'one'})28 self.api.validate_request(a_name, {'session_id': 's',29 'name': u'лунный свет'})30 self.api.validate_response(a_name, {'status': 'ok', 'id': 1})31 self.validate_error_response(a_name)32 def test_get_tariffication_objects(self):33 a_name = 'get_tariffication_objects'34 self.api.validate_request(a_name, {'session_id': 'i',35 'filter_params': {}, 'paging_params': {},})36 self.api.validate_request(a_name, {'session_id': 'i',37 'filter_params': {'id': 1, 'ids': [1, 2], 'name': 'lala'},38 'paging_params': {'limit': 0, 'offset': 0,}})39 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,40 'tariffication_objects': [41 {'id': 1, 'name': 'one'},42 {'id': 2, 'name': 'two'},43 ]44 })45 self.validate_error_response(a_name)46 def test_modify_tariffication_object(self):47 a_name = 'modify_tariffication_object'48 self.api.validate_request(a_name, {'session_id': 's',49 'id': 1, 'new_name': 'one'})50 self.validate_status_response(a_name)51 def test_delete_tariffication_object(self):52 a_name = 'delete_tariffication_object'53 self.api.validate_request(a_name, {'session_id': 's', 'id': 1})54 self.validate_status_response(a_name)55 def test_get_action_logs(self):56 a_name = 'get_action_logs'57 self.api.validate_request(a_name, {'session_id': 's',58 'filter_params': {}, 'paging_params': {},})59 self.api.validate_request(a_name, {'session_id': 's',60 'filter_params': {}, 'paging_params': {'limit': 0,},})61 self.api.validate_request(a_name, {'session_id': 's',62 'filter_params': {}, 'paging_params': {'limit': 0, 'offset': 0,},})63 self.api.validate_request(a_name, {'session_id': 's',64 'filter_params': {'from_request_date': '2011-02-21 00:00:00',65 'to_request_date': '2011-02-21 23:59:59'},66 'paging_params': {}})67 self.api.validate_request(a_name, {'session_id': 's',68 'filter_params': {'action': 'a'}, 'paging_params': {}})69 self.api.validate_request(a_name, {'session_id': 's',70 'filter_params': {'user_id': 1}, 'paging_params': {}})71 self.api.validate_request(a_name, {'session_id': 's',72 'filter_params': {'session_id': ''}, 'paging_params': {}})73 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,74 'action_logs': []})75 self.api.validate_response(a_name, {'status': 'ok', 'total': 4,76 'action_logs': [77 {78 'id': 42, 'session_id': 's_id', 'custom_actor_info': None,79 'subject_users_ids': [3], 'actor_user_id': 1, 'action': 'a',80 'request_date': '%s' % datetime.datetime.now(pytz.utc),81 'remote_addr': '127.0.0.1', 'request': 'req',82 'response': 'resp'83 },84 ]})85 self.validate_error_response(a_name)86 def test_get_action_logs_self(self):87 a_name = 'get_action_logs_self'88 self.api.validate_request(a_name, {'session_id': 's',89 'filter_params': {}, 'paging_params': {},})90 self.api.validate_request(a_name, {'session_id': 's',91 'filter_params': {}, 'paging_params': {'limit': 0,},})92 self.api.validate_request(a_name, {'session_id': 's',93 'filter_params': {}, 'paging_params': {'limit': 0, 'offset': 0,},})94 self.api.validate_request(a_name, {'session_id': 's',95 'filter_params': {'from_request_date': '2011-02-21 00:00:00',96 'to_request_date': '2011-02-21 23:59:59'},97 'paging_params': {}})98 self.api.validate_request(a_name, {'session_id': 's',99 'filter_params': {'action': 'a'}, 'paging_params': {}})100 self.api.validate_request(a_name, {'session_id': 's',101 'filter_params': {'session_id': ''}, 'paging_params': {}})102 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,103 'action_logs': []})104 self.api.validate_response(a_name, {'status': 'ok', 'total': 4,105 'action_logs': [106 {107 'id': 42, 'session_id': 's_id', 'custom_actor_info': None,108 'subject_users_ids': [3], 'actor_user_id': 1, 'action': 'a',109 'request_date': '%s' % datetime.datetime.now(pytz.utc),110 'remote_addr': '127.0.0.1', 'request': 'req',111 'response': 'resp'112 },113 ]})114 self.validate_error_response(a_name)115 def test_add_tariff(self):116 a_name = 'add_tariff'117 self.api.validate_request(a_name, {'session_id': 's', 'name': 'one',118 'parent_tariff_id': None,119 'type': Tariff.TYPE_PERSONAL, 'status': Tariff.STATUS_ACTIVE})120 self.api.validate_request(a_name, {'session_id': 's', 'name': 'one',121 'parent_tariff_id': 1, 'currency': 'RUB',122 'type': Tariff.TYPE_PUBLIC, 'status': Tariff.STATUS_INACTIVE})123 self.api.validate_response(a_name, {'status': 'ok', 'id': 1})124 self.validate_error_response(a_name)125 def test_get_tariffs(self):126 a_name = 'get_tariffs'127 self.api.validate_request(a_name, {'session_id': 's',128 'filter_params': {}, 'paging_params': {},})129 self.api.validate_request(a_name, {'session_id': 's',130 'filter_params': {'id': 1, 'ids': [1, 2], 'name': 't',131 'type': Tariff.TYPE_PERSONAL, 'status': Tariff.STATUS_ARCHIVE},132 'paging_params': {'limit': 0}})133 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,134 'tariffs': []})135 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,136 'tariffs': [137 {'id': 1, 'name': 't0', 'parent_tariffs': [{'id': 1, 'name': 'pt0',138 'status': Tariff.STATUS_ACTIVE, 'currency': 'RUB'}], 'type': Tariff.TYPE_PUBLIC,139 'status': Tariff.STATUS_ACTIVE, 'currency': 'RUB'}140 ]})141 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,142 'tariffs': [143 {'id': 1, 'name': 't0', 'parent_tariffs': [{'id': 2, 'name': 'pt2',144 'status': Tariff.STATUS_ACTIVE, 'currency': None}, {'id': 3, 'name': 'pt3',145 'status': Tariff.STATUS_ARCHIVE, 'currency': 'RUB'}],146 'type': Tariff.TYPE_PUBLIC, 'status': Tariff.STATUS_ACTIVE, 'currency': 'RUB'},147 {'id': 1, 'name': 't0', 'parent_tariffs': [{'id': 1, 'name': 'pt0',148 'status': Tariff.STATUS_ACTIVE, 'currency': None}], 'type': Tariff.TYPE_PUBLIC,149 'status': Tariff.STATUS_ACTIVE, 'currency': None},150 ]})151 self.validate_error_response(a_name)152 def test_modify_tariff(self):153 a_name = 'modify_tariff'154 self.api.validate_request(a_name, {'session_id': 's', 'id': 1, 'new_name': 'n'})155 self.api.validate_request(a_name, {'session_id': 's', 'id': 1,156 'new_name': 'n', 'new_status': Tariff.STATUS_ARCHIVE,157 'new_type': Tariff.TYPE_PERSONAL, 'new_parent_tariff_id': 1,158 'new_currency': 'RUB'})159 self.api.validate_request(a_name, {'session_id': 's', 'id': 1,160 'new_currency': None})161 self.validate_status_response(a_name)162 def test_delete_tariff(self):163 a_name = 'delete_tariff'164 self.api.validate_request(a_name, {'session_id': 's', 'id': 1})165 self.validate_status_response(a_name)166 def test_add_viewing_tariff_context(self):167 a_name = 'add_tariff_viewing_context'168 self.api.validate_request(a_name, {'session_id': 's', 'name': None,169 'tariff_id': 1, 'view_order': 2, 'context': []})170 self.api.validate_request(a_name, {'session_id': 's', 'name': None,171 'tariff_id': 1, 'view_order': 2, 'context': [172 {'name': 'num', 'value': 2},173 {'name': 'num', 'value': 3},174 {'name': 'name', 'value': 'n'},175 ]})176 self.api.validate_response(a_name, {'status': 'ok', 'id': 1})177 self.validate_error_response(a_name)178 def test_get_tariff_viewing_contexts(self):179 a_name = 'get_tariff_viewing_contexts'180 self.api.validate_request(a_name, {'session_id': 's',181 'filter_params': {'tariff_id': 4}, 'paging_params': {},})182 self.api.validate_request(a_name, {'session_id': 's',183 'filter_params': {'id': 1, 'ids': [1, 2], 'tariff_id': 2},184 'paging_params': {'limit': 0},185 'ordering_params': ['view_order']})186 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,187 'tariff_contexts': []})188 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,189 'tariff_contexts': [190 {'id': 1, 'name': 't0', 'tariff_id': 3, 'view_order': 3,191 'context': [192 {'name': 'n', 'value': 'v'},193 {'name': 'm', 'value': 1},194 ]}195 ]})196 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,197 'tariff_contexts': [198 {'id': 1, 'name': 't0', 'tariff_id': 3, 'view_order': 3,199 'context': [200 {'name': 'n', 'value': 'v'},201 {'name': 'm', 'value': 1},202 ]},203 {'id': 1, 'name': 't0', 'tariff_id': 3, 'view_order': 4,204 'context': [205 {'name': 'n', 'value': 'v'},206 {'name': 'm', 'value': 1},207 ]}208 ]})209 self.validate_error_response(a_name)210 def test_modify_viewing_tariff_context(self):211 a_name = 'modify_tariff_viewing_context'212 self.api.validate_request(a_name, {'session_id': 's', 'id': 1,213 'new_name': 'n'})214 self.api.validate_request(a_name, {'session_id': 's', 'id': 1,215 'new_name': 'n', 'new_tariff_id': 4,216 'new_view_order': 3, 'new_context': [217 {'name': 'num', 'value': 2},218 ]})219 self.validate_status_response(a_name)220 def test_delete_viewing_tariff_context(self):221 a_name = 'delete_tariff_viewing_context'222 self.api.validate_request(a_name, {'session_id': 's', 'id': 1})223 self.validate_status_response(a_name)224 def test_save_rules(self):225 a_name = 'save_rule'226 self.api.validate_request(a_name, {'session_id': 's', 'tariff_id': 1,227 'tariffication_object_id': 3, 'draft_rule': 'p',228 'status': Rule.STATUS_ACTIVE})229 self.api.validate_request(a_name, {'session_id': 's', 'tariff_id': 1,230 'tariffication_object_id': 3, 'draft_rule': 'p',231 'status': Rule.STATUS_ACTIVE, 'view_order': 0})232 self.api.validate_response(a_name, {'status': 'ok', 'id': 1})233 self.validate_error_response(a_name)234 def test_get_rules(self):235 a_name = 'get_rules'236 self.api.validate_request(a_name, {'session_id': 's',237 'filter_params': {}, 'paging_params': {},})238 self.api.validate_request(a_name, {'session_id': 's',239 'filter_params': {'id': 1, 'ids': [1, 2],240 'tariff_id': 1, 'tariffication_object_id': 1,241 'status': Rule.STATUS_ACTIVE},242 'paging_params': {'limit': 0}})243 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,244 'rules': []})245 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,246 'rules': [247 {'id': 1, 'tariff_id': 1, 'tariff_name': 't0',248 'tariffication_object_id': 2, 'tariffication_object_name': 'to0',249 'rule': None, 'draft_rule': 'rule', 'status': Rule.STATUS_ACTIVE,250 'view_order': 0},251 {'id': 1, 'tariff_id': 1, 'tariff_name': 't0',252 'tariffication_object_id': 2, 'tariffication_object_name': 'to0',253 'rule': 'tt', 'draft_rule': None, 'status': Rule.STATUS_ACTIVE,254 'view_order': 1}255 ]256 })257 self.validate_error_response(a_name)258 def test_delete_rule(self):259 a_name = 'delete_rule'260 self.api.validate_request(a_name, {'session_id': 's', 'id': 1})261 self.validate_status_response(a_name)262 def test_apply_rules(self):263 a_name = 'apply_draft_rules'264 self.api.validate_request(a_name, {'session_id': 's', 'tariff_id': 1})265 self.validate_status_response(a_name)266 def test_get_tariffs_prices(self):267 a_name = 'get_tariffs_prices'268 self.api.validate_request(a_name, {'session_id': 's', 'filter_params': {},269 'paging_params': {}, 'calculation_contexts': []})270 self.api.validate_request(a_name, {'session_id': 's',271 'filter_params': {'user_id': 1, 'ids': [1, 2]},272 'paging_params': {'limit': 0}, 'calculation_contexts': []})273 self.api.validate_request(a_name, {'session_id': 's',274 'filter_params': {'user_id': 1, 'ids': [1, 2]},275 'paging_params': {'limit': 0}, 'calculation_contexts': [{'objects_num': 3}]})276 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,277 'tariffs': []})278 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,279 'tariffs': [{280 'tariff_id': 1, 'tariff_name': 't0', 'tariff_status': Tariff.STATUS_ACTIVE,281 'tariffication_objects': [282 {'tariffication_object_id': 2, 'tariffication_object_name': 'to0',283 'view_order': 1,284 'prices': [285 {'calculation_context': {},286 'rule': {'rule_id': 1, 'rule_from_tariff_id': 1,287 'rule_from_tariff_name': 't0', 'price': '10.1'}288 }289 ],290 }291 ]292 }]293 })294 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,295 'tariffs': [{296 'tariff_id': 1, 'tariff_name': 't0', 'tariff_status': Tariff.STATUS_ACTIVE,297 'tariffication_objects': [298 {'tariffication_object_id': 2, 'tariffication_object_name': 'to0',299 'view_order': 1,300 'prices': [301 {'calculation_context': {},302 'draft_rule': {'rule_id': 1, 'rule_from_tariff_id': 1,303 'rule_from_tariff_name': 't0', 'price': '10.1'},304 'rule': {'rule_id': 1, 'rule_from_tariff_id': 1,305 'rule_from_tariff_name': 't0', 'price': '10.1'},306 }307 ],308 }309 ]310 }]311 })312 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,313 'tariffs': [314 {'tariff_id': 1, 'tariff_name': 't0', 'tariff_status': Tariff.STATUS_ACTIVE,315 'tariffication_objects': [316 {'tariffication_object_id': 2, 'tariffication_object_name': 'to0',317 'view_order': 1,318 'prices': [319 {'calculation_context': {},320 'draft_rule': {'rule_id': 1, 'rule_from_tariff_id': 1,321 'rule_from_tariff_name': 't0', 'price': '10.1'},322 'rule': {'rule_id': 1, 'rule_from_tariff_id': 1,323 'rule_from_tariff_name': 't0', 'price': '10.2'},324 }325 ],326 }327 ]},328 {'tariff_id': 12, 'tariff_name': 't02', 'tariff_status': Tariff.STATUS_ARCHIVE,329 'tariffication_objects': [330 {'tariffication_object_id': 2, 'tariffication_object_name': 'to0',331 'view_order': 2,332 'prices': [333 {'calculation_context': {},334 'draft_rule': {'rule_id': 1, 'rule_from_tariff_id': 1,335 'rule_from_tariff_name': 't0', 'price': '10.1'},336 'rule': {'rule_id': 1, 'rule_from_tariff_id': 1,337 'rule_from_tariff_name': 't0', 'price': '10.1'},338 },339 {'calculation_context': {'objects_num': 100},340 'draft_rule': {'rule_id': 1, 'rule_from_tariff_id': 1,341 'rule_from_tariff_name': 't0', 'price': '8.1'},342 'rule': {'rule_id': 1, 'rule_from_tariff_id': 1,343 'rule_from_tariff_name': 't0', 'price': '7.1'},344 }345 ],346 }347 ]},348 ]349 })350 def test_get_price(self):351 a_name = 'get_price'352 self.api.validate_request(a_name, {'session_id': 's',353 'tariff_id': 1, 'tariffication_object_id': 3})354 self.api.validate_response(a_name, {'status': 'ok',355 'price': '10.1', 'rule_id': 1,356 'tariffication_object_id': 2, 'tariffication_object_name': 'to0',357 'rule_from_tariff_id': 1, 'rule_from_tariff_name': 't0',358 })359 self.api.validate_response(a_name, {'status': 'ok',360 'price': '10.1', 'rule_id': 1,361 'tariffication_object_id': 2, 'tariffication_object_name': 'to0',362 'rule_from_tariff_id': 1, 'rule_from_tariff_name': 't0',363 'calculation_context': {'objects_num': 3}364 })365 self.validate_error_response(a_name)366 def test_get_draft_price(self):367 a_name = 'get_draft_price'368 self.api.validate_request(a_name, {'session_id': 's',369 'tariff_id': 1, 'tariffication_object_id': 3})370 self.api.validate_response(a_name, {'status': 'ok',371 'price': '10.1', 'rule_id': 1,372 'tariffication_object_id': 2, 'tariffication_object_name': 'to0',373 'rule_from_tariff_id': 1, 'rule_from_tariff_name': 't0',374 })375 self.api.validate_response(a_name, {'status': 'ok',376 'price': '10.1', 'rule_id': 1,377 'tariffication_object_id': 2, 'tariffication_object_name': 'to0',378 'rule_from_tariff_id': 1, 'rule_from_tariff_name': 't0',379 'calculation_context': {'objects_num': 3}380 })381 self.validate_error_response(a_name)382 def test_add_user_tariff(self):383 a_name = 'add_user_tariff'384 self.api.validate_request(a_name, {'session_id': 's',385 'tariff_id': 1, 'user_id': 2})386 self.api.validate_response(a_name, {'status': 'ok', 'id': 1})387 self.validate_error_response(a_name)388 def test_delete_user_tariffs(self):389 a_name = 'delete_user_tariffs'390 self.api.validate_request(a_name, {'session_id': 's', 'user_id': 1,391 'tariff_ids': [1, 2]})392 self.validate_status_response(a_name)393 def test_get_users_tariffs(self):394 a_name = 'get_user_tariffs'395 self.api.validate_request(a_name, {'session_id': 's',396 'filter_params': {}, 'paging_params': {},})397 self.api.validate_request(a_name, {'session_id': 's',398 'filter_params': {'user_ids': [1], 'tariff_ids': [1, 2]},399 'paging_params': {'limit': 0}})400 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,401 'user_tariffs': []})402 self.api.validate_response(a_name, {'status': 'ok', 'total': 2,403 'user_tariffs': [{'user_id': 1, 'tariff_ids': [1, 2]}]})404 self.validate_error_response(a_name)405if __name__ == '__main__':...

Full Screen

Full Screen

requests.py

Source:requests.py Github

copy

Full Screen

2from ..tools.validate import validate_request3class TestRequestValidation(unittest.TestCase):4 def test_empty_request_body(self):5 body = {}6 validation_error = validate_request(body)7 self.assertNotEqual(validation_error, None)8 self.assertEqual(9 validation_error.get("message"),10 "Schema threw an error when validating the request body.",11 )12 def test_missing_response(self):13 body = {"answer": "example", "params": {}}14 validation_error = validate_request(body)15 self.assertNotEqual(validation_error, None)16 self.assertEqual(17 validation_error.get("error_thrown").get("message"),18 "'response' is a required property") 19 def test_null_response(self):20 body = {"response": None, "answer": "example", "params": {}}21 validation_error = validate_request(body)22 self.assertNotEqual(validation_error, None)23 self.assertEqual(24 validation_error.get("error_thrown").get("message"),25 "None should not be valid under {'type': 'null'}")26 27 def test_missing_answer(self):28 body = {"response": "example", "params": {}}29 validation_error = validate_request(body)30 self.assertNotEqual(validation_error, None)31 self.assertEqual(32 validation_error.get("error_thrown").get("message"),33 "'answer' is a required property") 34 35 def test_null_answer(self):36 body = {"response": "example", "answer": None, "params": {}}37 validation_error = validate_request(body)38 self.assertNotEqual(validation_error, None)39 self.assertEqual(40 validation_error.get("error_thrown").get("message"),41 "None should not be valid under {'type': 'null'}") 42 def test_bad_params(self):43 body = {"response": "example", "answer": "example", "params": 2}44 validation_error = validate_request(body)45 self.assertNotEqual(validation_error, None)46 47 self.assertEqual(48 validation_error.get("error_thrown").get("message"),49 "2 is not of type 'object'") 50 def test_extra_fields(self):51 body = {52 "response": "example", 53 "answer": "example", 54 "params": {},55 "hello": "world"56 }57 validation_error = validate_request(body)58 self.assertNotEqual(validation_error, None)59 60 self.assertEqual(61 validation_error.get("error_thrown").get("message"),62 "Additional properties are not allowed ('hello' was unexpected)",63 ) 64 def test_valid_request_body(self):65 body = {"response": "", "answer": ""}66 validation_error = validate_request(body)67 self.assertEqual(validation_error, None)68if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful