Token acquisition method, device, computer equipment and storage medium
By defining the login request function and the identification verification code function in the target class, the verification code is automatically obtained and the token is obtained, which solves the problem of low efficiency and high cost of manually obtaining tokens in software regression testing, and realizes automated and efficient tokens. acquisition process.
Patent Information
- Application Number
- CN202311657881.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-01
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2043-12-01
AI Technical Summary
In software regression testing, the process of manually obtaining tokens is inefficient and costly. Especially when multiple platforms require automated interface testing, tokens need to be obtained frequently, resulting in excessive labor costs and time consumption.
By defining the login request function and the identification verification code function in the target class, the verification code is automatically obtained and the token is obtained using the account number, password and verification code string. Salt encryption and public key encryption are supported to realize automatic acquisition of tokens and reduce Dependence on platform developers.
It reduces the cost and time of manually obtaining tokens, improves efficiency, and can automatically obtain tokens from different platforms to be tested. It does not require developers to specifically write interfaces for obtaining tokens, and supports iterative token acquisition until success.
Smart Images

Figure CN117763625B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a token acquisition method, apparatus, computer equipment, and storage medium. Background Art
[0002] For software released to production environments, regular regression testing is required to monitor interfaces for issues. However, in real-world applications, regression testing is often required for software on multiple platforms, each containing dozens or even hundreds of interfaces. Manually performing regression testing is prohibitively laborious. This requires writing automated interface testing scripts that automatically call interfaces at regular intervals and generate test reports based on the results returned. Since most interfaces verify a token in the request header, the first issue to address when writing automated interface testing scripts is how to obtain a token.
[0003] Traditionally, platform developers have been required to write a token-retrieval API specifically for test accounts, allowing the test client to directly obtain tokens through the API. However, this approach requires the involvement of platform developers, resulting in high labor costs and low efficiency. Summary of the Invention
[0004] Based on this, it is necessary to provide a token acquisition method, device, computer equipment, computer-readable storage medium and computer program product that can reduce labor costs and improve efficiency in response to the above technical problems.
[0005] In a first aspect, the present application provides a token acquisition method, comprising:
[0006] Obtain the parameters passed in for the login request function and store the addresses in the parameters as class variables in the target class; the parameters include the account and password for logging into the platform to be tested, as well as the addresses of the login request interface and verification code acquisition interface of the platform to be tested;
[0007] The login request function calls the identification verification code function, so that the identification verification code function obtains verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain a verification code string; the login request function and the identification verification code function are both functions in the target class;
[0008] A token is obtained from the login request interface according to the address of the login request interface through the login request function based on the account number, the password and the verification code character string.
[0009] In one embodiment, calling the verification code identification function through the login request function so that the verification code identification function obtains verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain a verification code string, includes:
[0010] Calling the verification code recognition function through the login request function;
[0011] The address of the verification code acquisition interface is passed into the request interface function through the recognition verification code function to request to obtain verification code information from the verification code acquisition interface;
[0012] The verification code recognition function transmits the obtained verification code information to the optical character recognition function, and the verification code information is recognized by the optical character recognition function to obtain a verification code string.
[0013] In one embodiment, the parameter further includes an address of a salt value acquisition interface of the platform to be tested; and the method further includes:
[0014] The password encryption function is called by the login request function, so that the password encryption function obtains a salt value from the salt value acquisition interface according to the address of the salt value acquisition interface, mixes the password based on the salt value and then encrypts it to obtain an encrypted password; the password encryption function is a function in the target class;
[0015] The acquiring of a token from the login request interface according to the address of the login request interface by the login request function based on the account number, the password and the verification code string includes:
[0016] A token is obtained from the login request interface according to the address of the login request interface through the login request function based on the account number, the encrypted password and the verification code character string.
[0017] In one embodiment, calling a password encryption function through the login request function so that the password encryption function obtains a salt value from the salt value acquisition interface according to the address of the salt value acquisition interface, and mixes the password based on the salt value and then encrypts it to obtain an encrypted password, includes:
[0018] Calling the password encryption function through the login request function;
[0019] The address of the salt value acquisition interface is passed into the request interface function through the password encryption function to request to obtain the salt value from the salt value acquisition interface;
[0020] The password is concatenated with the obtained salt value, and the concatenated result is encrypted using a public key to obtain an encrypted password.
[0021] In one embodiment, before concatenating the password with the obtained salt value and encrypting the concatenated result using a public key to obtain the encrypted password, the method further includes:
[0022] Assigning platform environment information to class variables in the target class in advance;
[0023] The corresponding public key is determined according to the platform environment information through the cryptographic encryption function.
[0024] In one embodiment, obtaining a token from the login request interface according to the address of the login request interface through the login request function based on the account number, the password, and the verification code string includes:
[0025] Obtaining a token from the login request interface according to the address of the login request interface through the login request function based on the account number, the password and the verification code string, and obtaining a login request return value;
[0026] If there are words and characters in the login request return value and they do not contain words and characters with locking meanings, then return to execute the step of obtaining the parameters passed in to the login request function and storing the address in the parameters as class variables in the target class and subsequent steps to iteratively re-acquire the token until there are no words and characters in the login request return value and the token is obtained.
[0027] In a second aspect, the present application further provides a token acquisition device, comprising:
[0028] A parameter input module is used to obtain the parameters passed in for the login request function and store the addresses in the parameters as class variables in the target class; the parameters include the account and password for logging into the platform to be tested, as well as the addresses of the login request interface and verification code acquisition interface of the platform to be tested;
[0029] A verification code recognition module is configured to call a verification code recognition function through the login request function, so that the verification code recognition function obtains verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and recognizes the verification code information to obtain a verification code string; the login request function and the verification code recognition function are both functions in the target class;
[0030] A token acquisition module is used to obtain a token based on the account number, the password and the verification code character string from the login request interface according to the address of the login request interface through the login request function.
[0031] In a third aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0032] Obtain the parameters passed in for the login request function and store the addresses in the parameters as class variables in the target class; the parameters include the account and password for logging into the platform to be tested, as well as the addresses of the login request interface and verification code acquisition interface of the platform to be tested;
[0033] The login request function calls the identification verification code function, so that the identification verification code function obtains verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain a verification code string; the login request function and the identification verification code function are both functions in the target class;
[0034] A token is obtained from the login request interface according to the address of the login request interface through the login request function based on the account number, the password and the verification code character string.
[0035] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0036] Obtain the parameters passed in for the login request function and store the addresses in the parameters as class variables in the target class; the parameters include the account and password for logging into the platform to be tested, as well as the addresses of the login request interface and verification code acquisition interface of the platform to be tested;
[0037] The login request function calls the identification verification code function, so that the identification verification code function obtains verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain a verification code string; the login request function and the identification verification code function are both functions in the target class;
[0038] A token is obtained from the login request interface according to the address of the login request interface through the login request function based on the account number, the password and the verification code character string.
[0039] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the following steps:
[0040] Obtain the parameters passed in for the login request function and store the addresses in the parameters as class variables in the target class; the parameters include the account and password for logging into the platform to be tested, as well as the addresses of the login request interface and verification code acquisition interface of the platform to be tested;
[0041] The login request function calls the identification verification code function, so that the identification verification code function obtains verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain a verification code string; the login request function and the identification verification code function are both functions in the target class;
[0042] A token is obtained from the login request interface according to the address of the login request interface through the login request function based on the account number, the password and the verification code character string.
[0043] The above-mentioned token acquisition method, device, computer equipment, storage medium and computer program product set the login request function and the identification verification code function as functions within the target class, and store the address parameter passed in by the login request function as a class variable in the target class, so that all functions in the target class can use the address of the target class as a class variable. The identification verification code function is called by the login request function, so that the identification verification code function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain the verification code string. The login request function obtains the token based on the account number, password and verification code string from the login request interface according to the address of the login request interface. Before performing interface testing on different platforms to be tested, it is only necessary to change the parameters passed in by the login request function to efficiently obtain tokens from different platforms to be tested, without the need for the developers of the platforms to be tested to specially write interfaces for obtaining tokens. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0045] Figure 1 A diagram showing an application environment of a token acquisition method in one embodiment;
[0046] Figure 2 A flowchart of a token acquisition method according to an embodiment;
[0047] Figure 3A schematic diagram of the overall process of a token acquisition method in one embodiment;
[0048] Figure 4 It is a structural block diagram of a token acquisition device in one embodiment;
[0049] Figure 5 It is a structural block diagram of a token acquisition device in another embodiment;
[0050] Figure 6 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0052] The token acquisition method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the first computer device 102 can communicate with each second computer device 104 through a network. The number of second computer devices 104 can be one or more. The first computer device 102 is the computer device on which the interface test script runs. The second computer device 104 is the computer device on which the platform to be tested runs. The first computer device 102 can execute the token acquisition method in each embodiment of the present application to obtain tokens from each second computer device 104. The first computer device 102 and the second computer device 104 can be terminals or servers. The terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server can be implemented as an independent server or a server cluster consisting of multiple servers.
[0053] In an exemplary embodiment, Figure 2 As shown, a token acquisition method is provided, which is applied to Figure 1 Taking the first computer device 102 in the example as an example, the following steps 202 to 206 are included. Among them:
[0054] Step 202, obtain the parameters passed to the login request function, and store the address in the parameters as a class variable in the target class; the parameters include the account and password used to log in to the platform to be tested, and the addresses of the login request interface and verification code acquisition interface of the platform to be tested.
[0055] Among them, the login request function is a function used to request login to the platform to be tested. The platform to be tested refers to the platform that needs to perform interface testing. The login request interface is an interface provided by the platform to be tested for requesting login to the platform to be tested. The verification code acquisition interface is an interface provided by the platform to be tested for obtaining the verification code. The address of the interface refers to the URL (Uniform Resource Locator) of the interface. Class variables are variables defined in a class, and can only be called by functions within the class. A class refers to a reference data type that encapsulates variables and functions. Functions in the target class can directly use class variables in the target class.
[0056] In an exemplary embodiment, the address in the parameter includes at least the address of the login request interface of the platform to be tested and the address of the verification code acquisition interface of the platform to be tested.
[0057] In some other embodiments, the parameter may further include the address of the salt value acquisition interface. Then, the address in the parameter also includes the address of the salt value acquisition interface.
[0058] In an exemplary embodiment, the login request function can call the parameter setting function so that the parameter setting function stores the address in the parameter as a class variable in the target class, thereby eliminating the need for parameter passing.
[0059] Step 204, calling the verification code identification function through the login request function, so that the verification code identification function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain the verification code string; the login request function and the verification code identification function are both functions in the target class.
[0060] The verification code recognition function is used to recognize verification code information. Verification code information refers to a verification code that has not yet been recognized as a specific string. For example, verification code information can be the image data corresponding to a verification code image. The verification code string is the string obtained by recognizing the specific content in the verification code information.
[0061] It can be understood that the login request function and the identification verification code function are both functions in the target class, so the login request function and the identification verification code function can directly use the class variables in the target class, that is, they can directly use the address in the parameters passed in to the login request function.
[0062] In an exemplary embodiment, the verification code recognition function can obtain verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, pass the obtained verification code information to the optical character recognition function, and use the optical character recognition function to recognize the verification code information to obtain a verification code string. The optical character recognition function is a function for optical character recognition (OCR).
[0063] In an exemplary embodiment, the verification code recognition function may directly obtain the address of the verification code acquisition interface from the class variable of the target class, and obtain the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface.
[0064] Step 206: Obtain a token from the login request interface based on the account number, password and verification code string according to the address of the login request interface through the login request function.
[0065] Among them, the token is a string of characters generated by the server, which is used as a token for the client to make requests. After the first login, the server generates a token and returns it to the client. In the future, the client only needs to bring this token to request data without having to bring the account and password again.
[0066] It is understood that after obtaining the token from the platform to be tested, the first computer device can test each interface on the platform to be tested based on the token. That is, the token acquisition method in each embodiment of the present application is a pre-processing before the interface test.
[0067] In an exemplary embodiment, the first computer device can send the account number, password and verification code string from the login request interface to the second computer device through the login request function according to the address of the login request interface. The second computer device can verify the account number, password and verification code string, and return the token to the first computer device through the login request interface after the verification is passed.
[0068] In an exemplary embodiment, the obtained verification code information includes the key and value of the verification code. The login request function can send the account number, password, verification code key and verification code string to the second computer device. The second computer device can determine the corresponding verification code information based on the verification code key to verify the verification code string based on the corresponding verification code information.
[0069] In an exemplary embodiment, the login request function can concatenate the request header and the request body to obtain a login request, and then send the login request to the login request interface. The request body includes the account number, password, and verification code string.
[0070] In an exemplary embodiment, the login request function may pass the address of the login request interface to the request interface function to request to obtain a token from the login request interface.
[0071] Among them, the request interface function is two functions of get request and post request written using the requests package. It is a tool function and can be reused in subsequent interface tests.
[0072] For example, the post request interface function requires parameters including the address, request headers, and request body, as well as the optional file parameter name and file path. The request interface function first determines the data type of the request body. If the data type is str, it uses the literal_eval function in the ast package to convert the string into a dictionary. It then determines whether the parameters include the file parameter name and file path. If not, it directly calls the post interface of the requests package, passing the address, request headers, and request body as parameters. If they do, it first uses regular expressions to extract the file name from the file path, reads the file path, adds the file name and file path to a list as values, and uses the file parameter name as the key to form a dictionary, which is then added to the request body. Finally, because file requests require bondary, it is necessary to use the encode_multipart_formdata function in the urllib3 package to regenerate the Content-Type in the request body and request header, replacing the passed-in parameters. The post interface of the requests package is then called again.
[0073] The above token acquisition method sets the login request function and the identification verification code function as functions within the target class, and stores the address parameter passed in by the login request function as a class variable in the target class, so that all functions in the target class can use the address of the target class as a class variable. The login request function calls the identification verification code function, so that the identification verification code function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain the verification code string. The login request function obtains the token based on the account number, password and verification code string from the login request interface according to the address of the login request interface. Before performing interface testing on different platforms to be tested, only the parameters passed in by the login request function need to be changed to efficiently obtain tokens from different platforms to be tested, without the need for the developers of the platforms to be tested to specially write interfaces for obtaining tokens. In addition, the entire token acquisition method can be deployed in an independent functional module in the interface test script. Each function is written inside a class and can be called outside the class using the class name (). function name method. If a new platform with a different login method is added, only a new login request function needs to be added, and the code has strong scalability.
[0074] In an exemplary embodiment, the identification verification code function is called through the login request function, so that the identification verification code function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain the verification code string, including: calling the identification verification code function through the login request function; passing the address of the verification code acquisition interface into the request interface function through the identification verification code function to request to obtain the verification code information from the verification code acquisition interface; the identification verification code function passes the obtained verification code information into the optical character recognition function, and identifies the verification code information through the optical character recognition function to obtain the verification code string.
[0075] The request interface function is a tool function used to make a request to the interface of the platform to be tested.
[0076] In one exemplary embodiment, the verification code information obtained by the verification code recognition function includes the verification code key and value. The verification code recognition function may first pass the verification code value to the optical character recognition function. The optical character recognition function may call the optical character recognition write function to decode the verification code value using a base64 package, then save it as an image through file operations for viewing. The optical character recognition function may then recognize the verification code information to obtain a verification code string. In this embodiment, the verification code is saved as an image, so that if optical character recognition fails, the specific appearance of the verification code image can be viewed.
[0077] In an exemplary embodiment, the optical character recognition function can use an object to call the classification function in the class to pass the verification code value and return the verification code string. The classification function supports passing bytes or strings, and the parameter img_base64=imageValue can be used to pass a string.
[0078] In the above embodiment, due to the use of optical character recognition technology, the user's real behavior can be simulated to perform the login operation, thereby more accurately simulating the user operation scenario and improving the coverage and authenticity of the test.
[0079] In an exemplary embodiment, the parameters also include the address of a salt value acquisition interface of the platform to be tested; the method further includes: calling a password encryption function through a login request function, so that the password encryption function obtains a salt value from the salt value acquisition interface according to the address of the salt value acquisition interface, and then mixes the password based on the salt value and encrypts it to obtain an encrypted password; the password encryption function is a function in the target class. Obtaining a token based on the account number, password, and verification code string from the login request interface according to the address of the login request interface through the login request function includes: obtaining a token based on the account number, encrypted password, and verification code string from the login request interface according to the address of the login request interface through the login request function.
[0080] The password encryption function is used to encrypt the password. The salt value acquisition interface is provided by the platform under test for obtaining the salt value. The salt value is a randomly generated string. For security reasons, the salt is added to the password before encryption. The salt value obtained for each request is different, so the encrypted password is different.
[0081] It can be understood that the password encryption function is a function in the target class, so the password encryption function can directly use the class variables in the target class, that is, the password encryption function can directly use the addresses of the login request interface, verification code acquisition interface and salt value acquisition interface of the platform to be tested.
[0082] In an exemplary embodiment, the password encryption function may directly obtain the address of the salt value acquisition interface from the class variable of the target class, and obtain the salt value from the salt value acquisition interface according to the address of the salt value acquisition interface.
[0083] In an exemplary embodiment, the first computer device can send the account number, encrypted password and verification code string from the login request interface to the second computer device through the login request function according to the address of the login request interface. The second computer device can decrypt the encrypted password to obtain the password, and then verify the account number, password and verification code string, and return the token to the first computer device through the login request interface after the verification is passed.
[0084] In an exemplary embodiment, the login request function can concatenate the request header and the request body to obtain a login request, and then send the login request to the login request interface. The request body includes the account number, encrypted password, and verification code string.
[0085] In the above embodiment, the password encryption function is called through the login request function, so that the password encryption function obtains the address of the interface according to the salt value, obtains the salt value from the salt value acquisition interface, and mixes the password based on the salt value and then encrypts it to obtain an encrypted password. The salt value can be obtained efficiently, so that before performing interface testing on different platforms to be tested, it is only necessary to change the parameters passed in by the login request function to efficiently obtain tokens from different platforms to be tested, and encrypting the password through the salt value can also improve data security.
[0086] In an exemplary embodiment, a password encryption function is called through a login request function, so that the password encryption function obtains the address of the salt value acquisition interface according to the salt value, obtains the salt value from the salt value acquisition interface, and mixes the password based on the salt value and then encrypts it to obtain an encrypted password, including: calling the password encryption function through the login request function; passing the address of the salt value acquisition interface into the request interface function through the password encryption function to request to obtain the salt value from the salt value acquisition interface; splicing and mixing the password with the obtained salt value, and then encrypting the splicing and mixing result through the public key to obtain an encrypted password.
[0087] In an exemplary embodiment, the salt value acquisition interface may concatenate the salt value after the password, and then encrypt the concatenation result using a public key to obtain an encrypted password.
[0088] In an exemplary embodiment, the public key is passed in advance through the import_key function of the Crypto.PublicKey.RSA file to obtain an object, which is then passed to the new function of the Crypto.Cipher.PKCS1_v1_5 file to obtain a target object. The salt value is then added to the end of the password, converted to a bytes type, and passed to the encrypt function of the target object. A bytes-type mixed password can be obtained, which is converted to a string through base64.b64encode and decode, which is the password required in the parameter.
[0089] In the above embodiment, the password encryption function is called through the login request function, and the address of the salt value acquisition interface is passed into the request interface function through the password encryption function to request to obtain the salt value from the salt value acquisition interface, and the password and the obtained salt value are spliced and mixed, and then the spliced and mixed result is encrypted by the public key to obtain an encrypted password. The salt value can be efficiently obtained and the password can be encrypted. Before performing interface testing on different platforms to be tested, it is only necessary to change the parameters passed in by the login request function to efficiently obtain tokens from different platforms to be tested. In addition, encrypting the password through the salt value can also improve data security.
[0090] In an exemplary embodiment, before concatenating and mixing the password with the obtained salt value and then encrypting the concatenated and mixed result with the public key to obtain the encrypted password, the method also includes: pre-assigning platform environment information to class variables in the target class; and determining the corresponding public key according to the platform environment information through a password encryption function.
[0091] The platform environment information is used to represent the platform environment of the platform to be tested. Different platform environments correspond to different accounts, passwords, addresses, and public keys.
[0092] In an exemplary embodiment, the platform environment may include at least one of a test environment, a pre-release environment, and a production environment.
[0093] In an exemplary embodiment, the first computer device may call a parameter setting function to assign the platform environment information to a class variable in the target class.
[0094] In an exemplary embodiment, a corresponding public key is determined according to platform environment information through a cryptographic encryption function, and then the concatenated and mixed result is encrypted using the public key to obtain an encrypted password.
[0095] Assigning the platform environment information to a class variable in the target class allows each function in the target class to directly access the platform environment information. The public key is requested from the front-end developer and written in the interface test script. The platform environment determines which public key to use. The platform environment has already been stored as a class variable, so the public key can be directly determined based on the platform environment information.
[0096] In the above embodiment, the platform environment information is pre-assigned to the class variable in the target class, and the corresponding public key is determined according to the platform environment information through a cryptographic encryption function, thereby being able to efficiently determine the corresponding public key according to the platform environment.
[0097] In an exemplary embodiment, obtaining a token based on an account, password, and verification code string from a login request interface according to the address of the login request interface through a login request function includes: obtaining a token based on an account, password, and verification code string from a login request interface according to the address of the login request interface through a login request function to obtain a login request return value; if the login request return value contains language text and does not contain language text with a locking meaning, then returning to execute the step of obtaining the parameters passed in to the login request function and storing the address in the parameter as a class variable in the target class and subsequent steps to iteratively re-obtain the token until there is no language text in the login request return value and the token is obtained.
[0098] In an exemplary embodiment, the first computer device may first determine whether the login request return value is empty. If it is empty, the first computer device may return to execute the steps of obtaining the parameters passed in to the login request function and storing the addresses in the parameters as class variables in the target class and subsequent steps to re-acquire the token; if it is not empty, the first computer device may determine whether there are language characters in the login request return value. If there are no language characters, the login request return value may be used as the token; if there are language characters, the first computer device may determine whether the login request return value contains language characters with locking meaning. If it does not contain language characters with locking meaning, the first computer device may return to execute the steps of obtaining the parameters passed in to the login request function and storing the addresses in the parameters as class variables in the target class and subsequent steps to iteratively re-acquire the token; if it contains language characters with locking meaning, the first computer device may exit the script.
[0099] It's understood that if the login request return value contains language text, it indicates that token acquisition failed. The login request return value includes the reason for the failure. The type of failure reason needs to be determined by determining whether the login request return value contains language text implying a lock. If it does, it indicates that the account and password have been modified, resulting in an incorrect password. If the account is entered several times, the account will be locked, so the script will exit immediately. If it doesn't contain language text implying a lock, it indicates that the password is incorrect due to an incorrect salt value, so the script returns to retrieve the token again. It's understandable that due to the time lag between obtaining the salt value and sending the login request, multiple scripts may obtain a different salt value during this time. The platform under test uses the most recently obtained salt value when decrypting the encrypted password in the login request. Therefore, in this case, a password error due to an incorrect salt value is likely to occur. This is simply due to the time lag, not a true password error. Therefore, it's appropriate to return to iteratively retrieve the token.
[0100] In an exemplary embodiment, if there is no language text in the login request return value, the first computer device can determine whether the length of the login request return value is greater than or equal to a preset length threshold. If so, the login request return value is used as a token; if not, the step of obtaining the parameters passed in to the login request function and storing the address in the parameters as a class variable in the target class and subsequent steps is returned to iteratively re-obtain the token until there is no language text in the login request return value and the length of the login request return value is greater than or equal to the preset length threshold, and a token is obtained.
[0101] In an exemplary embodiment, the language may be Chinese.
[0102] In an exemplary embodiment, when the number of iterations is greater than or equal to a preset threshold, the script is exited.
[0103] In an exemplary embodiment, the words and phrases with the meaning of locking may include words such as "lock" or "remaining". It is understandable that the return value of the login request may be "two incorrect passwords have been entered, and there are three remaining attempts to enter the password, otherwise the account will be locked."
[0104] In the above embodiment, if there are language characters in the login request return value and it does not contain language characters with locking meaning, then the process returns to execute the step of obtaining the parameters passed in to the login request function and storing the address in the parameters as class variables in the target class and subsequent steps to iteratively re-obtain the token until there are no language characters in the login request return value and the token is obtained, thereby avoiding the problem of being unable to successfully obtain the token due to an incorrect salt value and improving the accuracy and success rate of the obtained token.
[0105] like Figure 3 As shown, it is a schematic diagram of the overall flow of the token acquisition method in each embodiment of the present application, which includes the following steps: first, the platform environment is assigned to the class variable, and then the login request function is called, the address of each interface is assigned to the class variable, and then the verification code is obtained, and then the password is encrypted, and then the token is obtained. If the token is obtained, the loop ends. If the acquisition fails, if the reason for the failure is an incorrect password, the program exits. If the reason for the failure is not an incorrect password, it returns to the step of calling the login request function to continue the loop.
[0106] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0107] Based on the same inventive concept, embodiments of the present application further provide a token acquisition device for implementing the aforementioned token acquisition method. The implementation solution provided by this device is similar to the implementation solution described in the aforementioned method. Therefore, the specific limitations of one or more token acquisition device embodiments provided below can be found in the above-mentioned limitations of the token acquisition method and will not be repeated here.
[0108] In an exemplary embodiment, Figure 4As shown, a token acquisition device 400 is provided, comprising: a parameter input module 402, a verification code recognition module 404 and a token acquisition module 406, wherein:
[0109] The parameter input module 402 is used to obtain the parameters input to the login request function and store the address in the parameter as a class variable in the target class; the parameters include the account and password used to log in to the platform to be tested, as well as the address of the login request interface and verification code acquisition interface of the platform to be tested.
[0110] The verification code recognition module 404 is used to call the verification code recognition function through the login request function, so that the verification code recognition function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and recognizes the verification code information to obtain the verification code string; the login request function and the verification code recognition function are both functions in the target class.
[0111] The token acquisition module 406 is used to acquire a token based on the account number, password and verification code string from the login request interface according to the address of the login request interface through the login request function.
[0112] In an exemplary embodiment, the verification code recognition module 404 is also used to call the verification code recognition function through the login request function; pass the address of the verification code acquisition interface into the request interface function through the verification code recognition function to request to obtain the verification code information from the verification code acquisition interface; the verification code recognition function passes the obtained verification code information into the optical character recognition function, and recognizes the verification code information through the optical character recognition function to obtain the verification code string.
[0113] In an exemplary embodiment, the parameters also include the address of the salt value acquisition interface of the platform to be tested; Figure 5 As shown, the token acquisition device 400 further includes:
[0114] The password encryption module 408 is used to call the password encryption function through the login request function, so that the password encryption function obtains the address of the salt value acquisition interface according to the salt value, obtains the salt value from the salt value acquisition interface, and mixes the password based on the salt value and then encrypts it to obtain an encrypted password; the password encryption function is a function in the target class.
[0115] The token acquisition module 406 is further configured to acquire a token based on the account number, encrypted password, and verification code string from the login request interface according to the address of the login request interface through a login request function.
[0116] In an exemplary embodiment, the password encryption module 408 is also used to call the password encryption function through the login request function; pass the address of the salt value acquisition interface into the request interface function through the password encryption function to request to obtain the salt value from the salt value acquisition interface; splice and mix the password with the obtained salt value, and then encrypt the spliced and mixed result through the public key to obtain an encrypted password.
[0117] In an exemplary embodiment, the parameter input module 402 is further used to pre-assign the platform environment information to the class variables in the target class. The password encryption module 408 is further used to determine the corresponding public key according to the platform environment information through a password encryption function.
[0118] In an exemplary embodiment, the token acquisition module 406 is also used to obtain a token based on the account, password and verification code string from the login request interface according to the address of the login request interface through the login request function to obtain the login request return value; if there is language text in the login request return value and it does not contain language text with a locking meaning, then return to execute the steps of obtaining the parameters passed in to the login request function and storing the address in the parameter as a class variable in the target class and subsequent steps to iteratively re-acquire the token until there is no language text in the login request return value and the token is obtained.
[0119] The above-mentioned token acquisition device sets the login request function and the identification verification code function as functions within the target class, and stores the address parameter passed in by the login request function as a class variable in the target class, so that all functions in the target class can use the address of the target class as a class variable. The identification verification code function is called by the login request function, so that the identification verification code function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain the verification code string. The login request function obtains the token based on the account number, password and verification code string from the login request interface according to the address of the login request interface. Before performing interface testing on different platforms to be tested, it is only necessary to change the parameters passed in by the login request function to efficiently obtain tokens from different platforms to be tested.
[0120] Each module in the token acquisition device described above may be implemented in whole or in part through software, hardware, or a combination thereof. Each module may be embedded in or independent of a processor in a computer device in the form of hardware, or may be stored in a memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0121] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 6As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a token acquisition method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse.
[0122] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0123] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor implements the steps in the above method embodiments when executing the computer program.
[0124] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0125] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0126] It should be noted that the data involved in this application (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0127] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.
[0128] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0129] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A token acquisition method, characterized in that: The method comprises: Obtain the parameters passed in for the login request function, and store the address in the parameters as a class variable in the target class; the parameters include the account and password used to log in to the platform to be tested, and the addresses of the login request interface and verification code acquisition interface of the platform to be tested; The identification verification code function is called through the login request function, so that the identification verification code function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain the verification code string; the login request function and the identification verification code function are both functions in the target class; The password encryption function is called through the login request function; the address of the salt value acquisition interface is passed into the request interface function through the password encryption function to request to obtain the salt value from the salt value acquisition interface; the platform environment information is assigned to the class variable in the target class in advance; the corresponding public key is determined according to the platform environment information through the password encryption function; the password is spliced and mixed with the obtained salt value, and then the spliced and mixed result is encrypted through the public key to obtain an encrypted password; the password encryption function is a function in the target class; A token is obtained from the login request interface according to the address of the login request interface through the login request function based on the account number, the encrypted password and the verification code character string.
2. The method according to claim 1, characterized in that The step of calling the identification verification code function through the login request function so that the identification verification code function obtains verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and identifies the verification code information to obtain a verification code string, including: Calling the identification verification code function through the login request function; The address of the verification code acquisition interface is passed into the request interface function through the identification verification code function to request to obtain the verification code information from the verification code acquisition interface; The verification code recognition function transmits the obtained verification code information to the optical character recognition function, and the verification code information is recognized by the optical character recognition function to obtain a verification code string.
3. The method according to claim 2, characterized in that The acquiring a token from the login request interface according to the address of the login request interface through the login request function based on the account number, the encrypted password and the verification code string comprises: Obtaining a token from the login request interface according to the address of the login request interface through the login request function based on the account number, the encrypted password and the verification code string, and obtaining a login request return value; If there are words and characters in the login request return value and do not contain words and characters with locking meaning, then return to execute the step of obtaining the parameters passed in to the login request function and storing the address in the parameters as class variables in the target class and subsequent steps to iteratively re-acquire the token until there are no words and characters in the login request return value and a token is obtained.
4. The method according to claim 2, characterized in that: The verification code information obtained by the verification code identification function includes a key and a value of the verification code, and the method further includes: The recognition verification code function transmits the value of the verification code to the optical character recognition function; The optical character recognition function calls the optical character recognition writing function, decodes the value of the verification code using a base64 package, and saves it as a picture through file operation for viewing.
5. The method according to claim 1, characterized in that The method is deployed in a functional module in an interface test script, and each function of the method belongs to the same class.
6. The method according to claim 1, characterized in that The method further comprises: When a new platform with a different login method is added, a login request function for the platform is added.
7. A token acquisition device, characterized in that: The device comprises: A parameter input module is used to obtain the parameters input to the login request function and store the addresses in the parameters as class variables in the target class; the parameters include the account and password for logging into the platform to be tested, and the addresses of the login request interface and verification code acquisition interface of the platform to be tested; and, pre-assigning the platform environment information to the class variables in the target class; A verification code recognition module, used for calling the verification code recognition function through the login request function, so that the verification code recognition function obtains the verification code information from the verification code acquisition interface according to the address of the verification code acquisition interface, and recognizes the verification code information to obtain a verification code string; the login request function and the verification code recognition function are both functions in the target class; A password encryption module is used to call a password encryption function through the login request function; pass the address of the salt value acquisition interface to the request interface function through the password encryption function to request to obtain the salt value from the salt value acquisition interface; determine the corresponding public key according to the platform environment information through the password encryption function; splice and mix the password with the obtained salt value, and then encrypt the splicing and mixing result through the public key to obtain an encrypted password; the password encryption function is a function in the target class; A token acquisition module is used to acquire a token from the login request interface according to the address of the login request interface through the login request function based on the account number, the encrypted password and the verification code character string.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
