SSH-based test method, apparatus and device, and computer readable storage medium

By the SSH -based testing method in the Linux system, initialize the SSH client class and establish a connection, solve the problem of high manual operation errors and high cost test costs in the traditional test method, and realize the efficient and automated test process.

CN119383121APending Publication Date: 2025-01-28BEIJING CO WHEELS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310922283.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-07-25
Publication Date
2025-01-28

Smart Images

  • Figure CN119383121A_ABST
    Figure CN119383121A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an SSH-based test method, device and equipment and a computer readable storage medium. The method comprises the steps that a pre-stated SSH client class is initialized, an instantiated object is obtained, and the SSH client class comprises a connection function, an execution function, connection parameters and client attributes; operating the connection function by using the connection parameter to establish a connection between the client attribute and the SSH server; and running the execution function to execute a test task between the instantiated object and the SSH server. In this way, the test can be automatically executed between the SSH client and the SSH server, the operation that a user manually inputs a command, transmits a file and the like is avoided, the execution of the test method does not need secondary development of a tester, the situations that the secondary development cost is too high and the reusability is poor are avoided, and the test efficiency and the test effect are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of Linux, and in particular to the field of SSH-based testing technology. Background Art

[0002] With the rapid development of computer technology, remote connection technology has become an indispensable part of daily work. Especially in the field of automotive computers and cloud servers, most of the underlying operating systems are Linux. When remotely connecting to the SSH (Secure shell protocol) server for testing in a traditional Linux system, users are required to manually enter commands, transfer files, and perform other operations, which is prone to errors and has low testing efficiency. Existing automated testing tools often require secondary development, which results in high secondary development costs, poor reusability, and affects testing efficiency and results. Summary of the invention

[0003] The present disclosure provides a testing method, apparatus, device, storage medium and vehicle based on SSH.

[0004] According to a first aspect of the present disclosure, a testing method based on SSH is provided. The method comprises:

[0005] Initializing a pre-declared SSH client class to obtain an instantiated object, wherein the SSH client class includes a connection function, an execution function, connection parameters, and client properties;

[0006] Running the connection function using the connection parameters to establish a connection between the client attributes and the SSH server;

[0007] The execution function is run to execute a test task between the instantiated object and the SSH server.

[0008] According to the above aspects and any possible implementation manner, an implementation manner is further provided, when establishing a connection between the client attribute and the SSH server, the method further includes:

[0009] Capture connection timeouts;

[0010] If the number of connection timeouts is less than the maximum number of reconnections, a connection abnormality alarm message is printed;

[0011] If the number of connection timeouts is greater than or equal to the maximum number of reconnections, the client attributes are destroyed.

[0012] According to the above aspects and any possible implementation, there is further provided an implementation, wherein the class of the SSH client further includes a key attribute;

[0013] When establishing a connection between the client attribute and the SSH server, the method further includes:

[0014] Capture initial connection identity anomaly information;

[0015] If the capture is successful, the value of the key attribute of the instantiated object is changed to a preset value, wherein the preset value is used to indicate that a key is required when the client attribute is connected to the SSH server for the first time.

[0016] According to the above aspects and any possible implementation, there is further provided an implementation, wherein the execution function includes a single interaction method and a session interaction method;

[0017] The running of the execution function to execute a test task between the instantiated object and the SSH server includes:

[0018] Obtaining current interaction requirements from the test task;

[0019] An interaction method matching the current interaction requirement is called from the single interaction method and the session interaction method to perform an interaction test between the instantiated object and the SSH server.

[0020] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein performing an interaction test between the instantiated object and the SSH server includes:

[0021] If the interaction method matching the current interaction requirement includes a session interaction method, executing the session interaction method to create a session channel between the instantiated object and the SSH server;

[0022] Session information is sent and received in the session channel to perform an interaction test between the instantiated object and the SSH server.

[0023] According to the above aspect and any possible implementation manner, an implementation manner is further provided, wherein the session information includes a flag bit for indicating the end of the dialog box, and when sending and receiving the session information in the session channel, the method further includes:

[0024] Determining whether the session information includes a flag indicating that the dialog box ends;

[0025] If received, and the current tail count is equal to zero, the operation of sending session information is executed;

[0026] If received and the current tail count is greater than zero, closing the session channel; and / or

[0027] If no session information is received within a preset maximum time period in the session channel, the session channel is closed.

[0028] According to the above aspects and any possible implementation, an implementation is further provided.

[0029] The execution function includes a transmission function; the transmission function includes: at least one of a method for downloading files from an SSH server, a method for uploading files from the SSH client to the SSH server, and a method for downloading files in batches;

[0030] The running of the execution function to execute a test task between the instantiated object and the SSH server includes:

[0031] Run the transmission function to create a transmission channel;

[0032] A file transfer test is performed between the instantiated object and the SSH server through the transmission channel.

[0033] According to the above aspects and any possible implementation manner, an implementation manner is further provided, wherein the method further includes:

[0034] Determining whether the instantiated object includes the client attribute;

[0035] If the client attributes are not included, creating the client attributes and re-executing the connection function;

[0036] and / or

[0037] If the client attribute is included, determining whether the transmission channel between the instantiated object and the SSH server is in an activated state;

[0038] If it is not in the activated state, re-execute the connection function;

[0039] and / or

[0040] If an exception is caught when performing the interactive test between the instantiated object and the SSH server, the connection function is re-executed.

[0041] According to a second aspect of the present disclosure, a test device based on SSH is provided. The device comprises:

[0042] An initialization module, used to initialize a pre-declared SSH client class to obtain an instantiated object, wherein the SSH client class includes a connection function, an execution function, connection parameters and client properties;

[0043] A first operation module, configured to operate the connection function using the connection parameters to establish a connection between the client attribute and the SSH server;

[0044] The second running module is used to run the execution function to execute the test task between the instantiated object and the SSH server.

[0045] According to a third aspect of the present disclosure, an electronic device is provided, which includes a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the program, the method described above is implemented.

[0046] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the method according to the first aspect and / or the second aspect of the present disclosure is implemented.

[0047] According to a fifth aspect of the present disclosure, a vehicle is provided, the vehicle comprising the SSH-based test device as described in the second aspect and / or the electronic device as described in the third aspect.

[0048] In the present disclosure, a pre-declared SSH client class is automatically initialized to obtain an instantiated object, and then a connection parameter is passed into a connection function, thereby running the connection function to establish a connection between the client attributes and the SSH server, so that a connection is established between the SSH client and the SSH server, and then the execution function is run to execute a test task between the instantiated object and the SSH server, that is, to execute a test task between the SSH client and the SSH server. In this way, the test can be automatically executed between the SSH client and the SSH server, avoiding the need for users to manually input commands, transfer files, and other operations, and the execution of the test method does not require secondary development by testers, avoiding excessively high secondary development costs and poor reusability, thereby improving test efficiency and test results.

[0049] It should be understood that the contents described in the summary of the invention are not intended to limit the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, among which:

[0051] Figure 1A flow chart of a testing method based on SSH according to an embodiment of the present disclosure is shown;

[0052] Figure 2 A schematic diagram showing an instantiated object according to an embodiment of the present disclosure is shown;

[0053] Figure 3 A block diagram of an SSH-based testing device according to an embodiment of the present disclosure is shown;

[0054] Figure 4 A block diagram of an exemplary electronic device capable of implementing embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0055] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0056] In addition, the term "and / or" in this article is only a description of the association relationship between the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0057] Figure 1 The flowchart of the SSH-based testing method 100 according to the embodiment of the present disclosure is shown. The execution subject of the method 100 is a computer, mobile phone or other device of the SSH client, and the method 100 may include:

[0058] Step 120, initializing the pre-declared SSH client class to obtain an instantiated object, wherein the SSH client class includes a connection function, an execution function, connection parameters, and client properties;

[0059] SSH client is SSH Client.

[0060] Specifically, declare a SSHClient class. A class is a blueprint or template that defines object properties and methods (such as the _connect() method, execute_cmd method and execute_interact_cmd method, sftp_get method, sftp_put method, and sftp_download_files method, etc.). It defines a set of properties and methods that describe the characteristics and behaviors of the entity represented by the class. The variables contained in the class are called properties, which represent the state of the object; the functions contained in the class are called methods, which represent the behavior of the object.

[0061] An instantiated object is obtained through class initialization, in which the dependent parameters are manually passed in during instantiation. These parameters include the address of the remote Linux server, user name, password, server port number, connection timeout, number of retries, key file address and other connection parameters.

[0062] Instantiate an object such as Figure 2 As shown, Figure 2 In the first box, self. represents the attributes of the instance object, and the second box represents the methods of the instantiated object, such as the _connect method, execute_cmd method and execute_interact_cmd method, sftp_get method, sftp_put method, and sftp_download_files method.

[0063] When initializing the class, set the properties of the instantiated object, mainly including the client property self._client, the transmission channel transport (you can declare an empty one first, and then establish the transmission channel when you need to transfer files), and the session channel channel (you can declare an empty one first, and then establish the session channel when you need a session).

[0064] Of course, since the methods, namely the connection function and the execution function, are already included when declaring the SSH client class, the instantiated object naturally includes the connection function and the execution function.

[0065] Step 120, running the connection function using the connection parameters to establish a connection between the client attributes and the SSH server;

[0066] By passing the connection parameters into the connection function, the connection function can be called and run to establish a connection between the client attributes and the SSH server, thereby establishing a connection between the SSH client and the SSH server.

[0067] Step 130: Run the execution function to execute the test task between the instantiated object and the SSH server.

[0068] The execution functions include but are not limited to interaction methods and transmission functions, etc. Correspondingly, the test tasks include: interaction tasks and transmission tasks, etc.

[0069] The pre-declared SSH client class is automatically initialized to obtain an instantiated object, and then the connection parameters are passed into the connection function, so as to run the connection function to establish a connection between the client attributes and the SSH server, thereby establishing a connection between the SSH client and the SSH server, and then run the execution function to execute the test task between the instantiated object and the SSH server, that is, to execute the test task between the SSH client and the SSH server. In this way, the test can be automatically executed between the SSH client and the SSH server, avoiding the need for users to manually input commands, transfer files, etc., and the execution of the test method does not require secondary development by testers, avoiding excessively high secondary development costs and poor reusability, thereby improving test efficiency and test results.

[0070] In some embodiments, when establishing a connection between the client attribute and the SSH server, the method further includes:

[0071] Capture connection timeouts;

[0072] If the number of connection timeouts is less than the maximum number of reconnections, a connection abnormality alarm message is printed;

[0073] If the number of connection timeouts is greater than or equal to the maximum number of reconnections, the client attributes are destroyed.

[0074] Within the maximum number of reconnections, an exception is captured each time a connection is made. If the captured connection timeout number is less than the number of reconnections, only a warning message is printed. When the maximum number of reconnections is exceeded, the program exits and returns a connection failure exception, i.e., the client properties are automatically destroyed. In this way, if a reconnection is required, the program can only reinitialize and rebuild the client properties.

[0075] The maximum number of reconnection times is set to improve the robustness of the program. That is, the SSH server may be in a state of network instability, busyness, or restart. This embodiment can increase connectivity.

[0076] In some embodiments, the class of the SSH client further includes a key attribute;

[0077] When establishing a connection between the client attribute and the SSH server, the method further includes:

[0078] Capture initial connection identity anomaly information;

[0079] If the capture is successful, the value of the key attribute of the instantiated object is changed to a preset value, wherein the preset value is used to indicate that a key is required when the client attribute is connected to the SSH server for the first time.

[0080] Because it is unclear whether the SSH server requires a key file for advanced login, the default is that no key is required and False is assigned to the key attribute of the instantiated object. Therefore, when connecting for the first time, try to capture the "initial connection identity exception information". If the capture is successful, the value of the key attribute is changed to the preset value, that is, True. In this way, the Boolean value of the password attribute is used to determine whether the key parameter is passed in during the connection.

[0081] In some embodiments, the execution function includes a single interaction method (execute_cmd method) and a session interaction method (execute_interact_cmd method);

[0082] The running of the execution function to execute a test task between the instantiated object and the SSH server includes:

[0083] Obtaining current interaction requirements from the test task;

[0084] Current interaction requirements include but are not limited to simple interactions such as the need to view dates and files, or complex interactions such as the need to view logs and execute scripts.

[0085] An interaction method matching the current interaction requirement is called from the single interaction method and the session interaction method to perform an interaction test between the instantiated object and the SSH server.

[0086] The current interaction requirements include simple single interactions and complex session interactions. Therefore, according to different interaction requirements, the interaction method matching the current interaction requirement can be automatically called from the single interaction method and the session interaction method, so as to perform an interaction test between the instantiated object and the SSH server.

[0087] In some embodiments, performing an interaction test between the instantiated object and the SSH server includes:

[0088] If the interaction method matching the current interaction requirement includes a session interaction method, executing the session interaction method to create a session channel between the instantiated object and the SSH server;

[0089] Session information is sent and received in the session channel to perform an interaction test between the instantiated object and the SSH server.

[0090] If the interaction method matching the current interaction requirement includes a session interaction method, the session interaction method is automatically executed to create a session channel between the instantiated object and the SSH server, and then session information is sent and received in the session channel, thereby performing an interaction test between the instantiated object and the SSH server.

[0091] Specifically, the execute_interact_cmd method can be used to establish a session channel to simulate terminal interaction. The session channel can send control characters and commands through send() and recv() to obtain remote output.

[0092] In some embodiments, the session information includes a flag bit for indicating the end of the dialog box, and when sending and receiving the session information in the session channel, the method further includes:

[0093] It is determined whether the session information includes a flag indicating that the session ends with the end of the dialog box. The flag indicating that the session ends with the end of the dialog box may be #, i.e., the cursor is after #. However, since the cursor is after #, it may be the beginning of the session or the end of the session. That is, the first time the cursor is after #, it indicates that information sending has started. The second time the cursor is after #, it indicates that information sending has been completed and the session has ended. Therefore, a current tail count may be performed. When the cursor is after # for the first time, the current tail count may be equal to zero. When the cursor is after # for the second time, the current tail count may be +1, i.e., the current tail count=1.

[0094] If received, and the current tail count is equal to zero, the operation of sending session information is executed;

[0095] If received and the current tail count is greater than zero, closing the session channel; and / or

[0096] If no session information is received within a preset maximum time period in the session channel, the session channel is closed.

[0097] When the dialog box ends and the current tail count is 0, the send() method is executed to send the interactive command, that is, to send the session information, and the current tail count is incremented by 1.

[0098] If the dialog box ends and the current tail count is greater than 0, the interactive session ends, the session channel is closed, and all received data is returned.

[0099] When creating a channel, there is a maximum timeout, which is the preset maximum duration. If no data is received within the preset maximum duration, it means that the session is over and the session channel is closed. The introduction of this mechanism can restore the connection in time when network failures or other abnormal situations occur, preventing long-term dead loops from blocking the program.

[0100] Of course, the interactive method of this embodiment can be designed as an infinite loop (i.e., looping steps 1)-5)), in which the output of the SSH server is first received through the session channel, and different processing logic is performed according to different outputs, as follows:

[0101] 1) Receive password confirmation: Check whether the current recv data ends with 'password:', if yes, send the password;

[0102] 2) Receive a selection confirmation: such as '(yes / no)? ', if yes, send 'yes';

[0103] 3) When the dialog box ends and the current tail count is 0, the send() method is executed to send the interactive command, and the tail count is increased by 1.

[0104] 4) If the dialog box ends and the current tail count is greater than 0, the interactive session ends, the session channel is closed, and all received data is returned.

[0105] 5) Capture timeout exception: There is a maximum timeout when creating a session channel. If no data is received within this time, it means the session is over and the session channel is closed. This mechanism is to prevent long-term dead loops from blocking the program.

[0106] In some embodiments, the execution function includes a transmission function; the transmission function includes: at least one of an SSH server file download method such as an sftp_get method, a method for uploading files from the SSH client to the SSH server such as an sftp_put method, and a batch file download method such as an sftp_download_files method;

[0107] The running of the execution function to execute a test task between the instantiated object and the SSH server includes:

[0108] Run the transmission function to create a transmission channel;

[0109] A file transfer test is performed between the instantiated object and the SSH server through the transmission channel.

[0110] In this embodiment, a transmission channel can be created by calling the sftp_get method or the sftp_put method, and then calling the transmission channel to download or upload documents. Specifically, after calling the upload transmission method, it is equivalent to creating an SFTP client, and then using the SFTP client to download or upload files, thereby completing the file transfer test.

[0111] Of course, you can also use the sftp_download_files method to batch download file directories on the remote SSH server to the local computer.

[0112] In some embodiments, the method further comprises:

[0113] Determining whether the instantiated object includes the client attribute;

[0114] If the client attributes are not included, creating the client attributes and re-executing the connection function;

[0115] and / or

[0116] If the client attribute is included, determining whether the transmission channel between the instantiated object and the SSH server is in an activated state;

[0117] If it is not in the activated state, re-execute the connection function;

[0118] and / or

[0119] If an exception is caught when performing the interactive test between the instantiated object and the SSH server, the connection function is re-executed.

[0120] This embodiment also designs an SSH reconnection decorator, which is a function that is used to decorate other functions and provide additional functions for the decorated functions. The main purpose of this decorator is to ensure the stability of the connection, reduce or eliminate program exceptions caused by the target server actively disconnecting the connection (when the target server is restarted or the connection is lost, the SSH client object executes command line interaction and file transfer will throw an exception, and the client object needs to recreate or establish a connection), thereby affecting the entire automated test process. The specific working principle of the decorator is:

[0121] 1) First, determine whether there is a client attribute in the decorated instantiated object. If not, create it, that is, re-execute the connection function, that is, the _connect() method, to establish a connection between the client attribute and the SSH server

[0122] 2) If yes, you need to check whether the transmission channel in the instantiated object is active. If not or inactive, it means that the transmission channel is closed and the remote connection is disconnected. At this time, you need to continue to execute the _connect() method

[0123] 3) In addition, a protection reconnection design for connection interruption or other exceptions during the execution process, namely the interactive test exception design, is added. The decorated function itself is returned in the decorator, that is, various methods of calling the SSH client, namely the execution function (such as session interaction method, transmission function), and the exception is captured at this time. If the connection is interrupted, restarted, or other related exceptions are captured, the _connect() method is still executed.

[0124] This design increases the stability of the automated program in detecting or resisting abnormal scenarios during the SSH connection interaction, thereby ensuring the success rate of automated test execution and reducing inaccurate test results caused by program design defects.

[0125] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present disclosure is not limited by the order of the actions described, because according to the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present disclosure.

[0126] The above is an introduction to the method embodiment. The following is a further explanation of the scheme disclosed in the present invention through an apparatus embodiment.

[0127] Figure 3 FIG. 3 shows a block diagram of an SSH-based testing device 300 according to an embodiment of the present disclosure. Figure 3 As shown, the device 300 includes:

[0128] An initialization module 310 is used to initialize a pre-declared SSH client class to obtain an instantiated object, wherein the SSH client class includes a connection function, an execution function, connection parameters and client properties;

[0129] A first operation module 320, configured to operate the connection function using the connection parameters to establish a connection between the client attributes and the SSH server;

[0130] The second running module 330 is used to run the execution function to execute the test task between the instantiated object and the SSH server.

[0131] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the described module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0132] According to an embodiment of the present disclosure, the present disclosure further provides an electronic device, including:

[0133] at least one processor; and

[0134] a memory communicatively connected to the at least one processor; wherein,

[0135] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform any one of the above method embodiments.

[0136] According to an embodiment of the present disclosure, the present disclosure further provides a vehicle, including: the SSH-based testing device as described in the above embodiment or the electronic device as described in the above embodiment.

[0137] According to an embodiment of the present disclosure, the present disclosure further provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute any one of the above method embodiments.

[0138] Figure 4 A schematic block diagram of an electronic device 400 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0139] The device 400 includes a computing unit 401, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 402 or a computer program loaded from a storage unit 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the device 400 can also be stored. The computing unit 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0140] A number of components in the device 400 are connected to the I / O interface 405, including: an input unit 406, such as a keyboard, a mouse, etc.; an output unit 407, such as various types of displays, speakers, etc.; a storage unit 408, such as a disk, an optical disk, etc.; and a communication unit 409, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 409 allows the device 400 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0141] The computing unit 401 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 401 performs the various methods and processes described above, such as method 100. For example, in some embodiments, the method 100 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 408. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 400 via ROM 402 and / or communication unit 409. When the computer program is loaded into RAM 403 and executed by the computing unit 401, one or more steps of the method 100 described above may be performed. Alternatively, in other embodiments, the computing unit 401 may be configured to perform the method 100 in any other appropriate manner (e.g., by means of firmware).

[0142] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0143] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0144] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0145] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0146] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0147] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0148] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0149] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A testing method based on SSH, characterized in that: include: Initializing a pre-declared SSH client class to obtain an instantiated object, wherein the SSH client class includes a connection function, an execution function, connection parameters, and client properties; Running the connection function using the connection parameters to establish a connection between the client attributes and the SSH server; The execution function is run to execute a test task between the instantiated object and the SSH server.

2. The method according to claim 1, characterized in that When establishing a connection between the client attribute and the SSH server, the method further includes: Capture connection timeouts; If the number of connection timeouts is less than the maximum number of reconnections, a connection abnormality alarm message is printed; If the number of connection timeouts is greater than or equal to the maximum number of reconnections, the client attributes are destroyed.

3. The method according to claim 1, characterized in that: The class of the SSH client also includes a key attribute; When establishing a connection between the client attribute and the SSH server, the method further includes: Capture initial connection identity anomaly information; If the capture is successful, the value of the key attribute of the instantiated object is changed to a preset value, wherein the preset value is used to indicate that a key is required when the client attribute is connected to the SSH server for the first time.

4. The method according to claim 1, characterized in that: The execution function includes a single interaction method and a session interaction method; The running of the execution function to execute a test task between the instantiated object and the SSH server includes: Obtaining current interaction requirements from the test task; An interaction method matching the current interaction requirement is called from the single interaction method and the session interaction method to perform an interaction test between the instantiated object and the SSH server.

5. The method according to claim 4, characterized in that The performing of an interactive test between the instantiated object and the SSH server includes: If the interaction method matching the current interaction requirement includes a session interaction method, executing the session interaction method to create a session channel between the instantiated object and the SSH server; Session information is sent and received in the session channel to perform an interaction test between the instantiated object and the SSH server.

6. The method according to claim 5, characterized in that The session information includes a flag bit for indicating the end of the dialog box. When sending and receiving the session information in the session channel, the method further includes: Determining whether the session information includes a flag indicating that the dialog box ends; If received, and the current tail count is equal to zero, the operation of sending session information is executed; If received and the current tail count is greater than zero, closing the session channel; and / or If no session information is received within a preset maximum time period in the session channel, the session channel is closed.

7. The method according to claim 1, characterized in that The execution function includes a transmission function; the transmission function includes: at least one of a method for downloading files from an SSH server, a method for uploading files from the SSH client to the SSH server, and a method for downloading files in batches; The running of the execution function to execute a test task between the instantiated object and the SSH server includes: Run the transmission function to create a transmission channel; A file transfer test is performed between the instantiated object and the SSH server through the transmission channel.

8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: Determining whether the instantiated object includes the client attribute; If the client attributes are not included, creating the client attributes and re-executing the connection function; and / or If the client attribute is included, determining whether the transmission channel between the instantiated object and the SSH server is in an activated state; If it is not in the activated state, re-execute the connection function; and / or If an exception is caught when performing the interactive test between the instantiated object and the SSH server, the connection function is re-executed.

9. A test device based on SSH, characterized in that: include: An initialization module, used to initialize a pre-declared SSH client class to obtain an instantiated object, wherein the SSH client class includes a connection function, an execution function, connection parameters and client properties; A first running module, configured to run the connection function using the connection parameters to establish a connection between the client attribute and the SSH server; The second running module is used to run the execution function to execute the test task between the instantiated object and the SSH server.

10. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.

11. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-8.

12. A vehicle, characterized in that: include: The apparatus as claimed in claim 9, and / or the electronic device as claimed in claim 10, and / or the readable storage medium as claimed in claim 11.